1 | /* $Id: static.cpp,v 1.3 1999-09-20 19:17:58 sandervl Exp $ */
|
---|
2 | /*
|
---|
3 | * Static control
|
---|
4 | *
|
---|
5 | * Copyright 1999 Christoph Bratschi (ported from WINE)
|
---|
6 | *
|
---|
7 | * Copyright David W. Metcalfe, 1993
|
---|
8 | *
|
---|
9 | */
|
---|
10 |
|
---|
11 | #include <stdlib.h>
|
---|
12 | #include "winuser.h"
|
---|
13 | #include "winbase.h"
|
---|
14 | #include "controls.h"
|
---|
15 | #include "static.h"
|
---|
16 |
|
---|
17 | //Prototypes
|
---|
18 |
|
---|
19 | static void STATIC_PaintTextfn( HWND hwnd, HDC hdc );
|
---|
20 | static void STATIC_PaintRectfn( HWND hwnd, HDC hdc );
|
---|
21 | static void STATIC_PaintIconfn( HWND hwnd, HDC hdc );
|
---|
22 | static void STATIC_PaintBitmapfn( HWND hwnd, HDC hdc );
|
---|
23 | static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc );
|
---|
24 |
|
---|
25 | static COLORREF color_windowframe, color_background, color_window;
|
---|
26 |
|
---|
27 |
|
---|
28 | typedef void (*pfPaint)( HWND, HDC );
|
---|
29 |
|
---|
30 | static pfPaint staticPaintFunc[SS_TYPEMASK+1] =
|
---|
31 | {
|
---|
32 | STATIC_PaintTextfn, /* SS_LEFT */
|
---|
33 | STATIC_PaintTextfn, /* SS_CENTER */
|
---|
34 | STATIC_PaintTextfn, /* SS_RIGHT */
|
---|
35 | STATIC_PaintIconfn, /* SS_ICON */
|
---|
36 | STATIC_PaintRectfn, /* SS_BLACKRECT */
|
---|
37 | STATIC_PaintRectfn, /* SS_GRAYRECT */
|
---|
38 | STATIC_PaintRectfn, /* SS_WHITERECT */
|
---|
39 | STATIC_PaintRectfn, /* SS_BLACKFRAME */
|
---|
40 | STATIC_PaintRectfn, /* SS_GRAYFRAME */
|
---|
41 | STATIC_PaintRectfn, /* SS_WHITEFRAME */
|
---|
42 | NULL, /* Not defined */
|
---|
43 | STATIC_PaintTextfn, /* SS_SIMPLE */
|
---|
44 | STATIC_PaintTextfn, /* SS_LEFTNOWORDWRAP */
|
---|
45 | NULL, /* SS_OWNERDRAW */
|
---|
46 | STATIC_PaintBitmapfn, /* SS_BITMAP */
|
---|
47 | NULL, /* SS_ENHMETAFILE */
|
---|
48 | STATIC_PaintEtchedfn, /* SS_ETCHEDHORIZ */
|
---|
49 | STATIC_PaintEtchedfn, /* SS_ETCHEDVERT */
|
---|
50 | STATIC_PaintEtchedfn, /* SS_ETCHEDFRAME */
|
---|
51 | };
|
---|
52 |
|
---|
53 |
|
---|
54 | /***********************************************************************
|
---|
55 | * STATIC_SetIcon
|
---|
56 | *
|
---|
57 | * Set the icon for an SS_ICON control.
|
---|
58 | */
|
---|
59 | static HICON STATIC_SetIcon( HWND hwnd, HICON hicon )
|
---|
60 | {
|
---|
61 | HICON prevIcon;
|
---|
62 | STATICINFO *infoPtr = (STATICINFO *)GetInfoPtr(hwnd);
|
---|
63 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
---|
64 | INT cx,cy;
|
---|
65 |
|
---|
66 | if ((dwStyle & SS_TYPEMASK) != SS_ICON) return 0;
|
---|
67 |
|
---|
68 | if (infoPtr->hIcon) DestroyIcon(infoPtr->hIcon);
|
---|
69 | prevIcon = infoPtr->hIcon;
|
---|
70 | infoPtr->hIcon = hicon;
|
---|
71 |
|
---|
72 | cx = GetSystemMetrics(SM_CXICON);
|
---|
73 | cy = GetSystemMetrics(SM_CYICON);
|
---|
74 |
|
---|
75 | SetWindowPos(hwnd,0,0,0,cx,cy,SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
|
---|
76 |
|
---|
77 | return prevIcon;
|
---|
78 | }
|
---|
79 |
|
---|
80 | /***********************************************************************
|
---|
81 | * STATIC_SetBitmap
|
---|
82 | *
|
---|
83 | * Set the bitmap for an SS_BITMAP control.
|
---|
84 | */
|
---|
85 | static HBITMAP STATIC_SetBitmap( HWND hwnd, HBITMAP hBitmap )
|
---|
86 | {
|
---|
87 | HBITMAP hOldBitmap;
|
---|
88 | STATICINFO *infoPtr = (STATICINFO *)GetInfoPtr(hwnd);
|
---|
89 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
---|
90 |
|
---|
91 | if ((dwStyle & SS_TYPEMASK) != SS_BITMAP) return 0;
|
---|
92 |
|
---|
93 | if (hBitmap && GetObjectType(hBitmap) != OBJ_BITMAP) {
|
---|
94 | //ERR("huh? hBitmap!=0, but not bitmap\n");
|
---|
95 | return 0;
|
---|
96 | }
|
---|
97 | hOldBitmap = infoPtr->hIcon;
|
---|
98 | infoPtr->hIcon = hBitmap;
|
---|
99 | if (hBitmap)
|
---|
100 | {
|
---|
101 | BITMAP bm;
|
---|
102 | GetObjectA(hBitmap, sizeof(bm), &bm);
|
---|
103 | SetWindowPos( hwnd, 0, 0, 0, bm.bmWidth, bm.bmHeight,
|
---|
104 | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
|
---|
105 | /* CB: alternative code, if necessary
|
---|
106 | HDC hdc = GetDC(hwnd);
|
---|
107 | BITMAPINFO info;
|
---|
108 |
|
---|
109 | ZeroMemory(&info,sizeof(info));
|
---|
110 | if (GetDIBits(hdc,hbitmap,0,0,NULL,&info,0) != 0)
|
---|
111 | {
|
---|
112 | SetWindowPos(hwnd,0,0,0,info.bmiHeader.biWidth,info.bmiHeader.biHeight,SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER);
|
---|
113 | }
|
---|
114 | ReleaseDC(hwnd,hdc);
|
---|
115 | */
|
---|
116 |
|
---|
117 | }
|
---|
118 | return hOldBitmap;
|
---|
119 | }
|
---|
120 |
|
---|
121 | /***********************************************************************
|
---|
122 | * STATIC_LoadIcon
|
---|
123 | *
|
---|
124 | * Load the icon for an SS_ICON control.
|
---|
125 | */
|
---|
126 | static HICON STATIC_LoadIcon( HWND hwnd, LPCSTR name )
|
---|
127 | {
|
---|
128 | HICON hicon;
|
---|
129 |
|
---|
130 | hicon = LoadIconA(GetWindowLongA(hwnd,GWL_HINSTANCE),name);
|
---|
131 |
|
---|
132 | if (!hicon)
|
---|
133 | hicon = LoadIconA(0, name);
|
---|
134 |
|
---|
135 | return hicon;
|
---|
136 | }
|
---|
137 |
|
---|
138 | /***********************************************************************
|
---|
139 | * STATIC_LoadBitmap
|
---|
140 | *
|
---|
141 | * Load the bitmap for an SS_BITMAP control.
|
---|
142 | */
|
---|
143 | static HBITMAP STATIC_LoadBitmap( HWND hwnd, LPCSTR name )
|
---|
144 | {
|
---|
145 | HBITMAP hbitmap;
|
---|
146 |
|
---|
147 | hbitmap = LoadBitmapA(GetWindowLongA(hwnd,GWL_HINSTANCE),name);
|
---|
148 |
|
---|
149 | if (!hbitmap) /* Try OEM icon (FIXME: is this right?) */
|
---|
150 | hbitmap = LoadBitmapA(0,name);
|
---|
151 |
|
---|
152 | return hbitmap;
|
---|
153 | }
|
---|
154 |
|
---|
155 | /* message handler */
|
---|
156 |
|
---|
157 | LRESULT STATIC_NCCreate(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
158 | {
|
---|
159 | CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
|
---|
160 | STATICINFO* infoPtr;
|
---|
161 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
---|
162 | DWORD style = dwStyle & SS_TYPEMASK;
|
---|
163 | DWORD dwExStyle = GetWindowLongA(hwnd,GWL_EXSTYLE);
|
---|
164 |
|
---|
165 | infoPtr = (STATICINFO*)malloc(sizeof(STATICINFO));
|
---|
166 | infoPtr->hFont = 0;
|
---|
167 | infoPtr->dummy = 0;
|
---|
168 | infoPtr->hIcon = 0;
|
---|
169 | SetInfoPtr(hwnd,(DWORD)infoPtr);
|
---|
170 |
|
---|
171 | if (dwStyle & SS_SUNKEN)
|
---|
172 | {
|
---|
173 | dwExStyle |= WS_EX_STATICEDGE;
|
---|
174 | SetWindowLongA(hwnd,GWL_EXSTYLE,dwExStyle);
|
---|
175 | }
|
---|
176 |
|
---|
177 | if (style == SS_ICON)
|
---|
178 | {
|
---|
179 | if (cs->lpszName)
|
---|
180 | {
|
---|
181 | if (!HIWORD(cs->lpszName) || cs->lpszName[0])
|
---|
182 | STATIC_SetIcon(hwnd,STATIC_LoadIcon(hwnd,cs->lpszName));
|
---|
183 | }
|
---|
184 | return TRUE;
|
---|
185 | }
|
---|
186 | if (style == SS_BITMAP)
|
---|
187 | {
|
---|
188 | if (cs->lpszName)
|
---|
189 | STATIC_SetBitmap(hwnd,STATIC_LoadBitmap(hwnd,cs->lpszName));
|
---|
190 | return TRUE;
|
---|
191 | }
|
---|
192 | if (!HIWORD(cs->lpszName) && (cs->lpszName)) return TRUE;
|
---|
193 |
|
---|
194 | return DefWindowProcA(hwnd,WM_NCCREATE,wParam,lParam);
|
---|
195 | }
|
---|
196 |
|
---|
197 | LRESULT STATIC_Create(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
198 | {
|
---|
199 | DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & SS_TYPEMASK;
|
---|
200 |
|
---|
201 | if (style < 0L || style > SS_TYPEMASK)
|
---|
202 | {
|
---|
203 | //Unknown style
|
---|
204 | return (LRESULT)-1;
|
---|
205 | }
|
---|
206 |
|
---|
207 | /* initialise colours */
|
---|
208 | color_windowframe = GetSysColor(COLOR_WINDOWFRAME);
|
---|
209 | color_background = GetSysColor(COLOR_BACKGROUND);
|
---|
210 | color_window = GetSysColor(COLOR_WINDOW);
|
---|
211 |
|
---|
212 | return 0;
|
---|
213 | }
|
---|
214 |
|
---|
215 | LRESULT STATIC_NCDestroy(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
216 | {
|
---|
217 | STATICINFO* infoPtr = (STATICINFO*)GetInfoPtr(hwnd);
|
---|
218 | DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & SS_TYPEMASK;
|
---|
219 |
|
---|
220 | if (style == SS_ICON && infoPtr->hIcon)
|
---|
221 | {
|
---|
222 | DestroyIcon(infoPtr->hIcon);
|
---|
223 | } else if (style == SS_BITMAP && infoPtr->hIcon)
|
---|
224 | {
|
---|
225 | DeleteObject(infoPtr->hIcon);
|
---|
226 | }
|
---|
227 |
|
---|
228 | free(infoPtr);
|
---|
229 |
|
---|
230 | return DefWindowProcA(hwnd,WM_NCDESTROY,wParam,lParam);
|
---|
231 | }
|
---|
232 |
|
---|
233 | LRESULT STATIC_Paint(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
234 | {
|
---|
235 | DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & SS_TYPEMASK;
|
---|
236 | PAINTSTRUCT ps;
|
---|
237 |
|
---|
238 | BeginPaint(hwnd,&ps);
|
---|
239 | if (staticPaintFunc[style]) (staticPaintFunc[style])(hwnd,ps.hdc);
|
---|
240 | EndPaint(hwnd,&ps);
|
---|
241 |
|
---|
242 | return 0;
|
---|
243 | }
|
---|
244 |
|
---|
245 | LRESULT STATIC_Enable(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
246 | {
|
---|
247 | InvalidateRect(hwnd,NULL,FALSE);
|
---|
248 |
|
---|
249 | return 0;
|
---|
250 | }
|
---|
251 |
|
---|
252 | LRESULT STATIC_SysColorChange(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
253 | {
|
---|
254 | color_windowframe = GetSysColor(COLOR_WINDOWFRAME);
|
---|
255 | color_background = GetSysColor(COLOR_BACKGROUND);
|
---|
256 | color_window = GetSysColor(COLOR_WINDOW);
|
---|
257 |
|
---|
258 | InvalidateRect(hwnd,NULL,TRUE);
|
---|
259 |
|
---|
260 | return 0;
|
---|
261 | }
|
---|
262 |
|
---|
263 | LRESULT STATIC_SetText(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
264 | {
|
---|
265 | DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & SS_TYPEMASK;
|
---|
266 |
|
---|
267 | if (style == SS_ICON)
|
---|
268 | STATIC_SetIcon(hwnd,STATIC_LoadIcon(hwnd,(LPCSTR)lParam));
|
---|
269 | else if (style == SS_BITMAP)
|
---|
270 | STATIC_SetBitmap(hwnd,STATIC_LoadBitmap(hwnd,(LPCSTR)lParam));
|
---|
271 | else
|
---|
272 | DefWindowProcA(hwnd,WM_SETTEXT,wParam,lParam);
|
---|
273 |
|
---|
274 | InvalidateRect(hwnd,NULL,FALSE);
|
---|
275 | UpdateWindow(hwnd);
|
---|
276 |
|
---|
277 | return 0;
|
---|
278 | }
|
---|
279 |
|
---|
280 | LRESULT STATIC_SetFont(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
281 | {
|
---|
282 | STATICINFO* infoPtr = (STATICINFO*)GetInfoPtr(hwnd);
|
---|
283 | DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & SS_TYPEMASK;
|
---|
284 |
|
---|
285 | if (style == SS_ICON) return 0;
|
---|
286 | if (style == SS_BITMAP) return 0;
|
---|
287 |
|
---|
288 | infoPtr->hFont = (HFONT)wParam;
|
---|
289 |
|
---|
290 | if (LOWORD(lParam))
|
---|
291 | {
|
---|
292 | InvalidateRect(hwnd,NULL,FALSE);
|
---|
293 | UpdateWindow(hwnd);
|
---|
294 | }
|
---|
295 |
|
---|
296 | return 0;
|
---|
297 | }
|
---|
298 |
|
---|
299 | LRESULT STATIC_GetFont(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
300 | {
|
---|
301 | STATICINFO* infoPtr = (STATICINFO*)GetInfoPtr(hwnd);
|
---|
302 |
|
---|
303 | return infoPtr->hFont;
|
---|
304 | }
|
---|
305 |
|
---|
306 | LRESULT STATIC_NCHitTest(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
307 | {
|
---|
308 | return HTTRANSPARENT;
|
---|
309 | }
|
---|
310 |
|
---|
311 | LRESULT STATIC_GetDlgCode(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
312 | {
|
---|
313 | return DLGC_STATIC;
|
---|
314 | }
|
---|
315 |
|
---|
316 | LRESULT STATIC_GetIcon(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
317 | {
|
---|
318 | STATICINFO* infoPtr = (STATICINFO*)GetInfoPtr(hwnd);
|
---|
319 |
|
---|
320 | return infoPtr->hIcon;
|
---|
321 | }
|
---|
322 |
|
---|
323 | LRESULT STATIC_SetImage(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
324 | {
|
---|
325 | LRESULT lResult;
|
---|
326 |
|
---|
327 | switch (wParam)
|
---|
328 | {
|
---|
329 | case IMAGE_CURSOR:
|
---|
330 | case IMAGE_ICON:
|
---|
331 | lResult = STATIC_SetIcon(hwnd,(HICON)lParam);
|
---|
332 | break;
|
---|
333 | case IMAGE_BITMAP:
|
---|
334 | lResult = STATIC_SetBitmap(hwnd,(HBITMAP)lParam);
|
---|
335 | case IMAGE_ENHMETAFILE:
|
---|
336 | return 0; //CB: not supported!
|
---|
337 | default:
|
---|
338 | return 0;
|
---|
339 | }
|
---|
340 |
|
---|
341 | InvalidateRect(hwnd,NULL,FALSE);
|
---|
342 | UpdateWindow(hwnd);
|
---|
343 |
|
---|
344 | return lResult;
|
---|
345 | }
|
---|
346 |
|
---|
347 | LRESULT STATIC_SetIcon(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
348 | {
|
---|
349 | LRESULT lResult;
|
---|
350 |
|
---|
351 | lResult = STATIC_SetIcon(hwnd,(HICON)wParam);
|
---|
352 |
|
---|
353 | InvalidateRect(hwnd,NULL,FALSE);
|
---|
354 | UpdateWindow(hwnd);
|
---|
355 |
|
---|
356 | return lResult;
|
---|
357 | }
|
---|
358 |
|
---|
359 | /***********************************************************************
|
---|
360 | * StaticWndProc
|
---|
361 | */
|
---|
362 | LRESULT WINAPI StaticWndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
|
---|
363 | {
|
---|
364 | switch (uMsg)
|
---|
365 | {
|
---|
366 | case WM_NCCREATE:
|
---|
367 | return STATIC_NCCreate(hwnd,wParam,lParam);
|
---|
368 |
|
---|
369 | case WM_CREATE:
|
---|
370 | return STATIC_Create(hwnd,wParam,lParam);
|
---|
371 |
|
---|
372 | case WM_NCDESTROY:
|
---|
373 | return STATIC_NCDestroy(hwnd,wParam,lParam);
|
---|
374 |
|
---|
375 | case WM_PAINT:
|
---|
376 | return STATIC_Paint(hwnd,wParam,lParam);
|
---|
377 |
|
---|
378 | case WM_ENABLE:
|
---|
379 | return STATIC_Enable(hwnd,wParam,lParam);
|
---|
380 |
|
---|
381 | case WM_SYSCOLORCHANGE:
|
---|
382 | return STATIC_SysColorChange(hwnd,wParam,lParam);
|
---|
383 |
|
---|
384 | case WM_SETTEXT:
|
---|
385 | return STATIC_SetText(hwnd,wParam,lParam);
|
---|
386 |
|
---|
387 | case WM_SETFONT:
|
---|
388 | return STATIC_SetFont(hwnd,wParam,lParam);
|
---|
389 |
|
---|
390 | case WM_GETFONT:
|
---|
391 | return STATIC_GetFont(hwnd,wParam,lParam);
|
---|
392 |
|
---|
393 | case WM_NCHITTEST:
|
---|
394 | return STATIC_NCHitTest(hwnd,wParam,lParam);
|
---|
395 |
|
---|
396 | case WM_GETDLGCODE:
|
---|
397 | return STATIC_GetDlgCode(hwnd,wParam,lParam);
|
---|
398 |
|
---|
399 | case STM_GETIMAGE:
|
---|
400 | case STM_GETICON:
|
---|
401 | return STATIC_GetIcon(hwnd,wParam,lParam);
|
---|
402 |
|
---|
403 | case STM_SETIMAGE:
|
---|
404 | return STATIC_SetImage(hwnd,wParam,lParam);
|
---|
405 |
|
---|
406 | case STM_SETICON:
|
---|
407 | return STATIC_SetIcon(hwnd,wParam,lParam);
|
---|
408 |
|
---|
409 | default:
|
---|
410 | return DefWindowProcA(hwnd,uMsg,wParam,lParam);
|
---|
411 | break;
|
---|
412 | }
|
---|
413 |
|
---|
414 | return DefWindowProcA(hwnd,uMsg,wParam,lParam);
|
---|
415 | }
|
---|
416 |
|
---|
417 |
|
---|
418 | static void STATIC_PaintTextfn(HWND hwnd, HDC hdc )
|
---|
419 | {
|
---|
420 | RECT rc;
|
---|
421 | HBRUSH hBrush;
|
---|
422 | WORD wFormat;
|
---|
423 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
---|
424 | LONG style = dwStyle;
|
---|
425 | STATICINFO *infoPtr = (STATICINFO *)GetInfoPtr(hwnd);
|
---|
426 | INT textLen;
|
---|
427 |
|
---|
428 | GetClientRect(hwnd,&rc);
|
---|
429 |
|
---|
430 | switch (style & SS_TYPEMASK)
|
---|
431 | {
|
---|
432 | case SS_LEFT:
|
---|
433 | wFormat = DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
|
---|
434 | break;
|
---|
435 |
|
---|
436 | case SS_CENTER:
|
---|
437 | wFormat = DT_CENTER | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
|
---|
438 | break;
|
---|
439 |
|
---|
440 | case SS_RIGHT:
|
---|
441 | wFormat = DT_RIGHT | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
|
---|
442 | break;
|
---|
443 |
|
---|
444 | case SS_SIMPLE:
|
---|
445 | wFormat = DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_NOCLIP;
|
---|
446 | break;
|
---|
447 |
|
---|
448 | case SS_LEFTNOWORDWRAP:
|
---|
449 | wFormat = DT_LEFT | DT_EXPANDTABS | DT_VCENTER;
|
---|
450 | break;
|
---|
451 |
|
---|
452 | default:
|
---|
453 | return;
|
---|
454 | }
|
---|
455 |
|
---|
456 | if (style & SS_NOPREFIX)
|
---|
457 | wFormat |= DT_NOPREFIX;
|
---|
458 |
|
---|
459 | if (infoPtr->hFont) SelectObject( hdc, infoPtr->hFont );
|
---|
460 | hBrush = SendMessageA( GetParent(hwnd), WM_CTLCOLORSTATIC,
|
---|
461 | hdc, hwnd );
|
---|
462 | if (!hBrush) hBrush = GetStockObject(WHITE_BRUSH);
|
---|
463 | FillRect( hdc, &rc, hBrush );
|
---|
464 |
|
---|
465 | textLen = GetWindowTextLengthA(hwnd);
|
---|
466 | if (textLen > 0)
|
---|
467 | {
|
---|
468 | char* text;
|
---|
469 |
|
---|
470 | textLen++;
|
---|
471 | text = (char*)malloc(textLen);
|
---|
472 | GetWindowTextA(hwnd,text,textLen);
|
---|
473 | DrawTextA( hdc, text, -1, &rc, wFormat );
|
---|
474 | free(text);
|
---|
475 | }
|
---|
476 | }
|
---|
477 |
|
---|
478 | static void STATIC_PaintRectfn( HWND hwnd, HDC hdc )
|
---|
479 | {
|
---|
480 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
---|
481 | RECT rc;
|
---|
482 | HBRUSH hBrush;
|
---|
483 |
|
---|
484 | GetClientRect( hwnd, &rc);
|
---|
485 |
|
---|
486 | switch (dwStyle & SS_TYPEMASK)
|
---|
487 | {
|
---|
488 | case SS_BLACKRECT:
|
---|
489 | hBrush = CreateSolidBrush(color_windowframe);
|
---|
490 | FillRect( hdc, &rc, hBrush );
|
---|
491 | break;
|
---|
492 | case SS_GRAYRECT:
|
---|
493 | hBrush = CreateSolidBrush(color_background);
|
---|
494 | FillRect( hdc, &rc, hBrush );
|
---|
495 | break;
|
---|
496 | case SS_WHITERECT:
|
---|
497 | hBrush = CreateSolidBrush(color_window);
|
---|
498 | FillRect( hdc, &rc, hBrush );
|
---|
499 | break;
|
---|
500 | case SS_BLACKFRAME:
|
---|
501 | hBrush = CreateSolidBrush(color_windowframe);
|
---|
502 | FrameRect( hdc, &rc, hBrush );
|
---|
503 | break;
|
---|
504 | case SS_GRAYFRAME:
|
---|
505 | hBrush = CreateSolidBrush(color_background);
|
---|
506 | FrameRect( hdc, &rc, hBrush );
|
---|
507 | break;
|
---|
508 | case SS_WHITEFRAME:
|
---|
509 | hBrush = CreateSolidBrush(color_window);
|
---|
510 | FrameRect( hdc, &rc, hBrush );
|
---|
511 | break;
|
---|
512 | default:
|
---|
513 | return;
|
---|
514 | }
|
---|
515 | DeleteObject( hBrush );
|
---|
516 | }
|
---|
517 |
|
---|
518 |
|
---|
519 | static void STATIC_PaintIconfn( HWND hwnd, HDC hdc )
|
---|
520 | {
|
---|
521 | RECT rc;
|
---|
522 | HBRUSH hbrush;
|
---|
523 | STATICINFO *infoPtr = (STATICINFO *)GetInfoPtr(hwnd);
|
---|
524 |
|
---|
525 | GetClientRect( hwnd, &rc );
|
---|
526 | hbrush = SendMessageA( GetParent(hwnd), WM_CTLCOLORSTATIC,
|
---|
527 | hdc, hwnd );
|
---|
528 | FillRect( hdc, &rc, hbrush );
|
---|
529 | if (infoPtr->hIcon) DrawIcon( hdc, rc.left, rc.top, infoPtr->hIcon );
|
---|
530 | }
|
---|
531 |
|
---|
532 | static void STATIC_PaintBitmapfn(HWND hwnd, HDC hdc )
|
---|
533 | {
|
---|
534 | RECT rc;
|
---|
535 | HBRUSH hbrush;
|
---|
536 | STATICINFO *infoPtr = (STATICINFO *)GetInfoPtr(hwnd);
|
---|
537 | HDC hMemDC;
|
---|
538 | HBITMAP oldbitmap;
|
---|
539 |
|
---|
540 | GetClientRect( hwnd, &rc );
|
---|
541 | hbrush = SendMessageA( GetParent(hwnd), WM_CTLCOLORSTATIC,
|
---|
542 | hdc, hwnd );
|
---|
543 | FillRect( hdc, &rc, hbrush );
|
---|
544 |
|
---|
545 | if (infoPtr->hIcon) {
|
---|
546 | BITMAP bm;
|
---|
547 | SIZE sz;
|
---|
548 |
|
---|
549 | if(GetObjectType(infoPtr->hIcon) != OBJ_BITMAP)
|
---|
550 | return;
|
---|
551 | if (!(hMemDC = CreateCompatibleDC( hdc ))) return;
|
---|
552 | GetObjectA(infoPtr->hIcon, sizeof(bm), &bm);
|
---|
553 | GetBitmapDimensionEx(infoPtr->hIcon, &sz);
|
---|
554 | oldbitmap = SelectObject(hMemDC, infoPtr->hIcon);
|
---|
555 | BitBlt(hdc, sz.cx, sz.cy, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0,
|
---|
556 | SRCCOPY);
|
---|
557 | SelectObject(hMemDC, oldbitmap);
|
---|
558 | DeleteDC(hMemDC);
|
---|
559 | }
|
---|
560 | }
|
---|
561 |
|
---|
562 |
|
---|
563 | static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc )
|
---|
564 | {
|
---|
565 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
---|
566 | RECT rc;
|
---|
567 | HBRUSH hbrush;
|
---|
568 | HPEN hpen;
|
---|
569 |
|
---|
570 | GetClientRect( hwnd, &rc );
|
---|
571 | hbrush = SendMessageA( GetParent(hwnd), WM_CTLCOLORSTATIC,
|
---|
572 | hdc, hwnd );
|
---|
573 | FillRect( hdc, &rc, hbrush );
|
---|
574 |
|
---|
575 | switch (dwStyle & SS_TYPEMASK)
|
---|
576 | {
|
---|
577 | case SS_ETCHEDHORZ:
|
---|
578 | hpen = SelectObject (hdc, GetSysColorPen (COLOR_3DSHADOW));
|
---|
579 | MoveToEx (hdc, rc.left, rc.bottom / 2 - 1, NULL);
|
---|
580 | LineTo (hdc, rc.right - 1, rc.bottom / 2 - 1);
|
---|
581 | SelectObject (hdc, GetSysColorPen (COLOR_3DHIGHLIGHT));
|
---|
582 | MoveToEx (hdc, rc.left, rc.bottom / 2, NULL);
|
---|
583 | LineTo (hdc, rc.right, rc.bottom / 2);
|
---|
584 | LineTo (hdc, rc.right, rc.bottom / 2 - 1);
|
---|
585 | SelectObject (hdc, hpen);
|
---|
586 | break;
|
---|
587 |
|
---|
588 | case SS_ETCHEDVERT:
|
---|
589 | hpen = SelectObject (hdc, GetSysColorPen (COLOR_3DSHADOW));
|
---|
590 | MoveToEx (hdc, rc.right / 2 - 1, rc.top, NULL);
|
---|
591 | LineTo (hdc, rc.right / 2 - 1, rc.bottom - 1);
|
---|
592 | SelectObject (hdc, GetSysColorPen (COLOR_3DHIGHLIGHT));
|
---|
593 | MoveToEx (hdc, rc.right / 2, rc.top, NULL);
|
---|
594 | LineTo (hdc, rc.right / 2, rc.bottom);
|
---|
595 | LineTo (hdc, rc.right / 2 -1 , rc.bottom);
|
---|
596 | SelectObject (hdc, hpen);
|
---|
597 | break;
|
---|
598 |
|
---|
599 | case SS_ETCHEDFRAME:
|
---|
600 | DrawEdge (hdc, &rc, EDGE_ETCHED, BF_RECT);
|
---|
601 | break;
|
---|
602 | }
|
---|
603 | }
|
---|
604 |
|
---|
605 | BOOL STATIC_Register()
|
---|
606 | {
|
---|
607 | WNDCLASSA wndClass;
|
---|
608 |
|
---|
609 | if (GlobalFindAtomA(STATICCLASSNAME)) return FALSE;
|
---|
610 |
|
---|
611 | ZeroMemory(&wndClass,sizeof(WNDCLASSA));
|
---|
612 | wndClass.style = CS_GLOBALCLASS | CS_HREDRAW | CS_PARENTDC;
|
---|
613 | wndClass.lpfnWndProc = (WNDPROC)StaticWndProc;
|
---|
614 | wndClass.cbClsExtra = 0;
|
---|
615 | wndClass.cbWndExtra = sizeof(STATICINFO);
|
---|
616 | wndClass.hCursor = LoadCursorA (0,IDC_ARROWA);
|
---|
617 | wndClass.hbrBackground = (HBRUSH)0;
|
---|
618 | wndClass.lpszClassName = STATICCLASSNAME;
|
---|
619 |
|
---|
620 | return RegisterClassA(&wndClass);
|
---|
621 | }
|
---|
622 |
|
---|
623 |
|
---|
624 | BOOL STATIC_Unregister()
|
---|
625 | {
|
---|
626 | if (GlobalFindAtomA (STATICCLASSNAME))
|
---|
627 | return UnregisterClassA(STATICCLASSNAME,(HINSTANCE)NULL);
|
---|
628 | else return FALSE;
|
---|
629 | }
|
---|