home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / com / activexcontrol / basectl / todosvr / todoctl.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-10-05  |  12.2 KB  |  401 lines

  1. //=--------------------------------------------------------------------------=
  2. // ToDoCtl.Cpp
  3. //=--------------------------------------------------------------------------=
  4. // Copyright 1995-1997 Microsoft Corporation.  All Rights Reserved.
  5. //
  6. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF 
  7. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO 
  8. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 
  9. // PARTICULAR PURPOSE.
  10. //=--------------------------------------------------------------------------=
  11. //
  12. #include "IPServer.H"
  13.  
  14. #include "Guids.H"
  15. #include "ToDoCtl.H"
  16. #include "LocalObj.H"
  17. #include "Util.H"
  18. #include "Globals.H"
  19. #include "Resource.H"
  20.  
  21. #include <commctrl.h>
  22.  
  23. // for ASSERT and FAIL
  24. //
  25. SZTHISFILE
  26.  
  27.  
  28. //=--------------------------------------------------------------------------=
  29. // all the events in this control
  30. //
  31. // TODO: add events here ...
  32. //
  33.  
  34. //=--------------------------------------------------------------------------=
  35. // array describing all of our property pages.  these clsids are typically
  36. // in guids.h
  37. //
  38. // TODO: add any additional property page guids here ...
  39. //
  40. const GUID *rgToDoPropPages [] = {
  41.     &CLSID_ToDoGeneralPage
  42. };
  43.  
  44. //=--------------------------------------------------------------------------=
  45. // Custum Verb information
  46. //
  47. // TODO: add any custom verbs here in an array, using the VERBINFO structure.
  48. //       then mark the controld def'n in ToDoCtl.H with
  49. //       this verb array
  50. //
  51.  
  52.  
  53. //=--------------------------------------------------------------------------=
  54. // CToDoControl::Create
  55. //=--------------------------------------------------------------------------=
  56. // global static function that creates an instance of the control an returns
  57. // an IUnknown pointer for it.
  58. //
  59. // Parameters:
  60. //    IUnknown *        - [in] controlling unknown for aggregation
  61. //
  62. // Output:
  63. //    IUnknown *        - new object.
  64. //
  65. // Notes:
  66. //
  67. IUnknown *CToDoControl::Create(IUnknown *pUnkOuter)
  68. {
  69.     // make sure we return the private unknown so that we support aggegation
  70.     // correctly!
  71.     //
  72.     CToDoControl *pNew = new CToDoControl(pUnkOuter);
  73.     return pNew->PrivateUnknown();
  74. }
  75.  
  76. //=--------------------------------------------------------------------------=
  77. // CToDoControl::CToDoControl
  78. //=--------------------------------------------------------------------------=
  79. // "Being born is like being kidnapped.  And then sold into slavery."
  80. //    - andy warhol (1928 - 87)
  81. //
  82. // Parameters:
  83. //    IUnknown *        - [in]
  84. //
  85. // Notes:
  86. //
  87. #pragma warning(disable:4355)  // using 'this' in constructor
  88. CToDoControl::CToDoControl(IUnknown* pUnkOuter)
  89.     : CDocumentObject(pUnkOuter, OBJECT_TYPE_CTLTODO, (IDispatch *)this)
  90. {
  91.     // initialize anything here ...
  92.     //
  93.     memset(&m_state, 0, sizeof(TODOCTLSTATE));
  94.  
  95.     // TODO: initialize anything you need to here.
  96.  
  97. }
  98. #pragma warning(default:4355)  // using 'this' in constructor
  99.  
  100. //=--------------------------------------------------------------------------=
  101. // CToDoControl::~CToDoControl
  102. //=--------------------------------------------------------------------------=
  103. // "We all labour against our own cure, for death is the cure of all diseases"
  104. //    - Sir Thomas Browne (1605 - 82)
  105. //
  106. // Notes:
  107. //
  108. CToDoControl::~CToDoControl ()
  109. {
  110.     // TODO: clean up anything here.
  111. }
  112.  
  113. //=--------------------------------------------------------------------------=
  114. // CToDoControl:RegisterClassData
  115. //=--------------------------------------------------------------------------=
  116. // register the window class information for your control here.
  117. // this information will automatically get cleaned up for you on DLL shutdown.
  118. //
  119. // Output:
  120. //    BOOL            - FALSE means fatal error.
  121. //
  122. // Notes:
  123. //
  124. BOOL CToDoControl::RegisterClassData(void)
  125. {
  126.     WNDCLASS wndclass;
  127.  
  128.     // subclass a windows ListView control.
  129.     //
  130.     if (!::GetClassInfo(g_hInstance, WC_LISTVIEW, &wndclass))
  131.         return FALSE;
  132.  
  133.     // this doesn't need a critical section for apartment threading support
  134.     // since it's already in a critical section in CreateInPlaceWindow
  135.     //
  136.     SUBCLASSWNDPROCOFCONTROL(OBJECT_TYPE_CTLTODO) = (WNDPROC)wndclass.lpfnWndProc;
  137.     wndclass.lpfnWndProc = COleControl::ControlWindowProc;
  138.     wndclass.lpszClassName = WNDCLASSNAMEOFCONTROL(OBJECT_TYPE_CTLTODO);
  139.  
  140.     return RegisterClass(&wndclass);
  141. }
  142.  
  143. //=--------------------------------------------------------------------------=
  144. // CToDoControl::BeforeCreateWindow
  145. //=--------------------------------------------------------------------------=
  146. // called just before the window is created.  Great place to set up the
  147. // window title, etc, so that they're passed in to the call to CreateWindowEx.
  148. // speeds things up slightly.
  149. //
  150. // Parameters:
  151. //    DWORD *            - [out] dwWindowFlags
  152. //    DWORD *            - [out] dwExWindowFlags
  153. //    LPSTR              - [out] name of window to create
  154. //
  155. // Notes:
  156. //
  157. BOOL CToDoControl::BeforeCreateWindow
  158. (
  159.     DWORD *pdwWindowStyle,
  160.     DWORD *pdwExWindowStyle,
  161.     LPSTR  pszWindowTitle
  162. )
  163. {
  164.     // TODO: users should set the values of *pdwWindowStyle, *pdwExWindowStyle,
  165.     // and pszWindowTitle so that the call to CreateWindowEx can use them. setting
  166.     // them here instead of calling SetWindowStyle in WM_CREATE is a huge perf win
  167.     // if you don't use this function, then you can probably just remove it.
  168.     //
  169.     lstrcpy(pszWindowTitle, "ToDo");
  170.     return TRUE;
  171. }
  172.  
  173. //=--------------------------------------------------------------------------=
  174. // CToDoControl::InternalQueryInterface
  175. //=--------------------------------------------------------------------------=
  176. // qi for things only we support.
  177. //
  178. // Parameters:
  179. // Parameters:
  180. //    REFIID        - [in]  interface they want
  181. //    void **       - [out] where they want to put the resulting object ptr.
  182. //
  183. // Output:
  184. //    HRESULT       - S_OK, E_NOINTERFACE
  185. //
  186. // Notes:
  187. //
  188. HRESULT CToDoControl::InternalQueryInterface
  189. (
  190.     REFIID  riid,
  191.     void  **ppvObjOut
  192. )
  193. {
  194.     IUnknown *pUnk;
  195.  
  196.     *ppvObjOut = NULL;
  197.  
  198.     // TODO: if you want to support any additional interrfaces, then you should
  199.     // indicate that here.  never forget to call the base class version in the
  200.     // case where you don't support the given interface.
  201.     //
  202.     if (DO_GUIDS_MATCH(riid, IID_IToDo)) {
  203.         pUnk = (IUnknown *)(IToDo *)this;
  204.     } else{
  205.         return CDocumentObject::InternalQueryInterface(riid, ppvObjOut);
  206.     }
  207.  
  208.     pUnk->AddRef();
  209.     *ppvObjOut = (void *)pUnk;
  210.     return S_OK;
  211. }
  212.  
  213. //=--------------------------------------------------------------------------=
  214. // CToDoControl::LoadTextState
  215. //=--------------------------------------------------------------------------=
  216. // load in our text state for this control.
  217. //
  218. // Parameters:
  219. //    IPropertyBag *        - [in] property bag to read from
  220. //    IErrorLog *           - [in] errorlog object to use with proeprty bag
  221. //
  222. // Output:
  223. //    HRESULT
  224. //
  225. // Notes:
  226. //    - NOTE: if you have a binary object, then you should pass an unknown
  227. //      pointer to the property bag, and it will QI it for IPersistStream, and
  228. //      get said object to do a Load()
  229. //
  230. STDMETHODIMP CToDoControl::LoadTextState
  231. (
  232.     IPropertyBag *pPropertyBag,
  233.     IErrorLog    *pErrorLog
  234. )
  235. {
  236.     // TODO: implement your text load code here.
  237.     //
  238.     return S_OK;
  239. }
  240.  
  241. //=--------------------------------------------------------------------------=
  242. // CToDoControl::LoadBinaryState
  243. //=--------------------------------------------------------------------------=
  244. // loads in our binary state using streams.
  245. //
  246. // Parameters:
  247. //    IStream *            - [in] stream to write to.
  248. //
  249. // Output:
  250. //    HRESULT
  251. //
  252. // Notes:
  253. //
  254. STDMETHODIMP CToDoControl::LoadBinaryState
  255. (
  256.     IStream *pStream
  257. )
  258. {
  259.     // TODO: implement your binary load code here.  to prevent this from being
  260.     // a massive performance sink, you should probably try to organize your
  261.     // properties in such a way that enables you to do just one IStream::Read
  262.     // in the LoadBinaryState function.  fast is good.
  263.     //
  264.     return S_OK;
  265. }
  266.  
  267. //=--------------------------------------------------------------------------=
  268. // CToDoControl::SaveTextState
  269. //=--------------------------------------------------------------------------=
  270. // saves out the text state for this control using a property bag.
  271. //
  272. // Parameters:
  273. //    IPropertyBag *        - [in] the property bag with which to work.
  274. //    BOOL                  - [in] if TRUE, then write out ALL properties, even
  275. //                            if they're their the default value ...
  276. //
  277. // Output:
  278. //    HRESULT
  279. //
  280. // Notes:
  281. //
  282. STDMETHODIMP CToDoControl::SaveTextState
  283. (
  284.     IPropertyBag *pPropertyBag,
  285.     BOOL          fWriteDefaults
  286. )
  287. {
  288.     // TODO: implement your text save code here.
  289.     //
  290.     return S_OK;
  291. }
  292.  
  293. //=--------------------------------------------------------------------------=
  294. // CToDoControl::SaveBinaryState
  295. //=--------------------------------------------------------------------------=
  296. // save out the binary state for this control, using the given IStream object.
  297. //
  298. // Parameters:
  299. //    IStream  *             - [in] save to which you should save.
  300. //
  301. // Output:
  302. //    HRESULT
  303. //
  304. // Notes:
  305. //    - it is important that you seek to the end of where you saved your
  306. //      properties when you're done with the IStream.
  307. //
  308. STDMETHODIMP CToDoControl::SaveBinaryState
  309. (
  310.     IStream *pStream
  311. )
  312. {
  313.     // TODO: implement your binary save state code here.  to prevent this from being
  314.     // a massive performance sink, you should probably try to organize your
  315.     // properties in such a way that enables you to do just one IStream::Read
  316.     // in the LoadBinaryState function.  fast is good.
  317.     //
  318.     return S_OK;
  319. }
  320.  
  321.  
  322. //=--------------------------------------------------------------------------=
  323. // CToDoControl::OnDraw
  324. //=--------------------------------------------------------------------------=
  325. // "I don't very much enjoy looking at paintings in general.  i know too
  326. //  much about them.  i take them apart."
  327. //    - georgia o'keeffe (1887-1986)
  328. //
  329. // Parameters:
  330. //    DWORD              - [in]  drawing aspect
  331. //    HDC                - [in]  HDC to draw to
  332. //    LPCRECTL           - [in]  rect we're drawing to
  333. //    LPCRECTL           - [in]  window extent and origin for meta-files
  334. //    HDC                - [in]  HIC for target device
  335. //    BOOL               - [in]  can we optimize dc handling?
  336. //
  337. // Output:
  338. //    HRESULT
  339. //
  340. // Notes:
  341. //
  342. HRESULT CToDoControl::OnDraw
  343. (
  344.     DWORD    dvAspect,
  345.     HDC      hdcDraw,
  346.     LPCRECTL prcBounds,
  347.     LPCRECTL prcWBounds,
  348.     HDC      hicTargetDevice,
  349.     BOOL     fOptimize
  350. )
  351. {
  352.     // TODO: put your drawing code here ...
  353.     //
  354.     return DoSuperClassPaint(hdcDraw, prcBounds);
  355. }
  356.  
  357. //=--------------------------------------------------------------------------=
  358. // CToDoControl::WindowProc
  359. //=--------------------------------------------------------------------------=
  360. // window procedure for this control.  nothing terribly exciting.
  361. //
  362. // Parameters:
  363. //     see win32sdk on window procs.
  364. //
  365. // Notes:
  366. //
  367. LRESULT CToDoControl::WindowProc
  368. (
  369.     UINT   msg,
  370.     WPARAM wParam,
  371.     LPARAM lParam
  372. )
  373. {
  374.     // TODO: handle any messages here, like in a normal window
  375.     // proc.  note that for special keys, you'll want to override and
  376.     // implement OnSpecialKey.
  377.     //
  378.     return CallWindowProc((WNDPROC)(FARPROC)SUBCLASSWNDPROCOFCONTROL(OBJECT_TYPE_CTLTODO), (HWND) m_hwnd, msg, wParam, lParam);
  379. }
  380.  
  381. //=--------------------------------------------------------------------------=
  382. // CToDoControl::AboutBox
  383. //=--------------------------------------------------------------------------=
  384. // prints up an about box.  fweeeee.
  385. //
  386. // Notes:
  387. //
  388. void CToDoControl::AboutBox
  389. (
  390.     void
  391. )
  392. {
  393.     // TODO: Ideally, one would use DialogBox, and some sort of Dialog Box here if
  394.     // they wanted a slightly more interesting About Box ...  you should
  395.     // still call ModalDialog first, however.
  396.     //
  397.     ModalDialog(TRUE);
  398.     MessageBox(NULL, "Sample DocObject Server", "About ToDo", MB_OK | MB_TASKMODAL);
  399.     ModalDialog(FALSE);
  400. }
  401.