home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / ole / oleview / iviewers / dispatch.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-27  |  3.6 KB  |  145 lines

  1. // dispatch.cpp : implementation file
  2. //
  3.  
  4. // This is a part of the Microsoft Foundation Classes C++ library.
  5. // Copyright (C) 1992-1998 Microsoft Corporation
  6. // All rights reserved.
  7. //
  8. // This source code is only intended as a supplement to the
  9. // Microsoft Foundation Classes Reference and related
  10. // electronic documentation provided with the library.
  11. // See these sources for detailed information regarding the
  12. // Microsoft Foundation Classes product.
  13.  
  14. #include "stdafx.h"
  15. #include "iviewers.h"
  16. #include "iview.h"
  17. #include "iviewer.h"
  18. #include "dispatch.h"
  19. #include "util.h"
  20.  
  21. #ifdef _DEBUG
  22. #undef THIS_FILE
  23. static char BASED_CODE THIS_FILE[] = __FILE__;
  24. #endif
  25.  
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CDispatchViewer
  28.  
  29. IMPLEMENT_DYNCREATE(CDispatchViewer, CInterfaceViewer)
  30.  
  31. CDispatchViewer::CDispatchViewer()
  32. {
  33. }
  34.  
  35. CDispatchViewer::~CDispatchViewer()
  36. {
  37. }
  38.  
  39. BEGIN_MESSAGE_MAP(CDispatchViewer, CInterfaceViewer)
  40. //  //{{AFX_MSG_MAP(CDispatchViewer)
  41. //      // NOTE - the ClassWizard will add and remove mapping macros here.
  42. //  //}}AFX_MSG_MAP
  43. END_MESSAGE_MAP()
  44.  
  45. IMPLEMENT_OLECREATE(CDispatchViewer, "Ole2View.IDispatch.1", 0xd2af7a60, 0x4c42, 0x11ce, 0xb2, 0x7d, 0x00, 0xaa, 0x00, 0x1f, 0x73, 0xc1) ;
  46.  
  47. /////////////////////////////////////////////////////////////////////////////
  48. // CDispatchViewer View imp.
  49.  
  50. //
  51.  
  52. HRESULT CDispatchViewer::OnView(HWND hwndParent, REFIID riid, LPUNKNOWN punk)
  53. {
  54.     SCODE sc = NOERROR ;
  55.  
  56.     ASSERT(hwndParent);
  57.     ASSERT(punk);
  58.  
  59.     if (riid != IID_IDispatch)
  60.     {
  61.         AfxMessageBox( _T("IDispatch interface viewer only supports IID_IDispatch") ) ;
  62.         return E_INVALIDARG ;
  63.     }
  64.  
  65.     CDispatchDlg dlg(CWnd::FromHandle(hwndParent)) ;
  66.  
  67.     sc = punk->QueryInterface( riid, (void**)&dlg.m_pdisp ) ;
  68.     if (FAILED(sc))
  69.     {
  70.         ErrorMessage( "Object does not support IDispatch.", sc ) ;
  71.         return E_UNEXPECTED ;
  72.     }
  73.  
  74.     dlg.DoModal() ;
  75.  
  76.     dlg.m_pdisp->Release() ;
  77.  
  78.     return sc ;
  79. }
  80. /////////////////////////////////////////////////////////////////////////////
  81. // CDispatchDlg dialog
  82.  
  83.  
  84. CDispatchDlg::CDispatchDlg(CWnd* pParent /*=NULL*/)
  85.     : CDialog(CDispatchDlg::IDD, pParent)
  86. {
  87.     //{{AFX_DATA_INIT(CDispatchDlg)
  88.     m_uiTypeInfoCount = 0;
  89.     //}}AFX_DATA_INIT
  90.     m_pdisp = NULL ;
  91. }
  92.  
  93.  
  94. void CDispatchDlg::DoDataExchange(CDataExchange* pDX)
  95. {
  96.     CDialog::DoDataExchange(pDX);
  97.     //{{AFX_DATA_MAP(CDispatchDlg)
  98.     DDX_Control(pDX, IDC_VIEWTYPEINFO, m_btnViewTypeInfo);
  99.     DDX_Text(pDX, IDC_TYPEINFOCOUNT, m_uiTypeInfoCount);
  100.     //}}AFX_DATA_MAP
  101.  
  102.     m_btnViewTypeInfo.EnableWindow(m_uiTypeInfoCount != 0) ;
  103. }
  104.  
  105.  
  106. BEGIN_MESSAGE_MAP(CDispatchDlg, CDialog)
  107.     //{{AFX_MSG_MAP(CDispatchDlg)
  108.     ON_BN_CLICKED(IDC_VIEWTYPEINFO, OnViewTypeInfo)
  109.     //}}AFX_MSG_MAP
  110. END_MESSAGE_MAP()
  111.  
  112.  
  113. /////////////////////////////////////////////////////////////////////////////
  114. // CDispatchDlg message handlers
  115.  
  116. void CDispatchDlg::OnViewTypeInfo()
  117. {
  118.     // TODO:
  119.     // if (m_uiTypeInfoCount > 0) // should never be > 1
  120.     //    Call IDispatch::GetTypeInfo
  121.     //    Pop up ITypeInfo Viewer in the resulting ITypeInfo*
  122.     //    (note that there is currently no ITypeInfo viewer, but
  123.     //     the ITypeLib viewer could easily be modified/extended
  124.     //     to browse a specific ITypeInfo).
  125.  
  126. }
  127.  
  128. BOOL CDispatchDlg::OnInitDialog()
  129. {
  130.     ASSERT(m_pdisp) ;
  131.  
  132.     HRESULT hr ;
  133.     hr = m_pdisp->GetTypeInfoCount( &m_uiTypeInfoCount ) ;
  134.     if (FAILED(hr))
  135.     {
  136.         m_uiTypeInfoCount = 0 ;
  137.         ErrorMessage( "IDispatch::GetTypeInfoCount failed.", hr ) ;
  138.     }
  139.  
  140.     CDialog::OnInitDialog();
  141.  
  142.     return TRUE;  // return TRUE unless you set the focus to a control
  143.                   // EXCEPTION: OCX Property Pages should return FALSE
  144. }
  145.