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