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.

233 lines
5.3 KiB

  1. /*
  2. * INIT.C
  3. * GizmoBar Version 1.00, Win32 version August 1993
  4. *
  5. * LibMain entry point and initialization code for the GizmoBar
  6. * DLL that is likely to be used once or very infrequently.
  7. *
  8. * Copyright (c)1993 Microsoft Corporation, All Rights Reserved
  9. *
  10. * Kraig Brockschmidt, Software Design Engineer
  11. * Microsoft Systems Developer Relations
  12. *
  13. * Internet : kraigb@microsoft.com
  14. * Compuserve: >INTERNET:kraigb@microsoft.com
  15. */
  16. #include <windows.h>
  17. #include "gizmoint.h"
  18. /*
  19. * LibMain
  20. *
  21. * Purpose:
  22. * Entry point conditionally compiled for Windows NT and Windows
  23. * 3.1. Provides the proper structure for each environment
  24. * and calls InternalLibMain for real initialization.
  25. */
  26. #ifdef WIN32
  27. BOOL _cdecl LibMain(
  28. HINSTANCE hDll,
  29. DWORD dwReason,
  30. LPVOID lpvReserved)
  31. {
  32. if (DLL_PROCESS_ATTACH == dwReason)
  33. {
  34. return FRegisterControl(hDll);
  35. }
  36. else
  37. {
  38. return TRUE;
  39. }
  40. }
  41. #else
  42. HANDLE FAR PASCAL LibMain(HANDLE hInstance, WORD wDataSeg
  43. , WORD cbHeapSize, LPSTR lpCmdLine)
  44. {
  45. //Perform global initialization.
  46. if (FRegisterControl(hInstance))
  47. {
  48. if (0!=cbHeapSize)
  49. UnlockData(0);
  50. }
  51. return hInstance;
  52. }
  53. #endif
  54. /*
  55. * WEP
  56. *
  57. * Purpose:
  58. * Required DLL Exit function. Does nothing.
  59. *
  60. * Parameters:
  61. * bSystemExit BOOL indicating if the system is being shut
  62. * down or the DLL has just been unloaded.
  63. *
  64. * Return Value:
  65. * void
  66. *
  67. */
  68. void FAR PASCAL WEP(int bSystemExit)
  69. {
  70. return;
  71. }
  72. /*
  73. * FRegisterControl
  74. *
  75. * Purpose:
  76. * Registers the GizmoBar control class, including CS_GLOBALCLASS
  77. * to make the control available to all applications in the system.
  78. *
  79. * Parameters:
  80. * hInst HINSTANCE of the DLL that will own this class.
  81. *
  82. * Return Value:
  83. * BOOL TRUE if the class is registered, FALSE otherwise.
  84. */
  85. BOOL FRegisterControl(HINSTANCE hInst)
  86. {
  87. static BOOL fRegistered=FALSE;
  88. WNDCLASS wc;
  89. if (!fRegistered)
  90. {
  91. wc.lpfnWndProc =GizmoBarWndProc;
  92. wc.cbClsExtra =0;
  93. wc.cbWndExtra =CBWINDOWEXTRA;
  94. wc.hInstance =hInst;
  95. wc.hIcon =NULL;
  96. wc.hCursor =LoadCursor(NULL, IDC_ARROW);
  97. wc.hbrBackground =(HBRUSH)(COLOR_BTNFACE+1);
  98. wc.lpszMenuName =NULL;
  99. wc.lpszClassName =CLASS_GIZMOBAR;
  100. wc.style =CS_DBLCLKS | CS_GLOBALCLASS | CS_VREDRAW | CS_HREDRAW;
  101. fRegistered=RegisterClass(&wc);
  102. }
  103. return fRegistered;
  104. }
  105. /*
  106. * GizmoBarPAllocate
  107. *
  108. * Purpose:
  109. * Allocates and initializes the control's primary data structure for
  110. * each window that gets created.
  111. *
  112. * Parameters:
  113. * pfSuccess LPINT indicating success of the function.
  114. * hWnd HWND that is tied to this structure.
  115. * hInst HINSTANCE of the DLL.
  116. * hWndAssociate HWND to which we send messages.
  117. * dwStyle DWORD initial style.
  118. * uState UINT initial state.
  119. * uID UINT identifier for this window.
  120. *
  121. * Return Value:
  122. * LPGIZMOBAR If NULL returned then GizmoBarPAllocate could not allocate
  123. * memory. If a non-NULL pointer is returned with
  124. * *pfSuccess, then call GizmoBarPFree immediately. If you
  125. * get a non-NULL pointer and *pfSuccess==TRUE then the
  126. * function succeeded.
  127. */
  128. LPGIZMOBAR GizmoBarPAllocate(LPINT pfSuccess, HWND hWnd, HINSTANCE hInst
  129. , HWND hWndAssociate, DWORD dwStyle, UINT uState, UINT uID)
  130. {
  131. LPGIZMOBAR pGB;
  132. if (NULL==pfSuccess)
  133. return NULL;
  134. *pfSuccess=FALSE;
  135. //Allocate the structure
  136. pGB=(LPGIZMOBAR)(void *)LocalAlloc(LPTR, CBGIZMOBAR);
  137. if (NULL==pGB)
  138. return NULL;
  139. //Initialize LibMain parameter holders.
  140. pGB->hWnd =hWnd;
  141. pGB->hInst =hInst;
  142. pGB->hWndAssociate=hWndAssociate;
  143. pGB->dwStyle =dwStyle;
  144. pGB->uState =uState;
  145. pGB->uID =uID;
  146. pGB->fEnabled =TRUE;
  147. pGB->crFace=GetSysColor(COLOR_BTNFACE);
  148. pGB->hBrFace=CreateSolidBrush(pGB->crFace);
  149. if (NULL==pGB->hBrFace)
  150. return pGB;
  151. pGB->hFont=GetStockObject(SYSTEM_FONT);
  152. *pfSuccess=TRUE;
  153. return pGB;
  154. }
  155. /*
  156. * GizmoBarPFree
  157. *
  158. * Purpose:
  159. * Reverses all initialization done by GizmoBarPAllocate, cleaning up
  160. * any allocations including the application structure itself.
  161. *
  162. * Parameters:
  163. * pGB LPGIZMOBAR to the control's structure
  164. *
  165. * Return Value:
  166. * LPGIZMOBAR NULL if successful, pGB if not, meaning we couldn't
  167. * free some allocation.
  168. */
  169. LPGIZMOBAR GizmoBarPFree(LPGIZMOBAR pGB)
  170. {
  171. if (NULL==pGB)
  172. return NULL;
  173. /*
  174. * Free all the gizmos we own. When we call GizmoPFree we always
  175. * free the first one in the list which updates pGB->pGizmos for
  176. * us, so we just have to keep going until pGizmos is NULL, meaning
  177. * we're at the end of the list.
  178. */
  179. while (NULL!=pGB->pGizmos)
  180. GizmoPFree(&pGB->pGizmos, pGB->pGizmos);
  181. if (NULL!=pGB->hBrFace)
  182. DeleteObject(pGB->hBrFace);
  183. /*
  184. * Notice that since we never create a font, we aren't responsible
  185. * for our hFont member.
  186. */
  187. return (LPGIZMOBAR)(void *)LocalFree((HLOCAL)(void *)(LONG)pGB);
  188. }