4 * Copyright David W. Metcalfe, 1993
8 static char Copyright[] = "Copyright David W. Metcalfe, 1993";
14 LONG StaticWndProc(HWND hWnd, WORD uMsg, WORD wParam, LONG lParam);
16 static LONG PaintTextfn(HWND hwnd);
17 static LONG PaintRectfn(HWND hwnd);
18 static LONG PaintFramefn(HWND hwnd);
19 static LONG PaintIconfn(HWND hwnd);
22 static COLORREF color_windowframe, color_background, color_window,
25 #define NOTIFY_PARENT(hWndCntrl, wNotifyCode) \
26 SendMessage(GetParent(hWndCntrl), WM_COMMAND, \
27 GetDlgCtrlID(hWndCntrl), MAKELPARAM(hWndCntrl, wNotifyCode));
28 #define DIM(array) ((sizeof array)/(sizeof array[0]))
35 #define MAX_STATIC_TYPE 12
37 static STATICFN staticfn[MAX_STATIC_TYPE] =
39 { (LONG(*)())PaintTextfn }, /* SS_LEFT */
40 { (LONG(*)())PaintTextfn }, /* SS_CENTER */
41 { (LONG(*)())PaintTextfn }, /* SS_RIGHT */
42 { (LONG(*)())PaintIconfn }, /* SS_ICON */
43 { (LONG(*)())PaintRectfn }, /* SS_BLACKRECT */
44 { (LONG(*)())PaintRectfn }, /* SS_GRAYRECT */
45 { (LONG(*)())PaintRectfn }, /* SS_WHITERECT */
46 { (LONG(*)())PaintFramefn }, /* SS_BLACKFRAME */
47 { (LONG(*)())PaintFramefn }, /* SS_GRAYFRAME */
48 { (LONG(*)())PaintFramefn }, /* SS_WHITEFRAME */
49 { (LONG(*)())PaintTextfn }, /* SS_SIMPLE */
50 { (LONG(*)())PaintTextfn } /* SS_LEFTNOWORDWRAP */
54 LONG StaticWndProc(HWND hWnd, WORD uMsg, WORD wParam, LONG lParam)
61 WND *wndPtr = WIN_FindWndPtr(hWnd);
62 LONG style = wndPtr->dwStyle & 0x0000000F;
66 InvalidateRect(hWnd, NULL, FALSE);
70 if (style < 0L || style >= (LONG)DIM(staticfn)) {
74 /* initialise colours */
75 color_windowframe = GetSysColor(COLOR_WINDOWFRAME);
76 color_background = GetSysColor(COLOR_BACKGROUND);
77 color_window = GetSysColor(COLOR_WINDOW);
78 color_windowtext = GetSysColor(COLOR_WINDOWTEXT);
80 if (style == SS_ICON) {
82 SetWindowPos(hWnd, (HWND)NULL, 0, 0, 32, 32,
83 SWP_NOZORDER | SWP_NOMOVE);
89 if (staticfn[style].paintfn)
90 (staticfn[style].paintfn)(hWnd);
93 case WM_SYSCOLORCHANGE:
94 color_windowframe = GetSysColor(COLOR_WINDOWFRAME);
95 color_background = GetSysColor(COLOR_BACKGROUND);
96 color_window = GetSysColor(COLOR_WINDOW);
97 color_windowtext = GetSysColor(COLOR_WINDOWTEXT);
98 InvalidateRect(hWnd, NULL, TRUE);
103 USER_HEAP_FREE(wndPtr->hText);
105 wndPtr->hText = USER_HEAP_ALLOC(GMEM_MOVEABLE,
106 strlen((LPSTR)lParam) + 1);
107 textPtr = (LPSTR)USER_HEAP_ADDR(wndPtr->hText);
108 strcpy(textPtr, (LPSTR)lParam);
109 InvalidateRect(hWnd, NULL, TRUE);
113 lResult = DefWindowProc(hWnd, uMsg, wParam, lParam);
122 static LONG PaintTextfn(HWND hwnd)
133 WND *wndPtr = WIN_FindWndPtr(hwnd);
134 LONG style = wndPtr->dwStyle;
136 hdc = BeginPaint(hwnd, &ps);
137 GetClientRect(hwnd, &rc);
139 textlen = GetWindowTextLength(hwnd);
140 hText = LocalAlloc(LMEM_MOVEABLE, textlen+1);
141 text = LocalLock(hText);
142 GetWindowText(hwnd, text, textlen+1);
144 switch (style & 0x0000000F)
147 wFormat = DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK;
151 wFormat = DT_CENTER | DT_EXPANDTABS | DT_WORDBREAK;
155 wFormat = DT_RIGHT | DT_EXPANDTABS | DT_WORDBREAK;
159 wFormat = DT_LEFT | DT_SINGLELINE | DT_VCENTER;
162 case SS_LEFTNOWORDWRAP:
163 wFormat = DT_LEFT | DT_SINGLELINE | DT_EXPANDTABS | DT_VCENTER;
167 if (style & SS_NOPREFIX)
168 wFormat |= DT_NOPREFIX;
170 hBrush = SendMessage(GetParent(hwnd), WM_CTLCOLOR, (WORD)hdc,
171 MAKELONG(hwnd, CTLCOLOR_STATIC));
172 if (hBrush == (HBRUSH)NULL) hBrush = GetStockObject(WHITE_BRUSH);
173 FillRect(hdc, &rc, hBrush);
174 DrawText(hdc, text, textlen, &rc, wFormat);
182 static LONG PaintRectfn(HWND hwnd)
188 HBRUSH hOldBrush, hBrush;
190 WND *wndPtr = WIN_FindWndPtr(hwnd);
192 hdc = BeginPaint(hwnd, &ps);
193 GetClientRect(hwnd, &rc);
195 switch (wndPtr->dwStyle & 0x0000000F)
198 hPen = CreatePen(PS_SOLID, 1, color_windowframe);
199 hBrush = CreateSolidBrush(color_windowframe);
203 hPen = CreatePen(PS_SOLID, 1, color_background);
204 hBrush = CreateSolidBrush(color_background);
208 hPen = CreatePen(PS_SOLID, 1, color_window);
209 hBrush = CreateSolidBrush(color_window);
213 hOldPen = (HPEN)SelectObject(hdc, (HANDLE)hPen);
214 hOldBrush = (HBRUSH)SelectObject(hdc, (HANDLE)hBrush);
215 Rectangle(hdc, rc.left, rc.top, rc.right, rc.bottom);
217 SelectObject(hdc, (HANDLE)hOldPen);
218 SelectObject(hdc, (HANDLE)hOldBrush);
219 DeleteObject((HANDLE)hPen);
220 DeleteObject((HANDLE)hBrush);
226 static LONG PaintFramefn(HWND hwnd)
232 HBRUSH hOldBrush, hBrush;
234 WND *wndPtr = WIN_FindWndPtr(hwnd);
236 hdc = BeginPaint(hwnd, &ps);
237 GetClientRect(hwnd, &rc);
239 switch (wndPtr->dwStyle & 0x0000000F)
242 hPen = CreatePen(PS_SOLID, 1, color_windowframe);
246 hPen = CreatePen(PS_SOLID, 1, color_background);
250 hPen = CreatePen(PS_SOLID, 1, color_window);
254 hBrush = CreateSolidBrush(color_window);
255 hOldPen = (HPEN)SelectObject(hdc, (HANDLE)hPen);
256 hOldBrush = (HBRUSH)SelectObject(hdc, (HANDLE)hBrush);
257 Rectangle(hdc, rc.left, rc.top, rc.right, rc.bottom);
259 SelectObject(hdc, (HANDLE)hOldPen);
260 SelectObject(hdc, (HANDLE)hOldBrush);
261 DeleteObject((HANDLE)hPen);
262 DeleteObject((HANDLE)hBrush);
269 static LONG PaintIconfn(HWND hwnd)
278 wndPtr = WIN_FindWndPtr(hwnd);
279 hdc = BeginPaint(hwnd, &ps);
280 GetClientRect(hwnd, &rc);
281 FillRect(hdc, &rc, GetStockObject(WHITE_BRUSH));
282 textPtr = (LPSTR)USER_HEAP_ADDR(wndPtr->hText);
283 printf("SS_ICON : textPtr='%s' / left=%d top=%d right=%d bottom=%d \n",
284 textPtr, rc.left, rc.top, rc.right, rc.bottom);
286 SetWindowPos(hwnd, (HWND)NULL, 0, 0, 32, 32,
287 SWP_NOZORDER | SWP_NOMOVE);
288 GetClientRect(hwnd, &rc);
289 printf("SS_ICON : textPtr='%s' / left=%d top=%d right=%d bottom=%d \n",
290 textPtr, rc.left, rc.top, rc.right, rc.bottom);
292 hIcon = LoadIcon(wndPtr->hInstance, textPtr);
293 DrawIcon(hdc, rc.left, rc.top, hIcon);