home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / atl / atlcon / atlcon1.h < prev    next >
C/C++ Source or Header  |  1998-04-03  |  6KB  |  184 lines

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