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