ATLCON1.H
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:6k
源码类别:

Windows编程

开发平台:

Visual C++

  1. // AtlCon1.h : Declaration of the CAtlCon
  2. //
  3. // This is a part of the Active Template Library.
  4. // Copyright (C) 1996-1998 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Active Template Library Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Active Template Library product.
  12. #include "resource.h"       // main symbols
  13. #include <oledlg.h>
  14. #include "propbrowsectl.h"
  15. #pragma comment(lib, "oledlg.lib")
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CFileOpenDlg
  18. class CFileOpenDlg : public CDialogImpl<CFileOpenDlg>
  19. {
  20. BEGIN_MSG_MAP(CFileOpenDlg)
  21. MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
  22. COMMAND_ID_HANDLER(IDOK, OnEndDialog)
  23. COMMAND_ID_HANDLER(IDCANCEL, OnEndDialog)
  24. COMMAND_ID_HANDLER(IDC_BROWSE, OnBrowse)
  25. END_MSG_MAP()
  26. LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  27. {
  28. // Let the system set the focus
  29. return 1;
  30. }
  31. LRESULT OnEndDialog(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  32. {
  33. CWindow(GetDlgItem(IDC_EDIT1)).GetWindowText(&m_bstrName);
  34. EndDialog(wID);
  35. return 0;
  36. }
  37. LRESULT OnBrowse(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  38. {
  39. OLEUIINSERTOBJECT   io;
  40. TCHAR               szFile[_MAX_PATH];
  41. ZeroMemory(&io, sizeof(io));
  42. io.cbStruct = sizeof(io);
  43. szFile[0] = 0;
  44. io.lpszFile = szFile;
  45. io.cchFile = _MAX_PATH;
  46. io.dwFlags = IOF_DISABLELINK | IOF_DISABLEDISPLAYASICON | IOF_SHOWINSERTCONTROL | IOF_SELECTCREATECONTROL;
  47. if (OleUIInsertObject(&io) == OLEUI_OK)
  48. {
  49. if (io.dwFlags & IOF_CREATELINKOBJECT)
  50. MessageBox(_T("Sorry. Creation from a file is not currently supported."));
  51. else
  52. {
  53. LPOLESTR pszClsid = NULL;
  54. StringFromCLSID(io.clsid, &pszClsid);
  55. m_bstrName = pszClsid;
  56. CoTaskMemFree(pszClsid);
  57. EndDialog(IDOK);
  58. }
  59. }
  60. return 0;
  61. }
  62. enum { IDD = IDD_FILEOPEN };
  63. CComBSTR m_bstrName;
  64. };
  65. /////////////////////////////////////////////////////////////////////////////
  66. // CAtlCon - Example of generic ActiveX Hosting window
  67. class CAtlCon : public CWindowImpl<CAtlCon, CWindow, CWinTraits<WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE> >
  68. {
  69. public:
  70. DECLARE_WND_CLASS_EX(NULL, 0, 0)
  71. BEGIN_MSG_MAP(CAtlCon)
  72. MESSAGE_HANDLER(WM_CREATE, OnCreate)
  73. MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
  74. COMMAND_ID_HANDLER(ID_FILE_OPEN, OnFileOpen)
  75. COMMAND_ID_HANDLER(ID_APP_EXIT, OnFileExit)
  76. MESSAGE_HANDLER(WM_SIZE, OnSize)
  77. MESSAGE_HANDLER(WM_ERASEBKGND, OnErase)
  78. END_MSG_MAP()
  79. void OnFinalMessage(HWND /*hWnd*/)
  80. {
  81. ::PostQuitMessage(0);
  82. }
  83. LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  84. {
  85. m_spBrowserControl->put_Dispatch(NULL);
  86. m_spBrowserContainer->put_Dispatch(NULL);
  87. m_spBrowserControl.Release();
  88. m_spBrowserContainer.Release();
  89. bHandled = FALSE;
  90. return 0;
  91. }
  92. LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  93. {
  94. AtlAxWinInit();
  95. RECT rcClient;
  96. GetClientRect(&rcClient);
  97. USES_CONVERSION;
  98. m_wndView.Create(m_hWnd, rcClient, OLE2T(m_dlgOpen.m_bstrName), WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN, WS_EX_CLIENTEDGE);
  99. m_wndBrowserControl.Create(m_hWnd, rcClient, _T(""), WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
  100. m_wndBrowserContainer.Create(m_hWnd, rcClient, _T(""), WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
  101. // Create two instances of the property browser
  102. CPropertyBrowseControl::CreateInstance(&m_spBrowserControl);
  103. CPropertyBrowseControl::CreateInstance(&m_spBrowserContainer);
  104. {
  105. // Obtain a pointer to the container object
  106. CComPtr<IAxWinHostWindow> spContainer;
  107. m_wndBrowserControl.QueryHost(&spContainer);
  108. // Attach the browser control to the container
  109. spContainer->AttachControl(m_spBrowserControl, m_wndBrowserControl);
  110. }
  111. {
  112. // Obtain a pointer to the container object
  113. CComPtr<IAxWinHostWindow> spContainer;
  114. m_wndBrowserContainer.QueryHost(&spContainer);
  115. // Attach the browser control to the container
  116. spContainer->AttachControl(m_spBrowserContainer, m_wndBrowserContainer);
  117. // Get the container for the users control window
  118. CComPtr<IDispatch> spDispatch;
  119. m_wndView.QueryHost(&spDispatch);
  120. // Tell the browser to browse it
  121. m_spBrowserContainer->put_Dispatch(spDispatch);
  122. }
  123. return 0;
  124. }
  125. LRESULT OnErase(UINT /* uMsg */, WPARAM /* wParam */, LPARAM /* lParam */, BOOL& bHandled)
  126. {
  127. return 1;
  128. }
  129. LRESULT OnSize(UINT /* uMsg */, WPARAM /* wParam */, LPARAM /* lParam */, BOOL& /* lResult */)
  130. {
  131. RECT rcClient;
  132. GetClientRect(&rcClient);
  133. m_wndBrowserControl.MoveWindow(rcClient.left, rcClient.top, 250, rcClient.bottom / 2);
  134. m_wndBrowserContainer.MoveWindow(rcClient.left, rcClient.bottom / 2, 250, rcClient.bottom / 2);
  135. m_wndView.MoveWindow(rcClient.left+250, rcClient.top, rcClient.right-250, rcClient.bottom);
  136. return 0;
  137. }
  138. LRESULT OnFileOpen(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  139. {
  140. if (m_dlgOpen.DoModal(m_hWnd) == IDOK)
  141. {
  142. m_spBrowserControl->put_Dispatch(NULL);
  143. CComPtr<IAxWinHostWindow> spHost;
  144. m_wndView.QueryHost(&spHost);
  145. spHost->CreateControl(m_dlgOpen.m_bstrName, m_wndView, 0);
  146. CComPtr<IDispatch> spDispatch;
  147. m_wndView.QueryControl(&spDispatch);
  148. m_spBrowserControl->put_Dispatch(spDispatch);
  149. }
  150. return 0;
  151. }
  152. LRESULT OnFileExit(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  153. {
  154. DestroyWindow();
  155. return 0;
  156. }
  157. CComPtr<IATLConPropertyBrowser> m_spBrowserContainer;
  158. CComPtr<IATLConPropertyBrowser> m_spBrowserControl;
  159. // This ActiveX control will browse the container
  160. CAxWindow m_wndBrowserContainer;
  161. // This ActiveX control will browse the control
  162. CAxWindow m_wndBrowserControl;
  163. // This ActiveX control will be defined by the user
  164. CAxWindow m_wndView;
  165. CFileOpenDlg m_dlgOpen;
  166. };