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