Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

259 lines
7.9 KiB

  1. //=--------------------------------------------------------------------------=
  2. // CtlHelper.Cpp
  3. //=--------------------------------------------------------------------------=
  4. // Copyright 1995 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. // helper routines for our COleControl implementation
  13. //
  14. #include "pch.h"
  15. #include "CtrlObj.H"
  16. #include "CtlHelp.H"
  17. #include <windowsx.h>
  18. // for ASSERT and FAIL
  19. //
  20. SZTHISFILE
  21. //=--------------------------------------------------------------------------=
  22. // this is used by the window reflection code.
  23. //
  24. extern BYTE g_fRegisteredReflect;
  25. extern const char g_szReflectClassName [];
  26. // define this here, since it's the only guid we really need to define in the
  27. // framework -- the user control defines all other interesting guids.
  28. //
  29. static const GUID IID_IControlPrv =
  30. { 0xd97180, 0xfcf7, 0x11ce, { 0xa0, 0x9e, 0x0, 0xaa, 0x0, 0x62, 0xbe, 0x57 } };
  31. //=--------------------------------------------------------------------------=
  32. // _SpecialKeyState
  33. //=--------------------------------------------------------------------------=
  34. // returns a short with some information on which of the SHIFT, ALT, and CTRL
  35. // keys are set.
  36. //
  37. // Output:
  38. // short - bit 0 is shift, bit 1 is ctrl, bit 2 is ALT.
  39. //
  40. // Notes:
  41. //
  42. short _SpecialKeyState()
  43. {
  44. // don't appear to be able to reduce number of calls to GetKeyState
  45. //
  46. BOOL bShift = (GetKeyState(VK_SHIFT) < 0);
  47. BOOL bCtrl = (GetKeyState(VK_CONTROL) < 0);
  48. BOOL bAlt = (GetKeyState(VK_MENU) < 0);
  49. return (short)(bShift + (bCtrl << 1) + (bAlt << 2));
  50. }
  51. //=--------------------------------------------------------------------------=
  52. // CopyOleVerb [helper]
  53. //=--------------------------------------------------------------------------=
  54. // copies an OLEVERB structure. used in CStandardEnum
  55. //
  56. // Parameters:
  57. // void * - [out] where to copy to
  58. // const void * - [in] where to copy from
  59. // DWORD - [in] bytes to copy
  60. //
  61. // Notes:
  62. //
  63. void WINAPI CopyOleVerb
  64. (
  65. void *pvDest,
  66. const void *pvSrc,
  67. DWORD cbCopy
  68. )
  69. {
  70. VERBINFO * pVerbDest = (VERBINFO *) pvDest;
  71. const VERBINFO * pVerbSrc = (const VERBINFO *) pvSrc;
  72. *pVerbDest = *pVerbSrc;
  73. ((OLEVERB *)pVerbDest)->lpszVerbName = OLESTRFROMRESID((WORD)((VERBINFO *)pvSrc)->idVerbName);
  74. }
  75. //=--------------------------------------------------------------------------=
  76. // ControlFromUnknown [helper, callable]
  77. //=--------------------------------------------------------------------------=
  78. // given an unknown, get the COleControl pointer for it.
  79. //
  80. // Parameters:
  81. // IUnknown * - [in]
  82. //
  83. // Output:
  84. // HRESULT
  85. //
  86. // Notes:
  87. //
  88. COleControl *ControlFromUnknown
  89. (
  90. IUnknown *pUnk
  91. )
  92. {
  93. HRESULT hr;
  94. IControlPrv *pControlPrv = NULL;
  95. COleControl *pCtl = NULL;
  96. if (!pUnk) return NULL;
  97. hr = pUnk->QueryInterface(IID_IControlPrv, (void **)&pControlPrv);
  98. ASSERT(SUCCEEDED(hr), "Failed to get IControlPrv interface");
  99. hr = pControlPrv->GetControl(&pCtl);
  100. ASSERT(SUCCEEDED(hr), "Failed to get COleControl pointer");
  101. QUICK_RELEASE(pControlPrv);
  102. return pCtl;
  103. }
  104. //=--------------------------------------------------------------------------=
  105. // CreateReflectWindow [blech]
  106. //=--------------------------------------------------------------------------=
  107. // unfortunately, in certain cases, we have to create two windows, one of
  108. // which exists strictly to reflect messages on to the control. Majorly
  109. // lame. Fortunately, the number of hosts which require this is quite small.
  110. //
  111. // Parameters:
  112. // BOOL - [in] should it be created visible?
  113. // HWND - [in] parent window
  114. // int - [in] x pos
  115. // int - [in] y pos
  116. // SIZEL * - [in] size
  117. //
  118. // Output:
  119. // HWND - reflecting hwnd or NULL if it failed.
  120. //
  121. // Notes:
  122. //
  123. HWND CreateReflectWindow
  124. (
  125. BOOL fVisible,
  126. HWND hwndParent,
  127. int x,
  128. int y,
  129. SIZEL *pSize
  130. )
  131. {
  132. WNDCLASS wndclass;
  133. // first thing to do is register the window class. crit sect this
  134. // so we don't have to move it into the control
  135. //
  136. ENTERCRITICALSECTION1(&g_CriticalSection);
  137. if (!g_fRegisteredReflect) {
  138. memset(&wndclass, 0, sizeof(wndclass));
  139. wndclass.lpfnWndProc = COleControl::ReflectWindowProc;
  140. wndclass.hInstance = g_hInstance;
  141. wndclass.lpszClassName = g_szReflectClassName;
  142. if (!RegisterClass(&wndclass)) {
  143. FAIL("Couldn't Register Parking Window Class!");
  144. LEAVECRITICALSECTION1(&g_CriticalSection);
  145. return NULL;
  146. }
  147. g_fRegisteredReflect = TRUE;
  148. }
  149. LEAVECRITICALSECTION1(&g_CriticalSection);
  150. // go and create the window.
  151. //
  152. return CreateWindowEx(0, g_szReflectClassName, NULL,
  153. WS_CHILD | WS_CLIPSIBLINGS |((fVisible) ? WS_VISIBLE : 0),
  154. x, y, pSize->cx, pSize->cy,
  155. hwndParent,
  156. NULL, g_hInstance, NULL);
  157. }
  158. //=--------------------------------------------------------------------------=
  159. // in case the user doesn't want our default window proc, we support
  160. // letting them specify one themselves. this is defined in their main ipserver
  161. // file.
  162. //
  163. // Note: As of VB6 we added ParkingWindowProc to the framework.
  164. // The ParkingWindowProc supports message reflection which is normally
  165. // the code you add to your implementation of ParkingWindowProc.
  166. // In most cases you can probably set this to NULL in your control's
  167. // implementation
  168. //
  169. extern WNDPROC g_ParkingWindowProc;
  170. //=--------------------------------------------------------------------------=
  171. // GetParkingWindow
  172. //=--------------------------------------------------------------------------=
  173. // creates the global parking window that we'll use to parent things, or
  174. // returns the already existing one
  175. //
  176. // Output:
  177. // HWND - our parking window
  178. //
  179. // Notes:
  180. //
  181. HWND GetParkingWindow
  182. (
  183. void
  184. )
  185. {
  186. WNDCLASS wndclass;
  187. // crit sect this creation for apartment threading support.
  188. //
  189. ENTERCRITICALSECTION1(&g_CriticalSection);
  190. if (g_hwndParking)
  191. goto CleanUp;
  192. ZeroMemory(&wndclass, sizeof(wndclass));
  193. wndclass.lpfnWndProc = (g_ParkingWindowProc) ? g_ParkingWindowProc : COleControl::ParkingWindowProc;
  194. wndclass.hInstance = g_hInstance;
  195. wndclass.lpszClassName = "CtlFrameWork_Parking";
  196. if (!RegisterClass(&wndclass)) {
  197. FAIL("Couldn't Register Parking Window Class!");
  198. goto CleanUp;
  199. }
  200. g_hwndParking = CreateWindow("CtlFrameWork_Parking", NULL, WS_POPUP, 0, 0, 0, 0, NULL, NULL, g_hInstance, NULL);
  201. ASSERT(g_hwndParking, "Couldn't Create Global parking window!!");
  202. CleanUp:
  203. LEAVECRITICALSECTION1(&g_CriticalSection);
  204. return g_hwndParking;
  205. }
  206. //=--------------------------------------------------------------------------=
  207. // ParkingWindowProc
  208. //=--------------------------------------------------------------------------=
  209. // Provides default processing for the parking window. Since your control
  210. // may be parented by the parking window, we provide message reflection.
  211. //
  212. LRESULT CALLBACK COleControl::ParkingWindowProc
  213. (
  214. HWND hwnd,
  215. UINT msg,
  216. WPARAM wParam,
  217. LPARAM lParam
  218. )
  219. {
  220. LRESULT lResult;
  221. // If the message is reflected then return the result of the OCM_ message
  222. //
  223. if (ReflectOcmMessage(hwnd, msg, wParam, lParam, &lResult))
  224. return lResult;
  225. return DefWindowProc(hwnd, msg, wParam, lParam);
  226. }