home *** CD-ROM | disk | FTP | other *** search
- // UseAtlTrigDlg.cpp : implementation file
-
- #include "stdafx.h"
- #include "UseAtlTrig.h"
-
- #include "atltrig.h"
-
- #include "UseAtlTrigDlg.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CUseAtlTrigDlg dialog
-
- CUseAtlTrigDlg::CUseAtlTrigDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CUseAtlTrigDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CUseAtlTrigDlg)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
-
- m_pTrig = 0;
- }
-
- void CUseAtlTrigDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CUseAtlTrigDlg)
- // NOTE: the ClassWizard will add DDX and DDV calls here
- //}}AFX_DATA_MAP
- }
-
- BEGIN_MESSAGE_MAP(CUseAtlTrigDlg, CDialog)
- //{{AFX_MSG_MAP(CUseAtlTrigDlg)
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_BN_CLICKED(IDC_BUTTON, OnButton)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CUseAtlTrigDlg message handlers
-
- BOOL CUseAtlTrigDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- // Set the icon for this dialog. The framework does this automatically
- // when the application's main window is not a dialog
- SetIcon(m_hIcon, TRUE); // Set big icon
- SetIcon(m_hIcon, FALSE); // Set small icon
-
- return TRUE;
- }
-
- // If you add a minimize button to your dialog, you will need the code below
- // to draw the icon. For MFC applications using the document/view model,
- // this is automatically done for you by the framework.
- void CUseAtlTrigDlg::OnPaint()
- {
- if (IsIconic())
- {
- CPaintDC dc(this); // device context for painting
-
- SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
-
- // Center icon in client rectangle
- int cxIcon = GetSystemMetrics(SM_CXICON);
- int cyIcon = GetSystemMetrics(SM_CYICON);
- CRect rect;
- GetClientRect(&rect);
- int x = (rect.Width() - cxIcon + 1) / 2;
- int y = (rect.Height() - cyIcon + 1) / 2;
-
- // Draw the icon
- dc.DrawIcon(x, y, m_hIcon);
- }
- else
- {
- CDialog::OnPaint();
- }
- }
-
- // The system calls this to obtain the cursor to display while
- // the user drags the minimized window.
- HCURSOR CUseAtlTrigDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
-
- void CUseAtlTrigDlg::OnButton()
- {
- // One can create the dispatch interfce using either the CLSID
- // or its name. Regardless of the type of object, one will get
- // whatever interface the object exposes when it receives
- // a request for its IDispatch interface, Itrig in this case.
- // See the COM_INTERFACE_ENTRY2 entry of the server's header file.
- // The first COM_INTERFACE_ENTRY2 entry in the BEGIN_COM_MAP is
- // the one that will be used.
-
- if (0 == m_pTrig)
- {
- m_pTrig = new Itrig;
- COleException e;
- BOOL rc = m_pTrig->CreateDispatch("trig.trig.1", &e);
- //BOOL rc = m_pTrig->CreateDispatch(CLSID_trig, &e);
- if (FALSE == rc)
- {
- MessageBox("Unable to create dispatch interface");
- delete m_pTrig;
- m_pTrig = 0;
- return;
- }
- }
-
- double x = 1.0, r;
- m_pTrig->ATLsin(x, &r);
-
- CString s;
- s.Format("The sin of %lf is %lf", x, r);
- MessageBox(s);
- }
-
- BOOL CUseAtlTrigDlg::DestroyWindow()
- {
- if (0 != m_pTrig)
- delete m_pTrig;
-
- return CDialog::DestroyWindow();
- }
-