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