Check for failed allocations and fix some resource leaks.
[reactos.git] / rosapps / welcome / welcome.c
1 /*
2 * ReactOS applications
3 * Copyright (C) 2001, 2002 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 /* $Id$
20 *
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS welcome/autorun application
23 * FILE: welcome/welcome.c
24 * PROGRAMMERS: Eric Kohl (ekohl@rz-online.de)
25 */
26
27 #include <windows.h>
28 #include <string.h>
29 #include <tchar.h>
30
31 #include "resource.h"
32
33
34
35 #define LIGHT_BLUE 0x00F0CAA6
36 #define DARK_BLUE 0x00996633
37
38
39
40 /* GLOBALS ******************************************************************/
41
42 TCHAR szFrameClass [] = "WelcomeWindowClass";
43 TCHAR szAppTitle [80];
44
45 HINSTANCE hInstance;
46
47 HWND hwndMain = 0;
48 HWND hwndDefaultTopic = 0;
49
50 HBITMAP hTitleBitmap = 0;
51 HDC hdcDisplay=0;
52 HDC hdcMem = 0;
53
54 int nTopic = -1;
55 int nDefaultTopic = -1;
56
57 ULONG ulInnerWidth = 480;
58 ULONG ulInnerHeight = 360;
59
60 HBITMAP hDefaultTopicBitmap;
61 HBITMAP hTopicBitmap[10];
62 HWND hwndTopicButton[10];
63 HWND hwndCloseButton;
64 HWND hwndCheckButton;
65
66
67 HFONT hfontTopicButton;
68 HFONT hfontTopicTitle;
69 HFONT hfontTopicDescription;
70 HFONT hfontCheckButton;
71
72 HFONT hfontBannerTitle;
73
74 HBRUSH hbrLightBlue;
75 HBRUSH hbrDarkBlue;
76 HBRUSH hbrRightPanel;
77
78 RECT rcTitlePanel;
79 RECT rcLeftPanel;
80 RECT rcRightPanel;
81
82 WNDPROC fnOldBtn;
83
84
85 LRESULT CALLBACK
86 MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
87
88
89 /* FUNCTIONS ****************************************************************/
90
91 int WINAPI
92 WinMain(HINSTANCE hInst,
93 HINSTANCE hPrevInstance,
94 LPSTR lpszCmdLine,
95 int nCmdShow)
96 {
97 WNDCLASSEX wndclass;
98 MSG msg;
99 int xPos;
100 int yPos;
101 int xWidth;
102 int yHeight;
103 RECT rcWindow;
104 DWORD dwStyle = WS_OVERLAPPED | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_CAPTION | WS_SYSMENU | WS_VISIBLE;
105
106 hInstance = hInst;
107
108 /* Register the window class */
109 wndclass.style = CS_OWNDC;
110 wndclass.lpfnWndProc = (WNDPROC)MainWndProc;
111 wndclass.cbClsExtra = 0;
112 wndclass.cbWndExtra = 0;
113 wndclass.hInstance = hInstance;
114 wndclass.hIcon = 0;
115 wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
116 wndclass.hbrBackground = 0;
117 wndclass.lpszMenuName = NULL;
118 wndclass.lpszClassName = szFrameClass;
119
120 wndclass.cbSize = sizeof(WNDCLASSEX);
121 wndclass.hIconSm = 0;
122
123 RegisterClassEx(&wndclass);
124
125 rcWindow.top = 0;
126 rcWindow.bottom = ulInnerHeight - 1;
127 rcWindow.left = 0;
128 rcWindow.right = ulInnerWidth - 1;
129
130 AdjustWindowRect(&rcWindow,
131 dwStyle,
132 FALSE);
133 xWidth = rcWindow.right - rcWindow.left;
134 yHeight = rcWindow.bottom - rcWindow.top;
135
136 xPos = (GetSystemMetrics(SM_CXSCREEN) - xWidth) / 2;
137 yPos = (GetSystemMetrics(SM_CYSCREEN) - yHeight) / 2;
138
139 rcTitlePanel.top = 0;
140 rcTitlePanel.bottom = 93;
141 rcTitlePanel.left = 0;
142 rcTitlePanel.right = ulInnerWidth - 1;
143
144 rcLeftPanel.top = rcTitlePanel.bottom;
145 rcLeftPanel.bottom = ulInnerHeight - 1;
146 rcLeftPanel.left = 0;
147 rcLeftPanel.right = ulInnerWidth / 3;
148
149 rcRightPanel.top = rcLeftPanel.top;
150 rcRightPanel.bottom = rcLeftPanel.bottom;
151 rcRightPanel.left = rcLeftPanel.right;
152 rcRightPanel.right = ulInnerWidth - 1;
153
154 if (!LoadString(hInstance, (UINT)MAKEINTRESOURCE(IDS_APPTITLE), szAppTitle, 80))
155 _tcscpy(szAppTitle, TEXT("ReactOS Welcome"));
156
157 /* Create main window */
158 hwndMain = CreateWindow(szFrameClass,
159 szAppTitle,
160 dwStyle,
161 xPos,
162 yPos,
163 xWidth,
164 yHeight,
165 0,
166 0,
167 hInstance,
168 NULL);
169
170 ShowWindow(hwndMain, nCmdShow);
171 UpdateWindow(hwndMain);
172
173 while (GetMessage(&msg, NULL, 0, 0) != FALSE)
174 {
175 TranslateMessage(&msg);
176 DispatchMessage(&msg);
177 }
178
179 return(msg.wParam);
180 }
181
182
183 LRESULT CALLBACK
184 ButtonSubclassWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
185 {
186 LONG i;
187
188 if (uMsg == WM_MOUSEMOVE)
189 {
190 i = GetWindowLong(hWnd, GWL_ID);
191 if (nTopic != i)
192 {
193 nTopic = i;
194 SetFocus(hWnd);
195 InvalidateRect(hwndMain, NULL, TRUE);
196 }
197 }
198
199 return(CallWindowProc(fnOldBtn, hWnd, uMsg, wParam, lParam));
200 }
201
202
203 static BOOL
204 RunApplication(int nTopic)
205 {
206 PROCESS_INFORMATION ProcessInfo;
207 STARTUPINFO StartupInfo;
208 CHAR AppName[256];
209 CHAR CurrentDir[256];
210 int nLength;
211
212 InvalidateRect(hwndMain, NULL, TRUE);
213
214 GetCurrentDirectory(256, CurrentDir);
215
216 nLength = LoadString(hInstance, IDS_TOPICACTION0 + nTopic, AppName, 256);
217 if (nLength == 0)
218 return(FALSE);
219
220 if (stricmp(AppName, "explorer.exe") == 0)
221 {
222 strcat(AppName, " ");
223 strcat(AppName, CurrentDir);
224 }
225
226 memset(&StartupInfo, 0, sizeof(STARTUPINFO));
227 StartupInfo.cb = sizeof(STARTUPINFO);
228 StartupInfo.lpTitle = "Test";
229 StartupInfo.dwFlags = STARTF_USESHOWWINDOW;
230 StartupInfo.wShowWindow = SW_SHOWNORMAL;
231
232 CreateProcess(NULL, AppName, NULL, NULL, FALSE, CREATE_NEW_CONSOLE,NULL,
233 CurrentDir,
234 &StartupInfo,
235 &ProcessInfo);
236
237 CloseHandle(ProcessInfo.hProcess);
238 CloseHandle(ProcessInfo.hThread);
239
240 return(TRUE);
241 }
242
243 static VOID
244 SubclassButton(HWND hWnd)
245 {
246 fnOldBtn = (WNDPROC)SetWindowLong(hWnd, GWL_WNDPROC, (LPARAM)ButtonSubclassWndProc);
247 }
248
249
250 static DWORD
251 GetButtonHeight(HDC hDC,
252 HFONT hFont,
253 PSZ szText,
254 DWORD dwWidth)
255 {
256 HFONT hOldFont;
257 RECT rect;
258
259 rect.left = 0;
260 rect.right = dwWidth - 20;
261 rect.top = 0;
262 rect.bottom = 25;
263
264 hOldFont = SelectObject(hDC, hFont);
265 DrawText(hDC, szText, -1, &rect, DT_TOP | DT_CALCRECT | DT_WORDBREAK);
266 SelectObject(hDC, hOldFont);
267
268 return(rect.bottom-rect.top + 14);
269 }
270
271
272 static LRESULT
273 OnCreate(HWND hWnd, WPARAM wParam, LPARAM lParam)
274 {
275 char szText[80];
276 int i,nLength;
277 DWORD dwTop;
278 DWORD dwHeight = 0;
279
280 hbrLightBlue = CreateSolidBrush (LIGHT_BLUE);
281 hbrDarkBlue = CreateSolidBrush(DARK_BLUE);
282 hbrRightPanel = CreateSolidBrush (0x00FFFFFF);
283
284 /* Banner fonts */
285 hfontBannerTitle = CreateFont(-30,0,0,0,FW_BOLD,
286 FALSE,FALSE,FALSE,ANSI_CHARSET,
287 OUT_DEFAULT_PRECIS,
288 CLIP_DEFAULT_PRECIS,
289 DEFAULT_QUALITY,
290 FF_DONTCARE,
291 "Arial");
292
293 hfontTopicTitle = CreateFont(-18,0,0,0,FW_NORMAL,
294 FALSE,FALSE,FALSE,ANSI_CHARSET,
295 OUT_DEFAULT_PRECIS,
296 CLIP_DEFAULT_PRECIS,
297 DEFAULT_QUALITY,
298 FF_DONTCARE,
299 "Arial");
300
301
302 hfontTopicDescription = CreateFont(-11,0,0,0,FW_THIN,
303 FALSE,FALSE,FALSE,ANSI_CHARSET,
304 OUT_DEFAULT_PRECIS,
305 CLIP_DEFAULT_PRECIS,
306 DEFAULT_QUALITY,
307 FF_DONTCARE,
308 "Arial");
309
310 hfontTopicButton = CreateFont(-11,0,0,0,FW_BOLD,
311 FALSE,FALSE,FALSE,ANSI_CHARSET,
312 OUT_DEFAULT_PRECIS,
313 CLIP_DEFAULT_PRECIS,
314 DEFAULT_QUALITY,
315 FF_DONTCARE,
316 "Arial");
317
318 /* Load bitmaps */
319 hTitleBitmap = LoadBitmap (hInstance, MAKEINTRESOURCE(IDB_TITLEBITMAP));
320 hDefaultTopicBitmap = LoadBitmap (hInstance, MAKEINTRESOURCE(IDB_DEFAULTTOPICBITMAP));
321 for (i=0;i < 10; i++)
322 {
323 hTopicBitmap[i] = LoadBitmap (hInstance, MAKEINTRESOURCE(IDB_TOPICBITMAP0+i));
324 }
325
326 hdcDisplay = CreateDC ("DISPLAY", NULL, NULL, NULL);
327 hdcMem = CreateCompatibleDC (hdcDisplay);
328
329 /* load and create buttons */
330 dwTop = rcLeftPanel.top;
331 for (i=0;i < 10; i++)
332 {
333 nLength = LoadString(hInstance, IDS_TOPICBUTTON0+i,szText,80);
334 if (nLength > 0)
335 {
336 dwHeight = GetButtonHeight(hdcMem,
337 hfontTopicButton,
338 szText,
339 rcLeftPanel.right - rcLeftPanel.left);
340
341 hwndTopicButton[i] = CreateWindow("BUTTON",
342 szText,
343 WS_CHILDWINDOW | WS_VISIBLE | WS_TABSTOP | BS_MULTILINE | BS_OWNERDRAW,
344 rcLeftPanel.left,
345 dwTop,
346 rcLeftPanel.right - rcLeftPanel.left,
347 dwHeight,
348 hWnd,
349 (HMENU)i,
350 hInstance,
351 NULL);
352 hwndDefaultTopic = hwndTopicButton[i];
353 nDefaultTopic = i;
354 SubclassButton(hwndTopicButton[i]);
355 SendMessage(hwndTopicButton[i], WM_SETFONT, (WPARAM)hfontTopicButton, MAKELPARAM(TRUE,0));
356 }
357 else
358 {
359 hwndTopicButton[i] = 0;
360 }
361
362 dwTop += dwHeight;
363 }
364
365 /* Create exit button */
366 nLength = LoadString(hInstance, IDS_CLOSETEXT, szText, 80);
367 if (nLength > 0)
368 {
369 hwndCloseButton = CreateWindow("BUTTON",
370 szText,
371 WS_VISIBLE | WS_CHILD | BS_FLAT,
372 rcRightPanel.right - 10 - 57,
373 rcRightPanel.bottom - 10 - 21,
374 57,
375 21,
376 hWnd,
377 (HMENU)IDC_CLOSEBUTTON,
378 hInstance,
379 NULL);
380 hwndDefaultTopic = 0;
381 nDefaultTopic = -1;
382 SendMessage(hwndCloseButton, WM_SETFONT, (WPARAM)hfontTopicButton, MAKELPARAM(TRUE,0));
383 }
384 else
385 {
386 hwndCloseButton = 0;
387 }
388
389 /* Create checkbox */
390 nLength = LoadString(hInstance, IDS_CHECKTEXT,szText,80);
391 if (nLength > 0)
392 {
393 hfontCheckButton = CreateFont(-10,0,0,0,FW_THIN,FALSE,FALSE,FALSE,ANSI_CHARSET,
394 OUT_DEFAULT_PRECIS,
395 CLIP_DEFAULT_PRECIS,
396 DEFAULT_QUALITY,
397 FF_DONTCARE,
398 "Tahoma");
399
400 hwndCheckButton = CreateWindow("BUTTON",
401 szText,
402 WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX,
403 rcLeftPanel.left + 8,
404 rcLeftPanel.bottom - 8 - 13,
405 rcLeftPanel.right - rcLeftPanel.left - 16,
406 13,
407 hWnd,
408 (HMENU)IDC_CHECKBUTTON,
409 hInstance,
410 NULL);
411 SendMessage(hwndCheckButton, WM_SETFONT, (WPARAM)hfontCheckButton, MAKELPARAM(TRUE,0));
412 }
413 else
414 {
415 hwndCheckButton = 0;
416 hfontCheckButton = 0;
417 }
418
419 return 0;
420 }
421
422
423 static LRESULT
424 OnCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
425 {
426 if (LOWORD(wParam) == IDC_CLOSEBUTTON)
427 {
428 DestroyWindow(hWnd);
429 }
430 else if ((LOWORD(wParam) < 10))
431 {
432 if (RunApplication(LOWORD(wParam)) == FALSE)
433 {
434 DestroyWindow(hWnd);
435 }
436 }
437 return 0;
438 }
439
440
441 static VOID
442 PaintBanner(HDC hdc, LPRECT rcPanel)
443 {
444 HBRUSH hOldBrush;
445 HFONT hOldFont;
446 RECT rcTitle;
447
448 #if 0
449 /* banner bitmap */
450 hOldBitmap = SelectObject(hdcMem, hTitleBitmap);
451 BitBlt(hdc,
452 rcPanel->left,
453 rcPanel->top,
454 rcPanel->right,
455 rcPanel->bottom - 3,
456 hdcMem, 0, 0, SRCCOPY);
457 SelectObject(hdc, hOldBitmap);
458 #endif
459
460 /* white background */
461 hOldBrush = SelectObject(hdc, hbrRightPanel);
462 PatBlt(hdc,
463 rcPanel->left,
464 rcPanel->top,
465 rcPanel->right - rcPanel->left,
466 rcPanel->bottom - 3,
467 PATCOPY);
468
469 hOldFont = SelectObject (hdc, hfontBannerTitle);
470 SetTextColor(hdc, 0x00000000);
471
472 rcTitle.top = 5;
473 rcTitle.left = 15;
474 DrawText(hdc, "ReactOS 0.0.20", -1,
475 &rcTitle, DT_TOP | DT_CALCRECT);
476
477 DrawText(hdc, "ReactOS 0.0.20", -1,
478 &rcTitle, DT_TOP);
479
480 SelectObject(hdc, hOldFont);
481
482 /* dark blue line */
483 hOldBrush = SelectObject(hdc, hbrDarkBlue);
484 PatBlt(hdc,
485 rcPanel->left,
486 rcPanel->bottom - 3,
487 rcPanel->right - rcPanel->left,
488 3,
489 PATCOPY);
490
491 SelectObject(hdc, hOldBrush);
492 }
493
494
495 static LRESULT
496 OnPaint(HWND hWnd, WPARAM wParam, LPARAM lParam)
497 {
498 HDC hdc;
499 PAINTSTRUCT ps;
500 HBITMAP hOldBitmap = 0;
501 HBRUSH hOldBrush;
502 HFONT hOldFont;
503 RECT rcTitle, rcDescription;
504 TCHAR szTopicTitle[80];
505 TCHAR szTopicDesc[256];
506 int nLength;
507 BITMAP bmpInfo;
508
509 hdc = BeginPaint(hWnd, &ps);
510
511 /* Banner panel */
512 PaintBanner(hdc, &rcTitlePanel);
513
514 /* Left panel */
515 hOldBrush = SelectObject (hdc, hbrLightBlue);
516 PatBlt(hdc,
517 rcLeftPanel.left,
518 rcLeftPanel.top,
519 rcLeftPanel.right - rcLeftPanel.left,
520 rcLeftPanel.bottom - rcLeftPanel.top,
521 PATCOPY);
522
523 /* Right panel */
524 SelectObject (hdc, hbrRightPanel);
525 PatBlt(hdc,
526 rcRightPanel.left,
527 rcRightPanel.top,
528 rcRightPanel.right - rcRightPanel.left,
529 rcRightPanel.bottom - rcRightPanel.top,
530 PATCOPY);
531
532 /* Draw topic bitmap */
533 if ((nTopic == -1) && (hDefaultTopicBitmap != 0))
534 {
535 GetObject(hDefaultTopicBitmap, sizeof(BITMAP), &bmpInfo);
536 hOldBitmap = SelectObject (hdcMem, hDefaultTopicBitmap);
537 BitBlt(hdc,
538 rcRightPanel.right - bmpInfo.bmWidth,
539 rcRightPanel.bottom - bmpInfo.bmHeight,
540 bmpInfo.bmWidth,
541 bmpInfo.bmHeight,
542 hdcMem,
543 0,
544 0,
545 SRCCOPY);
546 }
547 else if (hTopicBitmap[nTopic] != 0)
548 {
549 GetObject(hTopicBitmap[nTopic], sizeof(BITMAP), &bmpInfo);
550 hOldBitmap = SelectObject (hdcMem, hTopicBitmap[nTopic]);
551 BitBlt(hdc,
552 rcRightPanel.right - bmpInfo.bmWidth,
553 rcRightPanel.bottom - bmpInfo.bmHeight,
554 bmpInfo.bmWidth,
555 bmpInfo.bmHeight,
556 hdcMem,
557 0,
558 0,
559 SRCCOPY);
560 }
561
562 if (nTopic == -1)
563 {
564 nLength = LoadString(hInstance, IDS_DEFAULTTOPICTITLE, szTopicTitle, 80);
565 }
566 else
567 {
568 nLength = LoadString(hInstance, IDS_TOPICTITLE0 + nTopic, szTopicTitle, 80);
569 if (nLength == 0)
570 nLength = LoadString(hInstance, IDS_DEFAULTTOPICTITLE, szTopicTitle, 80);
571 }
572
573 if (nTopic == -1)
574 {
575 nLength = LoadString(hInstance, IDS_DEFAULTTOPICDESC, szTopicDesc, 256);
576 }
577 else
578 {
579 nLength = LoadString(hInstance, IDS_TOPICDESC0 + nTopic, szTopicDesc, 256);
580 if (nLength == 0)
581 nLength = LoadString(hInstance, IDS_DEFAULTTOPICDESC, szTopicDesc, 256);
582 }
583
584 SetBkMode(hdc, TRANSPARENT);
585
586 /* Draw topic title */
587 rcTitle.left = rcRightPanel.left + 12;
588 rcTitle.right = rcRightPanel.right - 8;
589 rcTitle.top = rcRightPanel.top + 8;
590 rcTitle.bottom = rcTitle.top + 57;
591 hOldFont = SelectObject(hdc, hfontTopicTitle);
592 DrawText(hdc, szTopicTitle, -1, &rcTitle, DT_TOP | DT_CALCRECT);
593
594 SetTextColor(hdc, DARK_BLUE);
595 DrawText(hdc, szTopicTitle, -1, &rcTitle, DT_TOP);
596
597 /* Draw topic description */
598 rcDescription.left = rcRightPanel.left + 12;
599 rcDescription.right = rcRightPanel.right - 8;
600 rcDescription.top = rcTitle.bottom + 8;
601 rcDescription.bottom = rcRightPanel.bottom - 20;
602
603 SelectObject(hdc, hfontTopicDescription);
604 SetTextColor(hdc, 0x00000000);
605 DrawText(hdc, szTopicDesc, -1, &rcDescription, DT_TOP | DT_WORDBREAK);
606
607 SetBkMode(hdc, OPAQUE);
608 SelectObject(hdc, hOldFont);
609
610 SelectObject (hdcMem, hOldBrush);
611 SelectObject (hdcMem, hOldBitmap);
612
613 EndPaint(hWnd, &ps);
614 return 0;
615 }
616
617
618 static LRESULT
619 OnDrawItem(HWND hWnd, WPARAM wParam, LPARAM lParam)
620 {
621 LPDRAWITEMSTRUCT lpDis = (LPDRAWITEMSTRUCT)lParam;
622 HPEN hPen, hOldPen;
623 HBRUSH hOldBrush;
624 CHAR szText[80];
625 int iBkMode;
626
627 if (lpDis->hwndItem == hwndCloseButton)
628 {
629 DrawFrameControl(lpDis->hDC,
630 &lpDis->rcItem,
631 DFC_BUTTON,
632 DFCS_BUTTONPUSH | DFCS_FLAT);
633 }
634 else
635 {
636 if (lpDis->CtlID == (ULONG)nTopic)
637 hOldBrush = SelectObject(lpDis->hDC, hbrRightPanel);
638 else
639 hOldBrush = SelectObject(lpDis->hDC, hbrLightBlue);
640 PatBlt(lpDis->hDC,
641 lpDis->rcItem.left,
642 lpDis->rcItem.top,
643 lpDis->rcItem.right,
644 lpDis->rcItem.bottom,
645 PATCOPY);
646 SelectObject(lpDis->hDC, hOldBrush);
647
648 hPen = CreatePen(PS_SOLID, 0, DARK_BLUE);
649 hOldPen = SelectObject(lpDis->hDC, hPen);
650 MoveToEx(lpDis->hDC, lpDis->rcItem.left, lpDis->rcItem.bottom-1, NULL);
651 LineTo(lpDis->hDC, lpDis->rcItem.right, lpDis->rcItem.bottom-1);
652 SelectObject(lpDis->hDC, hOldPen);
653 DeleteObject(hPen);
654
655 InflateRect(&lpDis->rcItem, -10, -4);
656 OffsetRect(&lpDis->rcItem, 0, 1);
657 GetWindowText(lpDis->hwndItem, szText, 80);
658 SetTextColor(lpDis->hDC, 0x00000000);
659 iBkMode = SetBkMode(lpDis->hDC, TRANSPARENT);
660 DrawText(lpDis->hDC, szText, -1, &lpDis->rcItem, DT_TOP | DT_LEFT | DT_WORDBREAK);
661 SetBkMode(lpDis->hDC, iBkMode);
662 }
663
664 return 0;
665 }
666
667
668 static LRESULT
669 OnMouseMove(HWND hWnd, WPARAM wParam, LPARAM lParam)
670 {
671 if (nTopic != -1)
672 {
673 nTopic = -1;
674 SetFocus(hWnd);
675 InvalidateRect(hwndMain, NULL, TRUE);
676 }
677
678 return 0;
679 }
680
681
682 static LRESULT
683 OnCtlColorStatic(HWND hWnd, WPARAM wParam, LPARAM lParam)
684 {
685 if ((HWND)lParam == hwndCheckButton)
686 {
687 SetBkColor((HDC)wParam, LIGHT_BLUE);
688 return((LRESULT)hbrLightBlue);
689 }
690
691 return 0;
692 }
693
694
695 static LRESULT
696 OnActivate(HWND hWnd, WPARAM wParam, LPARAM lParam)
697 {
698 nTopic = -1;
699 InvalidateRect(hwndMain, NULL, TRUE);
700
701 return(0);
702 }
703
704
705 static LRESULT
706 OnDestroy(HWND hWnd, WPARAM wParam, LPARAM lParam)
707 {
708 int i;
709
710 for (i=0;i<10;i++)
711 {
712 if (hwndTopicButton[i] != 0)
713 DestroyWindow(hwndTopicButton[i]);
714 }
715
716 if (hwndCloseButton != 0)
717 DestroyWindow(hwndCloseButton);
718
719 if (hwndCheckButton != 0)
720 DestroyWindow(hwndCheckButton);
721
722 DeleteDC(hdcMem);
723 DeleteDC(hdcDisplay);
724
725 /* delete bitmaps */
726 DeleteObject(hDefaultTopicBitmap);
727 DeleteObject(hTitleBitmap);
728 for (i=0;i<10;i++)
729 {
730 if (hTopicBitmap[i] != 0)
731 DeleteObject(hTopicBitmap[i]);
732 }
733
734 DeleteObject(hfontTopicTitle);
735 DeleteObject(hfontTopicDescription);
736 DeleteObject(hfontTopicButton);
737
738 DeleteObject(hfontBannerTitle);
739
740
741 if (hfontCheckButton != 0)
742 DeleteObject(hfontCheckButton);
743
744 DeleteObject(hbrLightBlue);
745 DeleteObject(hbrDarkBlue);
746 DeleteObject(hbrRightPanel);
747
748 return 0;
749 }
750
751
752 LRESULT CALLBACK
753 MainWndProc(HWND hWnd,
754 UINT uMsg,
755 WPARAM wParam,
756 LPARAM lParam)
757 {
758 switch(uMsg)
759 {
760 case WM_CREATE:
761 return(OnCreate(hWnd, wParam, lParam));
762
763 case WM_COMMAND:
764 return(OnCommand(hWnd, wParam, lParam));
765
766 case WM_ACTIVATE:
767 return(OnActivate(hWnd, wParam, lParam));
768
769 case WM_PAINT:
770 return(OnPaint(hWnd, wParam, lParam));
771
772 case WM_DRAWITEM:
773 return(OnDrawItem(hWnd, wParam, lParam));
774
775 case WM_CTLCOLORSTATIC:
776 return(OnCtlColorStatic(hWnd, wParam, lParam));
777
778 case WM_MOUSEMOVE:
779 return(OnMouseMove(hWnd, wParam, lParam));
780
781 case WM_DESTROY:
782 OnDestroy(hWnd, wParam, lParam);
783 PostQuitMessage(0);
784 return(0);
785 }
786
787 return(DefWindowProc(hWnd, uMsg, wParam, lParam));
788 }
789
790 /* EOF */