|
|
1.1 root 1: /*
2: * INIT.C
3: * GizmoBar Version 1.00, March 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)1992 Microsoft Corporation, All Rights Reserved
9: *
10: * Kraig Brockschmidt, Software Design Engineer
11: * Microsoft Systems Developer Relations
12: *
13: * Internet : [email protected]
14: * Compuserve: >INTERNET:[email protected]
15: */
16:
17: #ifdef WIN32
18: #define _INC_OLE
19: #define __RPC_H__
20: #endif
21:
22:
23: #define STRICT
24: #include <windows.h>
25: #include "gizmoint.h"
26:
27:
28:
29: /*
30: * LibMain
31: *
32: * Purpose:
33: * DLL-specific entry point called from LibEntry. Initializes
34: * the DLL's heap and registers the GizmoBar GizmoBar.
35: *
36: * Parameters:
37: * hInst HINSTANCE instance of the DLL.
38: * wDataSeg WORD segment selector of the DLL's data segment.
39: * wHeapSize WORD byte count of the heap.
40: * lpCmdLine LPSTR to command line used to start the module.
41: *
42: * Return Value:
43: * HANDLE Instance handle of the DLL.
44: *
45: */
46: #ifdef WIN32
47:
48: extern BOOL WINAPI _CRT_INIT(HINSTANCE hInst, DWORD dwReason, LPVOID lpReserved);
49: extern _cexit(void);
50: void FAR PASCAL WEP(int);
51:
52: extern BOOL __stdcall LibMain
53: (
54: HINSTANCE hInstance,
55: ULONG Reason,
56: PCONTEXT Context
57: )
58: {
59: OutputDebugString("gizmobar LibMain: gizmobar.dll loaded\r\n");
60:
61: UNREFERENCED_PARAMETER(Context);
62:
63: if (Reason == DLL_PROCESS_DETACH) {
64:
65: _cexit(); // BUGBUG32 replace with call to CRT_INIT when it's fixed
66:
67: WEP(0);
68: return TRUE;
69: }
70: else if (Reason != DLL_PROCESS_ATTACH)
71: return TRUE;
72:
73: if (!_CRT_INIT(hInstance,Reason,NULL))
74: return FALSE;
75:
76: return FRegisterControl(hInstance);
77:
78: }
79:
80: #else
81:
82: HANDLE FAR PASCAL LibMain(HINSTANCE hInst, WORD wDataSeg
83: , WORD cbHeapSize, LPSTR lpCmdLine)
84: {
85: //Go register the control
86: if (FRegisterControl(hInst))
87: {
88: if (0!=cbHeapSize)
89: UnlockData(0);
90:
91: return hInst;
92: }
93:
94: return (HANDLE)NULL;
95: }
96:
97:
98: #endif
99:
100:
101: /*
102: * WEP
103: *
104: * Purpose:
105: * Required DLL Exit function. Does nothing.
106: *
107: * Parameters:
108: * bSystemExit BOOL indicating if the system is being shut
109: * down or the DLL has just been unloaded.
110: *
111: * Return Value:
112: * void
113: *
114: */
115:
116: void FAR PASCAL WEP(int bSystemExit)
117: {
118: return;
119: }
120:
121:
122:
123:
124:
125:
126: /*
127: * FRegisterControl
128: *
129: * Purpose:
130: * Registers the GizmoBar control class, including CS_GLOBALCLASS
131: * to make the control available to all applications in the system.
132: *
133: * Parameters:
134: * hInst HINSTANCE of the DLL that will own this class.
135: *
136: * Return Value:
137: * BOOL TRUE if the class is registered, FALSE otherwise.
138: */
139:
140: BOOL FRegisterControl(HINSTANCE hInst)
141: {
142: static BOOL fRegistered=FALSE;
143: WNDCLASS wc;
144:
145: if (!fRegistered)
146: {
147: wc.lpfnWndProc =GizmoBarWndProc;
148: wc.cbClsExtra =0;
149: wc.cbWndExtra =CBWINDOWEXTRA;
150: wc.hInstance =hInst;
151: wc.hIcon =NULL;
152: wc.hCursor =LoadCursor(NULL, IDC_ARROW);
153: wc.hbrBackground =(HBRUSH)(COLOR_BTNFACE+1);
154: wc.lpszMenuName =NULL;
155: wc.lpszClassName =CLASS_GIZMOBAR;
156: wc.style =CS_DBLCLKS | CS_GLOBALCLASS | CS_VREDRAW | CS_HREDRAW;
157:
158: fRegistered=RegisterClass(&wc);
159: }
160:
161: return fRegistered;
162: }
163:
164:
165:
166:
167:
168:
169: /*
170: * GizmoBarPAllocate
171: *
172: * Purpose:
173: * Allocates and initializes the control's primary data structure for
174: * each window that gets created.
175: *
176: * Parameters:
177: * pfSuccess LPINT indicating success of the function.
178: * hWnd HWND that is tied to this structure.
179: * hInst HINSTANCE of the DLL.
180: * hWndAssociate HWND to which we send messages.
181: * dwStyle DWORD initial style.
182: * uState UINT initial state.
183: *
184: *
185: * Return Value:
186: * PGIZMOBAR If NULL returned then GizmoBarPAllocate could not allocate
187: * memory. If a non-NULL pointer is returned with
188: * *pfSuccess, then call GizmoBarPFree immediately. If you
189: * get a non-NULL pointer and *pfSuccess==TRUE then the
190: * function succeeded.
191: */
192:
193: PGIZMOBAR GizmoBarPAllocate(LPINT pfSuccess, HWND hWnd, HINSTANCE hInst
194: , HWND hWndAssociate, DWORD dwStyle, UINT uState)
195: {
196: PGIZMOBAR pGB;
197:
198: if (NULL==pfSuccess)
199: return NULL;
200:
201: *pfSuccess=FALSE;
202:
203: //Allocate the structure
204: pGB=(PGIZMOBAR)(char *)LocalAlloc(LPTR, CBGIZMOBAR);
205:
206: if (NULL==pGB)
207: return NULL;
208:
209: //Initialize LibMain parameter holders.
210: pGB->hWnd =hWnd;
211: pGB->hInst =hInst;
212: pGB->hWndAssociate=hWndAssociate;
213: pGB->dwStyle =dwStyle;
214: pGB->uState =uState;
215: pGB->fEnabled =TRUE;
216:
217: pGB->crFace=GetSysColor(COLOR_BTNFACE);
218: pGB->hBrFace=CreateSolidBrush(pGB->crFace);
219:
220: if (NULL==pGB->hBrFace)
221: return pGB;
222:
223: pGB->hFont=GetStockObject(SYSTEM_FONT);
224:
225: *pfSuccess=TRUE;
226: return pGB;
227: }
228:
229:
230:
231:
232: /*
233: * GizmoBarPFree
234: *
235: * Purpose:
236: * Reverses all initialization done by GizmoBarPAllocate, cleaning up
237: * any allocations including the application structure itself.
238: *
239: * Parameters:
240: * pGB PGIZMOBAR to the control's structure
241: *
242: * Return Value:
243: * PGIZMOBAR NULL if successful, pGB if not, meaning we couldn't
244: * free some allocation.
245: */
246:
247: PGIZMOBAR GizmoBarPFree(PGIZMOBAR pGB)
248: {
249: if (NULL==pGB)
250: return NULL;
251:
252: /*
253: * Free all the gizmos we own. When we call GizmoPFree we always
254: * free the first one in the list which updates pGB->pGizmos for
255: * us, so we just have to keep going until pGizmos is NULL, meaning
256: * we're at the end of the list.
257: */
258: while (NULL!=pGB->pGizmos)
259: GizmoPFree(&pGB->pGizmos, pGB->pGizmos);
260:
261: if (NULL!=pGB->hBrFace)
262: DeleteObject(pGB->hBrFace);
263:
264: /*
265: * Notice that since we never create a font, we aren't responsible
266: * for our hFont member.
267: */
268:
269: return (PGIZMOBAR)LocalFree((HLOCAL)(UINT)(LONG)pGB);
270: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.