4 * Copyright David W. Metcalfe, 1993
8 static char Copyright
[] = "Copyright David W. Metcalfe, 1993";
15 LONG
StaticWndProc(HWND hWnd
, WORD uMsg
, WORD wParam
, LONG lParam
);
17 static LONG
PaintTextfn(HWND hwnd
);
18 static LONG
PaintRectfn(HWND hwnd
);
19 static LONG
PaintFramefn(HWND hwnd
);
20 static LONG
PaintIconfn(HWND hwnd
);
23 static COLORREF color_windowframe
, color_background
, color_window
,
26 #define NOTIFY_PARENT(hWndCntrl, wNotifyCode) \
27 SendMessage(GetParent(hWndCntrl), WM_COMMAND, \
28 GetDlgCtrlID(hWndCntrl), MAKELPARAM(hWndCntrl, wNotifyCode));
29 #define DIM(array) ((sizeof array)/(sizeof array[0]))
36 #define MAX_STATIC_TYPE 12
38 static STATICFN staticfn
[MAX_STATIC_TYPE
] =
40 { (LONG(*)())PaintTextfn
}, /* SS_LEFT */
41 { (LONG(*)())PaintTextfn
}, /* SS_CENTER */
42 { (LONG(*)())PaintTextfn
}, /* SS_RIGHT */
43 { (LONG(*)())PaintIconfn
}, /* SS_ICON */
44 { (LONG(*)())PaintRectfn
}, /* SS_BLACKRECT */
45 { (LONG(*)())PaintRectfn
}, /* SS_GRAYRECT */
46 { (LONG(*)())PaintRectfn
}, /* SS_WHITERECT */
47 { (LONG(*)())PaintFramefn
}, /* SS_BLACKFRAME */
48 { (LONG(*)())PaintFramefn
}, /* SS_GRAYFRAME */
49 { (LONG(*)())PaintFramefn
}, /* SS_WHITEFRAME */
50 { (LONG(*)())PaintTextfn
}, /* SS_SIMPLE */
51 { (LONG(*)())PaintTextfn
} /* SS_LEFTNOWORDWRAP */
55 LONG
StaticWndProc(HWND hWnd
, WORD uMsg
, WORD wParam
, LONG lParam
)
62 WND
*wndPtr
= WIN_FindWndPtr(hWnd
);
63 LONG style
= wndPtr
->dwStyle
& 0x0000000F;
67 InvalidateRect(hWnd
, NULL
, FALSE
);
71 if (style
< 0L || style
>= (LONG
)DIM(staticfn
)) {
75 /* initialise colours */
76 color_windowframe
= GetSysColor(COLOR_WINDOWFRAME
);
77 color_background
= GetSysColor(COLOR_BACKGROUND
);
78 color_window
= GetSysColor(COLOR_WINDOW
);
79 color_windowtext
= GetSysColor(COLOR_WINDOWTEXT
);
81 if (style
== SS_ICON
) {
83 SetWindowPos(hWnd, (HWND)NULL, 0, 0, 32, 32,
84 SWP_NOZORDER | SWP_NOMOVE);
90 if (staticfn
[style
].paintfn
)
91 (staticfn
[style
].paintfn
)(hWnd
);
94 case WM_SYSCOLORCHANGE
:
95 color_windowframe
= GetSysColor(COLOR_WINDOWFRAME
);
96 color_background
= GetSysColor(COLOR_BACKGROUND
);
97 color_window
= GetSysColor(COLOR_WINDOW
);
98 color_windowtext
= GetSysColor(COLOR_WINDOWTEXT
);
99 InvalidateRect(hWnd
, NULL
, TRUE
);
104 USER_HEAP_FREE(wndPtr
->hText
);
106 wndPtr
->hText
= USER_HEAP_ALLOC(GMEM_MOVEABLE
,
107 strlen((LPSTR
)lParam
) + 1);
108 textPtr
= (LPSTR
)USER_HEAP_ADDR(wndPtr
->hText
);
109 strcpy(textPtr
, (LPSTR
)lParam
);
110 InvalidateRect(hWnd
, NULL
, TRUE
);
123 return(SendMessage(wndPtr
->hwndParent
, uMsg
, wParam
, lParam
));
126 lResult
= DefWindowProc(hWnd
, uMsg
, wParam
, lParam
);
135 static LONG
PaintTextfn(HWND hwnd
)
146 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
147 LONG style
= wndPtr
->dwStyle
;
149 hdc
= BeginPaint(hwnd
, &ps
);
150 GetClientRect(hwnd
, &rc
);
152 textlen
= GetWindowTextLength(hwnd
);
153 hText
= USER_HEAP_ALLOC(0, textlen
+1);
154 text
= USER_HEAP_ADDR(hText
);
155 GetWindowText(hwnd
, text
, textlen
+1);
157 switch (style
& 0x0000000F)
160 wFormat
= DT_LEFT
| DT_EXPANDTABS
| DT_WORDBREAK
;
164 wFormat
= DT_CENTER
| DT_EXPANDTABS
| DT_WORDBREAK
;
168 wFormat
= DT_RIGHT
| DT_EXPANDTABS
| DT_WORDBREAK
;
172 wFormat
= DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
;
175 case SS_LEFTNOWORDWRAP
:
176 wFormat
= DT_LEFT
| DT_SINGLELINE
| DT_EXPANDTABS
| DT_VCENTER
;
180 if (style
& SS_NOPREFIX
)
181 wFormat
|= DT_NOPREFIX
;
183 hBrush
= SendMessage(GetParent(hwnd
), WM_CTLCOLOR
, (WORD
)hdc
,
184 MAKELONG(hwnd
, CTLCOLOR_STATIC
));
185 if (hBrush
== (HBRUSH
)NULL
) hBrush
= GetStockObject(WHITE_BRUSH
);
186 FillRect(hdc
, &rc
, hBrush
);
187 DrawText(hdc
, text
, textlen
, &rc
, wFormat
);
189 USER_HEAP_FREE(hText
);
194 static LONG
PaintRectfn(HWND hwnd
)
200 HBRUSH hOldBrush
, hBrush
;
202 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
204 hdc
= BeginPaint(hwnd
, &ps
);
205 GetClientRect(hwnd
, &rc
);
207 switch (wndPtr
->dwStyle
& 0x0000000F)
210 hPen
= CreatePen(PS_SOLID
, 1, color_windowframe
);
211 hBrush
= CreateSolidBrush(color_windowframe
);
215 hPen
= CreatePen(PS_SOLID
, 1, color_background
);
216 hBrush
= CreateSolidBrush(color_background
);
220 hPen
= CreatePen(PS_SOLID
, 1, color_window
);
221 hBrush
= CreateSolidBrush(color_window
);
225 hOldPen
= (HPEN
)SelectObject(hdc
, (HANDLE
)hPen
);
226 hOldBrush
= (HBRUSH
)SelectObject(hdc
, (HANDLE
)hBrush
);
227 Rectangle(hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
229 SelectObject(hdc
, (HANDLE
)hOldPen
);
230 SelectObject(hdc
, (HANDLE
)hOldBrush
);
231 DeleteObject((HANDLE
)hPen
);
232 DeleteObject((HANDLE
)hBrush
);
238 static LONG
PaintFramefn(HWND hwnd
)
244 HBRUSH hOldBrush
, hBrush
;
246 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
248 hdc
= BeginPaint(hwnd
, &ps
);
249 GetClientRect(hwnd
, &rc
);
251 switch (wndPtr
->dwStyle
& 0x0000000F)
254 hPen
= CreatePen(PS_SOLID
, 1, color_windowframe
);
258 hPen
= CreatePen(PS_SOLID
, 1, color_background
);
262 hPen
= CreatePen(PS_SOLID
, 1, color_window
);
266 hBrush
= CreateSolidBrush(color_window
);
267 hOldPen
= (HPEN
)SelectObject(hdc
, (HANDLE
)hPen
);
268 hOldBrush
= (HBRUSH
)SelectObject(hdc
, (HANDLE
)hBrush
);
269 Rectangle(hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
271 SelectObject(hdc
, (HANDLE
)hOldPen
);
272 SelectObject(hdc
, (HANDLE
)hOldBrush
);
273 DeleteObject((HANDLE
)hPen
);
274 DeleteObject((HANDLE
)hBrush
);
281 static LONG
PaintIconfn(HWND hwnd
)
290 wndPtr
= WIN_FindWndPtr(hwnd
);
291 hdc
= BeginPaint(hwnd
, &ps
);
292 GetClientRect(hwnd
, &rc
);
293 FillRect(hdc
, &rc
, GetStockObject(WHITE_BRUSH
));
294 textPtr
= (LPSTR
)USER_HEAP_ADDR(wndPtr
->hText
);
295 printf("SS_ICON : textPtr='%8x' / left=%d top=%d right=%d bottom=%d \n",
296 textPtr
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
298 SetWindowPos(hwnd, (HWND)NULL, 0, 0, 32, 32,
299 SWP_NOZORDER | SWP_NOMOVE);
300 GetClientRect(hwnd, &rc);
301 printf("SS_ICON : textPtr='%s' / left=%d top=%d right=%d bottom=%d \n",
302 textPtr, rc.left, rc.top, rc.right, rc.bottom);
304 hIcon
= LoadIcon(wndPtr
->hInstance
, textPtr
);
305 DrawIcon(hdc
, rc
.left
, rc
.top
, hIcon
);