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