home *** CD-ROM | disk | FTP | other *** search
/ The Houseplan Collection / HRCD2005.ISO / data1.cab / Zusatz / 3DS / DATA2.Z / EventDemoDlg.cpp < prev    next >
C/C++ Source or Header  |  1999-06-14  |  5KB  |  222 lines

  1. // EventDemoDlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "EventDemo.h"
  6. #include "EventDemoDlg.h"
  7. #include "ArConEventSink.h"
  8. #include "MakroUtil.h"
  9. #include <AfxCtl.h>
  10.  
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16.  
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CAboutDlg dialog used for App About
  19.  
  20. class CAboutDlg : public CDialog
  21. {
  22. public:
  23.     CAboutDlg();
  24.  
  25. // Dialog Data
  26.     //{{AFX_DATA(CAboutDlg)
  27.     enum { IDD = IDD_ABOUTBOX };
  28.     //}}AFX_DATA
  29.  
  30.     // ClassWizard generated virtual function overrides
  31.     //{{AFX_VIRTUAL(CAboutDlg)
  32.     protected:
  33.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  34.     //}}AFX_VIRTUAL
  35.  
  36. // Implementation
  37. protected:
  38.     //{{AFX_MSG(CAboutDlg)
  39.     //}}AFX_MSG
  40.     DECLARE_MESSAGE_MAP()
  41. };
  42.  
  43. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  44. {
  45.     //{{AFX_DATA_INIT(CAboutDlg)
  46.     //}}AFX_DATA_INIT
  47. }
  48.  
  49. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  50. {
  51.     CDialog::DoDataExchange(pDX);
  52.     //{{AFX_DATA_MAP(CAboutDlg)
  53.     //}}AFX_DATA_MAP
  54. }
  55.  
  56. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  57.     //{{AFX_MSG_MAP(CAboutDlg)
  58.         // No message handlers
  59.     //}}AFX_MSG_MAP
  60. END_MESSAGE_MAP()
  61.  
  62. /////////////////////////////////////////////////////////////////////////////
  63. // CEventDemoDlg dialog
  64.  
  65. CEventDemoDlg::CEventDemoDlg(CWnd* pParent /*=NULL*/)
  66.     : CDialog(CEventDemoDlg::IDD, pParent)
  67. {
  68.     //{{AFX_DATA_INIT(CEventDemoDlg)
  69.         // NOTE: the ClassWizard will add member initialization here
  70.     //}}AFX_DATA_INIT
  71.     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  72.  
  73.   m_pArConEXE = NULL;
  74.   m_pEventSink = NULL;
  75. }
  76.  
  77. CEventDemoDlg::~CEventDemoDlg()
  78. {
  79.   CleanUp();
  80. }
  81.  
  82. void CEventDemoDlg::CleanUp()
  83. {
  84.   if (m_pEventSink) {
  85.     AfxConnectionUnadvise(m_pArConEXE->m_lpDispatch, DIID__ArConEvents, 
  86.         m_pEventSink->GetIDispatch(FALSE), FALSE, m_eventCookie);
  87.     m_pEventSink->ExternalRelease();
  88.     m_pEventSink = NULL;
  89.   }
  90.  
  91.   if (m_pArConEXE) {
  92.     m_pArConEXE->EndMe();
  93.     m_pArConEXE->ReleaseDispatch();
  94.     delete m_pArConEXE;
  95.     m_pArConEXE = NULL;
  96.   }
  97. }
  98.  
  99. void CEventDemoDlg::DoDataExchange(CDataExchange* pDX)
  100. {
  101.     CDialog::DoDataExchange(pDX);
  102.     //{{AFX_DATA_MAP(CEventDemoDlg)
  103.     DDX_Control(pDX, IDC_LIST, m_eventList);
  104.     //}}AFX_DATA_MAP
  105. }
  106.  
  107. BEGIN_MESSAGE_MAP(CEventDemoDlg, CDialog)
  108.     //{{AFX_MSG_MAP(CEventDemoDlg)
  109.     ON_WM_SYSCOMMAND()
  110.     ON_WM_PAINT()
  111.     ON_WM_QUERYDRAGICON()
  112.     //}}AFX_MSG_MAP
  113. END_MESSAGE_MAP()
  114.  
  115. /////////////////////////////////////////////////////////////////////////////
  116. // CEventDemoDlg message handlers
  117.  
  118. BOOL CEventDemoDlg::OnInitDialog()
  119. {
  120.     CDialog::OnInitDialog();
  121.  
  122.     // Add "About..." menu item to system menu.
  123.  
  124.     // IDM_ABOUTBOX must be in the system command range.
  125.     ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  126.     ASSERT(IDM_ABOUTBOX < 0xF000);
  127.  
  128.     CMenu* pSysMenu = GetSystemMenu(FALSE);
  129.     if (pSysMenu != NULL)
  130.     {
  131.         CString strAboutMenu;
  132.         strAboutMenu.LoadString(IDS_ABOUTBOX);
  133.         if (!strAboutMenu.IsEmpty())
  134.         {
  135.             pSysMenu->AppendMenu(MF_SEPARATOR);
  136.             pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  137.         }
  138.     }
  139.  
  140.     SetIcon(m_hIcon, TRUE);            // Set big icon
  141.     SetIcon(m_hIcon, FALSE);        // Set small icon
  142.     
  143.     // Erzeuge die OLE Verbindung zur ArCon.EXE
  144.   m_pArConEXE = new IArCon;
  145.   m_pArConEXE->CreateDispatch("ArCon.Application.1");
  146.  
  147.   // Erzeuge die Senke fⁿr die ArCon-Ereignisse
  148.   m_pEventSink = new ArConEventSink(this);
  149.   if (!AfxConnectionAdvise(m_pArConEXE->m_lpDispatch, DIID__ArConEvents, 
  150.       m_pEventSink->GetIDispatch(FALSE), FALSE, &m_eventCookie))
  151.   {
  152.     TRACE("Konnte die Event-Verbindung nicht herstellen!\n");
  153.   }
  154.  
  155.   // Nachdem die Event-Senke verbunden ist, k÷nnen wir die Ereignisse
  156.   // aktivieren
  157.   m_pArConEXE->StartMe((long)m_hWnd, AfxGetApp()->m_pszHelpFilePath);
  158.  
  159.   // Test: fordere einen Click an
  160.   CBitmap bmp;
  161.   bmp.LoadBitmap(IDB_CROSS);
  162.   VARIANT pic;
  163.   ArConPictureFromBitmap(bmp, &pic);
  164.   m_pArConEXE->GetOneClick("Bitte einmal klicken!", pic, 4711);
  165.   VariantClear(&pic);
  166.     
  167.     return TRUE;  // return TRUE  unless you set the focus to a control
  168. }
  169.  
  170. void CEventDemoDlg::OnSysCommand(UINT nID, LPARAM lParam)
  171. {
  172.     if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  173.     {
  174.         CAboutDlg dlgAbout;
  175.         dlgAbout.DoModal();
  176.     }
  177.     else
  178.     {
  179.         CDialog::OnSysCommand(nID, lParam);
  180.     }
  181. }
  182.  
  183. // If you add a minimize button to your dialog, you will need the code below
  184. //  to draw the icon.  For MFC applications using the document/view model,
  185. //  this is automatically done for you by the framework.
  186.  
  187. void CEventDemoDlg::OnPaint() 
  188. {
  189.     if (IsIconic())
  190.     {
  191.         CPaintDC dc(this); // device context for painting
  192.  
  193.         SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  194.  
  195.         // Center icon in client rectangle
  196.         int cxIcon = GetSystemMetrics(SM_CXICON);
  197.         int cyIcon = GetSystemMetrics(SM_CYICON);
  198.         CRect rect;
  199.         GetClientRect(&rect);
  200.         int x = (rect.Width() - cxIcon + 1) / 2;
  201.         int y = (rect.Height() - cyIcon + 1) / 2;
  202.  
  203.         // Draw the icon
  204.         dc.DrawIcon(x, y, m_hIcon);
  205.     }
  206.     else
  207.     {
  208.         CDialog::OnPaint();
  209.     }
  210. }
  211.  
  212. HCURSOR CEventDemoDlg::OnQueryDragIcon()
  213. {
  214.     return (HCURSOR) m_hIcon;
  215. }
  216.  
  217. void CEventDemoDlg::Display(const CString & msg)
  218. {
  219.   CString line;
  220.   m_eventList.AddString(msg);
  221. }
  222.