Source code of Windows XP (NT5)
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.

290 lines
8.6 KiB

  1. //=--------------------------------------------------------------------------=
  2. // CtlHelp.Cpp
  3. //=--------------------------------------------------------------------------=
  4. // Copyright 1995-1996 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 "IPServer.H"
  15. #include "CtrlObj.H"
  16. #include "CtlHelp.H"
  17. #include "Util.H"
  18. #include <windows.h>
  19. // for ASSERT and FAIL
  20. //
  21. SZTHISFILE
  22. //=--------------------------------------------------------------------------=
  23. // this is used by the window reflection code.
  24. //
  25. extern BYTE g_fRegisteredReflect;
  26. extern char g_szReflectClassName [];
  27. // define this here, since it's the only guid we really need to define in the
  28. // framework -- the user control defines all other interesting guids.
  29. //
  30. static const GUID IID_IControlPrv =
  31. { 0xd97180, 0xfcf7, 0x11ce, { 0xa0, 0x9e, 0x0, 0xaa, 0x0, 0x62, 0xbe, 0x57 } };
  32. // this table is used for copying data around, and persisting properties.
  33. // basically, it contains the size of a given data type
  34. //
  35. const BYTE g_rgcbDataTypeSize[] = {
  36. 0, // VT_EMPTY= 0,
  37. 0, // VT_NULL= 1,
  38. sizeof(short), // VT_I2= 2,
  39. sizeof(long), // VT_I4 = 3,
  40. sizeof(float), // VT_R4 = 4,
  41. sizeof(double), // VT_R8= 5,
  42. sizeof(CURRENCY), // VT_CY= 6,
  43. sizeof(DATE), // VT_DATE = 7,
  44. sizeof(BSTR), // VT_BSTR = 8,
  45. sizeof(IDispatch *), // VT_DISPATCH = 9,
  46. sizeof(SCODE), // VT_ERROR = 10,
  47. sizeof(VARIANT_BOOL), // VT_BOOL = 11,
  48. sizeof(VARIANT), // VT_VARIANT= 12,
  49. sizeof(IUnknown *), // VT_UNKNOWN= 13,
  50. };
  51. const BYTE g_rgcbPromotedDataTypeSize[] = {
  52. 0, // VT_EMPTY= 0,
  53. 0, // VT_NULL= 1,
  54. sizeof(int ), // VT_I2= 2,
  55. sizeof(long), // VT_I4 = 3,
  56. sizeof(double), // VT_R4 = 4,
  57. sizeof(double), // VT_R8= 5,
  58. sizeof(CURRENCY), // VT_CY= 6,
  59. sizeof(DATE), // VT_DATE = 7,
  60. sizeof(BSTR), // VT_BSTR = 8,
  61. sizeof(IDispatch *), // VT_DISPATCH = 9,
  62. sizeof(SCODE), // VT_ERROR = 10,
  63. sizeof(int), // VT_BOOL = 11,
  64. sizeof(VARIANT), // VT_VARIANT= 12,
  65. sizeof(IUnknown *), // VT_UNKNOWN= 13,
  66. };
  67. //=--------------------------------------------------------------------------=
  68. // _SpecialKeyState
  69. //=--------------------------------------------------------------------------=
  70. // returns a short with some information on which of the SHIFT, ALT, and CTRL
  71. // keys are set.
  72. //
  73. // Output:
  74. // short - bit 0 is shift, bit 1 is ctrl, bit 2 is ALT.
  75. //
  76. // Notes:
  77. //
  78. short _SpecialKeyState()
  79. {
  80. // don't appear to be able to reduce number of calls to GetKeyState
  81. //
  82. BOOL bShift = (GetKeyState(VK_SHIFT) < 0);
  83. BOOL bCtrl = (GetKeyState(VK_CONTROL) < 0);
  84. BOOL bAlt = (GetKeyState(VK_MENU) < 0);
  85. return (short)(bShift + (bCtrl << 1) + (bAlt << 2));
  86. }
  87. //=--------------------------------------------------------------------------=
  88. // CopyAndAddRefObject
  89. //=--------------------------------------------------------------------------=
  90. // copies an object pointer, and then addref's the object.
  91. //
  92. // Parameters:
  93. // void * - [in] dest.
  94. // const void * - [in] src
  95. // DWORD - [in] size, ignored, since it's always 4
  96. //
  97. // Notes:
  98. //
  99. void WINAPI CopyAndAddRefObject
  100. (
  101. void *pDest,
  102. const void *pSource,
  103. DWORD dwSize
  104. )
  105. {
  106. ASSERT(pDest && pSource, "Bogus Pointer(s) passed into CopyAndAddRefObject!!!!");
  107. *((IUnknown **)pDest) = *((IUnknown **)pSource);
  108. ADDREF_OBJECT(*((IUnknown **)pDest));
  109. return;
  110. }
  111. //=--------------------------------------------------------------------------=
  112. // CopyOleVerb [helper]
  113. //=--------------------------------------------------------------------------=
  114. // copies an OLEVERB structure. used in CStandardEnum
  115. //
  116. // Parameters:
  117. // void * - [out] where to copy to
  118. // const void * - [in] where to copy from
  119. // DWORD - [in] bytes to copy
  120. //
  121. // Notes:
  122. //
  123. void WINAPI CopyOleVerb
  124. (
  125. void *pvDest,
  126. const void *pvSrc,
  127. DWORD cbCopy
  128. )
  129. {
  130. VERBINFO * pVerbDest = (VERBINFO *) pvDest;
  131. const VERBINFO * pVerbSrc = (const VERBINFO *) pvSrc;
  132. *pVerbDest = *pVerbSrc;
  133. ((OLEVERB *)pVerbDest)->lpszVerbName = OLESTRFROMRESID((WORD)((VERBINFO *)pvSrc)->idVerbName);
  134. }
  135. //=--------------------------------------------------------------------------=
  136. // ControlFromUnknown [helper, callable]
  137. //=--------------------------------------------------------------------------=
  138. // given an unknown, get the COleControl pointer for it.
  139. //
  140. // Parameters:
  141. // IUnknown * - [in]
  142. //
  143. // Output:
  144. // HRESULT
  145. //
  146. // Notes:
  147. //
  148. COleControl *ControlFromUnknown
  149. (
  150. IUnknown *pUnk
  151. )
  152. {
  153. COleControl *pCtl = NULL;
  154. if (!pUnk) return NULL;
  155. pUnk->QueryInterface(IID_IControlPrv, (void **)&pCtl);
  156. return pCtl;
  157. }
  158. //=--------------------------------------------------------------------------=
  159. // CreateReflectWindow [blech]
  160. //=--------------------------------------------------------------------------=
  161. // unfortunately, in certain cases, we have to create two windows, one of
  162. // which exists strictly to reflect messages on to the control.
  163. // Fortunately, the number of hosts which require this is quite small.
  164. //
  165. // Parameters:
  166. // BOOL - [in] should it be created visible?
  167. // HWND - [in] parent window
  168. // int - [in] x pos
  169. // int - [in] y pos
  170. // SIZEL * - [in] size
  171. //
  172. // Output:
  173. // HWND - reflecting hwnd or NULL if it failed.
  174. //
  175. // Notes:
  176. //
  177. HWND CreateReflectWindow
  178. (
  179. BOOL fVisible,
  180. HWND hwndParent,
  181. int x,
  182. int y,
  183. SIZEL *pSize
  184. )
  185. {
  186. WNDCLASS wndclass;
  187. // first thing to do is register the window class. crit sect this
  188. // so we don't have to move it into the control
  189. //
  190. EnterCriticalSection(&g_CriticalSection);
  191. if (!g_fRegisteredReflect) {
  192. memset(&wndclass, 0, sizeof(wndclass));
  193. wndclass.lpfnWndProc = COleControl::ReflectWindowProc;
  194. wndclass.hInstance = g_hInstance;
  195. wndclass.lpszClassName = g_szReflectClassName;
  196. if (!RegisterClass(&wndclass)) {
  197. FAIL("Couldn't Register Parking Window Class!");
  198. LeaveCriticalSection(&g_CriticalSection);
  199. return NULL;
  200. }
  201. g_fRegisteredReflect = TRUE;
  202. }
  203. LeaveCriticalSection(&g_CriticalSection);
  204. // go and create the window.
  205. //
  206. return CreateWindowEx(0, g_szReflectClassName, NULL,
  207. WS_CHILD | WS_CLIPSIBLINGS |((fVisible) ? WS_VISIBLE : 0),
  208. x, y, pSize->cx, pSize->cy,
  209. hwndParent,
  210. NULL, g_hInstance, NULL);
  211. }
  212. //=--------------------------------------------------------------------------=
  213. // in case the user doesn't want our default window proc, we support
  214. // letting them specify one themselves. this is defined in their main ipserver
  215. // file.
  216. //
  217. extern WNDPROC g_ParkingWindowProc;
  218. //=--------------------------------------------------------------------------=
  219. // GetParkingWindow
  220. //=--------------------------------------------------------------------------=
  221. // creates the global parking window that we'll use to parent things, or
  222. // returns the already existing one
  223. //
  224. // Output:
  225. // HWND - our parking window
  226. //
  227. // Notes:
  228. //
  229. HWND GetParkingWindow
  230. (
  231. void
  232. )
  233. {
  234. WNDCLASS wndclass;
  235. // crit sect this creation for apartment threading support.
  236. //
  237. EnterCriticalSection(&g_CriticalSection);
  238. if (g_hwndParking)
  239. goto CleanUp;
  240. ZeroMemory(&wndclass, sizeof(wndclass));
  241. wndclass.lpfnWndProc = (g_ParkingWindowProc) ? g_ParkingWindowProc : DefWindowProc;
  242. wndclass.hInstance = g_hInstance;
  243. wndclass.lpszClassName = "CtlFrameWork_Parking";
  244. if (!RegisterClass(&wndclass)) {
  245. FAIL("Couldn't Register Parking Window Class!");
  246. goto CleanUp;
  247. }
  248. g_hwndParking = CreateWindow("CtlFrameWork_Parking", NULL, WS_POPUP, 0, 0, 0, 0, NULL, NULL, g_hInstance, NULL);
  249. if (g_hwndParking != NULL)
  250. ++g_cLocks;
  251. ASSERT(g_hwndParking, "Couldn't Create Global parking window!!");
  252. CleanUp:
  253. LeaveCriticalSection(&g_CriticalSection);
  254. return g_hwndParking;
  255. }
  256.