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 / framewrk / ctlwrap.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-10-05  |  8.6 KB  |  336 lines

  1. //=--------------------------------------------------------------------------=
  2. // CtlWrap.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. // wrappers for various routines that have slightly different implementations
  13. // for windowed and windowless controls.
  14. //
  15. #include "IPServer.H"
  16.  
  17. #include "CtrlObj.H"
  18.  
  19.  
  20. // for ASSERT and FAIL
  21. //
  22. SZTHISFILE
  23.  
  24. //=--------------------------------------------------------------------------=
  25. // COleControl::OcxGetFocus    [wrapper]
  26. //=--------------------------------------------------------------------------=
  27. // indicates whether or not we have the focus.
  28. //
  29. // Parameters:
  30. //    none
  31. //
  32. // Output:
  33. //    TRUE if we have focus, else false
  34. //
  35. // Notes:
  36. //
  37. BOOL COleControl::OcxGetFocus
  38. (
  39.     void
  40. )
  41. {
  42.     // if we're windowless, the site provides this functionality
  43.     //
  44.     if (m_pInPlaceSiteWndless) {
  45.         return (m_pInPlaceSiteWndless->GetFocus() == S_OK);
  46.     } else {
  47.  
  48.         // we've got a window.  just let the APIs do our work
  49.         //
  50.         if (m_fInPlaceActive)
  51.             return (GetFocus() == m_hwnd);
  52.         else
  53.             return FALSE;
  54.     }
  55.  
  56.     // dead code
  57. }
  58.  
  59. //=--------------------------------------------------------------------------=
  60. // COleControl::OcxGetWindowRect    [wrapper]
  61. //=--------------------------------------------------------------------------=
  62. // returns the current rectangle for this control, and correctly handles
  63. // windowless vs windowed.
  64. //
  65. // Parameters:
  66. //    LPRECT                - [out]  duh.
  67. //
  68. // Output:
  69. //    BOOL                  - false means unexpected.
  70. //
  71. // Notes:
  72. //
  73. BOOL COleControl::OcxGetWindowRect
  74. (
  75.     LPRECT prc
  76. )
  77. {
  78.     // if we're windowless, then we have this information already!
  79.     //
  80.     if (Windowless()) {
  81.         *prc = m_rcLocation;
  82.         return TRUE;
  83.     } else
  84.         return GetWindowRect(m_hwnd, prc);
  85.  
  86.     // dead code
  87. }
  88.  
  89. //=--------------------------------------------------------------------------=
  90. // COleControl::OcxDefWindowProc    [wrapper]
  91. //=--------------------------------------------------------------------------=
  92. // default window processing
  93. //
  94. // Parameters:
  95. //    UINT           - [in] duh.
  96. //    WPARAM         - [in] duh.
  97. //    LPARAM         - [in] DUH.
  98. //
  99. // Output:
  100. //    LRESULT
  101. //
  102. // Notes:
  103. //
  104. LRESULT COleControl::OcxDefWindowProc
  105. (
  106.     UINT   msg,
  107.     WPARAM wParam,
  108.     LPARAM lParam
  109. )
  110. {
  111.     LRESULT l;
  112.  
  113.     // if we're windowless, this is a site provided pointer
  114.     //
  115.     if (m_pInPlaceSiteWndless)
  116.         m_pInPlaceSiteWndless->OnDefWindowMessage(msg, wParam, lParam, &l);
  117.     else
  118.         // we've got a window -- just pass it along
  119.         //
  120.         l = DefWindowProc(m_hwnd, msg, wParam, lParam);
  121.  
  122.     return l;
  123. }
  124.  
  125. //=--------------------------------------------------------------------------=
  126. // COleControl::OcxGetDC    [wrapper]
  127. //=--------------------------------------------------------------------------=
  128. // wraps the functionality of GetDC, and correctly handles windowless controls
  129. //
  130. // Parameters:
  131. //    none
  132. //
  133. // Output:
  134. //    HDC            - null means we couldn't get one
  135. //
  136. // Notes:
  137. //    - we don't bother with a bunch of the IOleInPlaceSiteWindowless::GetDc
  138. //      parameters, since the windows GetDC doesn't expose these either. users
  139. //      wanting that sort of fine tuned control can call said routine
  140. //      explicitly
  141. //
  142. HDC COleControl::OcxGetDC
  143. (
  144.     void
  145. )
  146. {
  147.     HDC hdc = NULL;
  148.  
  149.     // if we're windowless, the site provides this functionality.
  150.     //
  151.     if (m_pInPlaceSiteWndless)
  152.         m_pInPlaceSiteWndless->GetDC(NULL, 0, &hdc);
  153.     else
  154.         hdc = GetDC(m_hwnd);
  155.  
  156.     return hdc;
  157. }
  158.  
  159. //=--------------------------------------------------------------------------=
  160. // COleControl::OcxReleaseDC    [wrapper]
  161. //=--------------------------------------------------------------------------=
  162. // releases a DC returned by OcxGetDC
  163. //
  164. // Parameters:
  165. //    HDC             - [in] release me
  166. //
  167. // Output:
  168. //    none
  169. //
  170. // Notes:
  171. //
  172. void COleControl::OcxReleaseDC
  173. (
  174.     HDC hdc
  175. )
  176. {
  177.     // if we're windowless, the site does this for us
  178.     //
  179.     if (m_pInPlaceSiteWndless)
  180.         m_pInPlaceSiteWndless->ReleaseDC(hdc);
  181.     else
  182.         ReleaseDC(m_hwnd, hdc);
  183. }
  184.  
  185. //=--------------------------------------------------------------------------=
  186. // COleControl::OcxSetCapture    [wrapper]
  187. //=--------------------------------------------------------------------------=
  188. // provides a means for the control to get or release capture.
  189. //
  190. // Parameters:
  191. //    BOOL            - [in] true means take, false release
  192. //
  193. // Output:
  194. //    BOOL            - true means it's yours, false nuh-uh
  195. //
  196. // Notes:
  197. //
  198. BOOL COleControl::OcxSetCapture
  199. (
  200.     BOOL fGrab
  201. )
  202. {
  203.     HRESULT hr;
  204.  
  205.     // the host does this for us if we're windowless [i'm getting really bored
  206.     // of typing that]
  207.     //
  208.     if (m_pInPlaceSiteWndless) {
  209.         hr = m_pInPlaceSiteWndless->SetCapture(fGrab);
  210.         return (hr == S_OK);
  211.     } else {
  212.         // people shouldn't call this when they're not in-place active, but
  213.         // just in case...
  214.         //
  215.         if (m_fInPlaceActive) {
  216.             SetCapture(m_hwnd);
  217.             return TRUE;
  218.         } else
  219.             return FALSE;
  220.     }
  221.  
  222.     // dead code
  223. }
  224.  
  225. //=--------------------------------------------------------------------------=
  226. // COleControl::OcxGetCapture    [wrapper]
  227. //=--------------------------------------------------------------------------=
  228. // tells you whether or not you have the capture.
  229. //
  230. // Parameters:
  231. //    none
  232. //
  233. // Output:
  234. //    BOOL         - true it's yours, false it's not
  235. //
  236. // Notes:
  237. //
  238. BOOL COleControl::OcxGetCapture
  239. (
  240.     void
  241. )
  242. {
  243.     // host does this for windowless dudes
  244.     //
  245.     if (m_pInPlaceSiteWndless)
  246.         return m_pInPlaceSiteWndless->GetCapture() == S_OK;
  247.     else {
  248.         // people shouldn't call this when they're not in-place active, but
  249.         // just in case.
  250.         //
  251.         if (m_fInPlaceActive)
  252.             return GetCapture() == m_hwnd;
  253.         else
  254.             return FALSE;
  255.     }
  256.  
  257.     // dead code
  258. }
  259.  
  260. //=--------------------------------------------------------------------------=
  261. // COleControl::OcxInvalidateRect    [wrapper]
  262. //=--------------------------------------------------------------------------=
  263. // invalidates the control's rectangle
  264. //
  265. // Parameters:
  266. //    LPCRECT            - [in] rectangle to invalidate
  267. //    BOOL               - [in] do we erase background first?
  268. //
  269. // Output:
  270. //    BOOL
  271. //
  272. // Notes:
  273. //
  274. BOOL COleControl::OcxInvalidateRect
  275. (
  276.     LPCRECT prcInvalidate,
  277.     BOOL    fErase
  278. )
  279. {
  280.     // if we're windowless, then we need to get the site to do all this for
  281.     // us
  282.     if (m_pInPlaceSiteWndless)
  283.         return m_pInPlaceSiteWndless->InvalidateRect(prcInvalidate, fErase) == S_OK;
  284.     else {
  285.         // otherwise do something different depending on whether or not we're
  286.         // in place active or not
  287.         //
  288.         if (m_fInPlaceActive)
  289.             return InvalidateRect(m_hwnd, prcInvalidate, TRUE);
  290.         else
  291.             ViewChanged();
  292.     }
  293.  
  294.     return TRUE;
  295. }
  296.  
  297. //=--------------------------------------------------------------------------=
  298. // COleControl::OcxScrollRect    [wrapper]
  299. //=--------------------------------------------------------------------------=
  300. // does some window scrolling for the control
  301. //
  302. // Parameters:
  303. //    LPCRECT             - [in] region to scroll
  304. //    LPCRECT             - [in] region to clip
  305. //    int                 - [in] dx to scroll
  306. //    int                 - [in] dy to scroll
  307. //
  308. // Output:
  309. //    BOOL
  310. //
  311. // Notes:
  312. //
  313. BOOL COleControl::OcxScrollRect
  314. (
  315.     LPCRECT  prcBounds,
  316.     LPCRECT  prcClip,
  317.     int      dx,
  318.     int      dy
  319. )
  320. {
  321.     // if we're windowless, the site provides this functionality, otherwise
  322.     // APIs do the job
  323.     //
  324.     if (m_pInPlaceSiteWndless)
  325.         return m_pInPlaceSiteWndless->ScrollRect(dx, dy, prcBounds, prcClip) == S_OK;
  326.     else {
  327.         if (m_fInPlaceActive) 
  328.             ScrollWindowEx(m_hwnd, dx, dy, prcBounds, prcClip, NULL, NULL, SW_INVALIDATE);
  329.         else
  330.             return FALSE;
  331.     }
  332.  
  333.     return TRUE;
  334. }
  335.  
  336.