|
|
1.1 root 1: /*
2: * ICONBOX.C
3: *
4: * Implemenatation of an IconBox control for OLE 2.0 UI dialogs that we'll
5: * use wherever a dialog needs an icon/label display. Through the control's
6: * interface we can change the image or control label visibility.
7: *
8: * The IconBox discusses images in CF_METAFILEPICT format. When drawing
9: * such a metafile, the entire aspect is centered in the IconBox, so long
10: * labels are chopped at either end.
11: *
12: * Copyright (c)1992 Microsoft Corporation, All Right Reserved
13: */
14:
15:
16: #define STRICT 1
17: #include "ole2ui.h"
18: #include "iconbox.h"
19:
20:
21: //Flag indicating if we've registered the class
22: static BOOL fRegistered=FALSE;
23:
24:
25: /*
26: * FIconBoxInitialize
27: *
28: * Purpose:
29: * Registers the IconBox control class.
30: *
31: * Parameters:
32: * hInst HINSTANCE instance of the DLL.
33: *
34: * Return Value:
35: * BOOL TRUE if all initialization succeeded, FALSE otherwise.
36: */
37:
38: BOOL FIconBoxInitialize(HINSTANCE hInst)
39: {
40: WNDCLASS wc;
41:
42: if (!fRegistered)
43: {
44: wc.lpfnWndProc =IconBoxWndProc;
45: wc.cbClsExtra =0;
46: wc.cbWndExtra =CBICONBOXWNDEXTRA;
47: wc.hInstance =hInst;
48: wc.hIcon =NULL;
49: wc.hCursor =LoadCursor(NULL, IDC_ARROW);
50: wc.hbrBackground =(HBRUSH)NULL;
51: wc.lpszMenuName =NULL;
52: wc.lpszClassName =SZCLASSICONBOX;
53: wc.style =CS_GLOBALCLASS | CS_VREDRAW | CS_HREDRAW;
54:
55: fRegistered=RegisterClass(&wc);
56: }
57:
58: return fRegistered;
59: }
60:
61:
62:
63:
64:
65: /*
66: * IconBoxUninitialize
67: *
68: * Purpose:
69: * Cleans up anything done in FIconBoxInitialize. Currently there is
70: * nothing, but we do this for symmetry.
71: *
72: * Parameters:
73: * None
74: *
75: * Return Value:
76: * None
77: */
78:
79: void IconBoxUninitialize(void)
80: {
81: //Nothing to do.
82: return;
83: }
84:
85:
86:
87:
88:
89:
90: /*
91: * IconBoxWndProc
92: *
93: * Purpose:
94: * Window Procedure for the IconBox custom control. Only handles
95: * WM_CREATE, WM_PAINT, and private messages to manipulate the image.
96: *
97: * Parameters:
98: * Standard
99: *
100: * Return Value:
101: * Standard
102: */
103:
104: LONG CALLBACK EXPORT IconBoxWndProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
105: {
106: HGLOBAL hMF=NULL;
107: PAINTSTRUCT ps;
108: HDC hDC;
109: RECT rc;
110:
111:
112: //Handle standard Windows messages.
113: switch (iMsg)
114: {
115: case WM_CREATE:
116: SetWindowWord(hWnd, IBWW_HIMAGE, 0);
117: SetWindowWord(hWnd, IBWW_FLABEL, TRUE);
118: return 0L;
119:
120:
121: case WM_ERASEBKGND:
122: {
123:
124: HBRUSH hBrush;
125: RECT Rect;
126: #if defined( WIN32 )
127: POINT point;
128: #endif
129:
130: GetClientRect(hWnd, &Rect);
131: #if defined( WIN32 )
132: hBrush = (HBRUSH)SendMessage(GetParent(hWnd),
133: WM_CTLCOLORDLG,
134: wParam,
135: (LPARAM)GetParent(hWnd));
136: #else
137: hBrush = (HBRUSH)SendMessage(GetParent(hWnd),
138: WM_CTLCOLOR,
139: wParam,
140: MAKELPARAM(GetParent(hWnd), CTLCOLOR_DLG));
141: #endif
142:
143:
144: if (!hBrush)
145: return FALSE;
146:
147: UnrealizeObject(hBrush);
148:
149: #if defined( WIN32 )
150: SetBrushOrgEx((HDC)wParam, 0, 0, &point);
151: #else
152: SetBrushOrg((HDC)wParam, 0, 0);
153: #endif
154:
155: FillRect((HDC)wParam, &Rect, hBrush);
156:
157: return TRUE;
158: }
159:
160:
161: case WM_PAINT:
162: hMF=(HGLOBAL)GetWindowWord(hWnd, IBWW_HIMAGE);
163:
164: //BeginPaint and EndPaint clear us even if hMF is NULL.
165: hDC=BeginPaint(hWnd, &ps);
166:
167: if (NULL!=hMF)
168: {
169: BOOL fLabel;
170:
171: //Now we get to paint the metafile, centered in our rect.
172: GetClientRect(hWnd, &rc);
173:
174: /*
175: * If we're doing icon only, then place the metafile
176: * at the center of our box minus half the icon width.
177: * Top is top.
178: */
179:
180: fLabel=GetWindowWord(hWnd, IBWW_FLABEL);
181:
182:
183: //Go draw where we decided to place it.
184: OleUIMetafilePictIconDraw(hDC, &rc, hMF, !fLabel);
185: }
186:
187: EndPaint(hWnd, &ps);
188: break;
189:
190:
191: case IBXM_IMAGESET:
192: /*
193: * wParam contains the new handle.
194: * lParam is a flag to delete the old or not.
195: */
196: hMF=(HGLOBAL)SetWindowWord(hWnd, IBWW_HIMAGE, (WORD)wParam);
197: InvalidateRect(hWnd, NULL, TRUE);
198: UpdateWindow(hWnd);
199:
200: //Delete the old handle if requested
201: if (0L!=lParam)
202: {
203: OleUIMetafilePictIconFree(hMF);
204: hMF=NULL;
205: }
206:
207: return (LONG)(UINT)hMF;
208:
209:
210: case IBXM_IMAGEGET:
211: //Return the current index.
212: hMF=(HGLOBAL)GetWindowWord(hWnd, IBWW_HIMAGE);
213: return (LONG)(UINT)hMF;
214:
215:
216: case IBXM_IMAGEFREE:
217: //Free up whatever we're holding.
218: hMF=(HGLOBAL)GetWindowWord(hWnd, IBWW_HIMAGE);
219: OleUIMetafilePictIconFree(hMF);
220: return 1L;
221:
222:
223: case IBXM_LABELENABLE:
224: //wParam has the new flag, returns the previous flag.
225: return (LONG)SetWindowWord(hWnd, IBWW_FLABEL, (WORD)wParam);
226:
227:
228: default:
229: return DefWindowProc(hWnd, iMsg, wParam, lParam);
230: }
231:
232: return 0L;
233: }
234:
235:
236:
237:
238:
239:
240:
241:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.