fc5b90642c22d3a97a54356bfd57decf43bc9dfd
[reactos.git] / reactos / subsys / system / 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
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: welcome.c,v 1.6 2004/09/26 15:55:53 weiden Exp $
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 * 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 LRESULT CALLBACK
93 MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
94
95
96 /* FUNCTIONS ****************************************************************/
97
98 int WINAPI
99 WinMain(HINSTANCE hInst,
100 HINSTANCE hPrevInstance,
101 LPSTR 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 hInstance = hInst;
118
119 /* Load icons */
120 hMainIcon = LoadIcon (hInstance, MAKEINTRESOURCE(IDI_MAIN));
121
122 /* Register the window class */
123 wndclass.style = CS_HREDRAW | CS_VREDRAW;
124 wndclass.lpfnWndProc = (WNDPROC)MainWndProc;
125 wndclass.cbClsExtra = 0;
126 wndclass.cbWndExtra = 0;
127 wndclass.hInstance = hInstance;
128 wndclass.hIcon = hMainIcon;
129 wndclass.hCursor = LoadCursor (NULL, MAKEINTRESOURCE(IDC_ARROW));
130 wndclass.hbrBackground = 0;
131 wndclass.lpszMenuName = NULL;
132 wndclass.lpszClassName = szFrameClass;
133
134 wndclass.cbSize = sizeof(WNDCLASSEX);
135 wndclass.hIconSm = 0;
136
137 RegisterClassEx(&wndclass);
138
139 hTitleBitmap = LoadBitmap (hInstance, MAKEINTRESOURCE(IDB_TITLEBITMAP));
140 if (hTitleBitmap != NULL)
141 {
142 GetObject(hTitleBitmap, sizeof(BITMAP), &BitmapInfo);
143 ulInnerWidth = BitmapInfo.bmWidth;
144 ulInnerHeight = (ulInnerWidth * 3) / 4;
145 ulTitleHeight = BitmapInfo.bmHeight + 3;
146 }
147 ulInnerHeight -= GetSystemMetrics(SM_CYCAPTION);
148
149 rcWindow.top = 0;
150 rcWindow.bottom = ulInnerHeight - 1;
151 rcWindow.left = 0;
152 rcWindow.right = ulInnerWidth - 1;
153
154 AdjustWindowRect(&rcWindow,
155 dwStyle,
156 FALSE);
157 xWidth = rcWindow.right - rcWindow.left;
158 yHeight = rcWindow.bottom - rcWindow.top;
159
160 xPos = (GetSystemMetrics(SM_CXSCREEN) - xWidth) / 2;
161 yPos = (GetSystemMetrics(SM_CYSCREEN) - yHeight) / 2;
162
163 rcTitlePanel.top = 0;
164 rcTitlePanel.bottom = ulTitleHeight;
165 rcTitlePanel.left = 0;
166 rcTitlePanel.right = ulInnerWidth - 1;
167
168 rcLeftPanel.top = rcTitlePanel.bottom;
169 rcLeftPanel.bottom = ulInnerHeight - 1;
170 rcLeftPanel.left = 0;
171 rcLeftPanel.right = ulInnerWidth / 3;
172
173 rcRightPanel.top = rcLeftPanel.top;
174 rcRightPanel.bottom = rcLeftPanel.bottom;
175 rcRightPanel.left = rcLeftPanel.right;
176 rcRightPanel.right = ulInnerWidth - 1;
177
178 if (!LoadString(hInstance, (UINT)MAKEINTRESOURCE(IDS_APPTITLE), szAppTitle, 80))
179 lstrcpy(szAppTitle, TEXT("ReactOS Welcome"));
180
181 /* Create main window */
182 hwndMain = CreateWindow(szFrameClass,
183 szAppTitle,
184 dwStyle,
185 xPos,
186 yPos,
187 xWidth,
188 yHeight,
189 0,
190 0,
191 hInstance,
192 NULL);
193
194 hSystemMenu = GetSystemMenu(hwndMain, FALSE);
195 if(hSystemMenu)
196 {
197 RemoveMenu(hSystemMenu, SC_SIZE, MF_BYCOMMAND);
198 RemoveMenu(hSystemMenu, SC_MAXIMIZE, MF_BYCOMMAND);
199 }
200
201 ShowWindow(hwndMain, nCmdShow);
202 UpdateWindow(hwndMain);
203
204 while (GetMessage(&msg, NULL, 0, 0) != FALSE)
205 {
206 TranslateMessage(&msg);
207 DispatchMessage(&msg);
208 }
209
210 return(msg.wParam);
211 }
212
213
214 LRESULT CALLBACK
215 ButtonSubclassWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
216 {
217 LONG i;
218
219 if (uMsg == WM_MOUSEMOVE)
220 {
221 i = GetWindowLong(hWnd, GWL_ID);
222 if (nTopic != i)
223 {
224 nTopic = i;
225 SetFocus(hWnd);
226 InvalidateRect(hwndMain, &rcRightPanel, TRUE);
227 }
228 }
229
230 return(CallWindowProc(fnOldBtn, hWnd, uMsg, wParam, lParam));
231 }
232
233
234 static BOOL
235 RunApplication(int nTopic)
236 {
237 PROCESS_INFORMATION ProcessInfo;
238 STARTUPINFO StartupInfo;
239 TCHAR AppName[256];
240 TCHAR CurrentDir[256];
241 int nLength;
242
243 InvalidateRect(hwndMain, NULL, TRUE);
244
245 GetCurrentDirectory(256, CurrentDir);
246
247 nLength = LoadString(hInstance, IDS_TOPICACTION0 + nTopic, AppName, 256);
248 if (nLength == 0)
249 return TRUE;
250
251 if (!lstrcmpi(AppName, TEXT("<exit>")))
252 return FALSE;
253
254 if (lstrcmpi(AppName, TEXT("explorer.exe")) == 0)
255 {
256 lstrcat(AppName, TEXT(" "));
257 lstrcat(AppName, CurrentDir);
258 }
259
260 memset(&StartupInfo, 0, sizeof(STARTUPINFO));
261 StartupInfo.cb = sizeof(STARTUPINFO);
262 StartupInfo.lpTitle = TEXT("Test");
263 StartupInfo.dwFlags = STARTF_USESHOWWINDOW;
264 StartupInfo.wShowWindow = SW_SHOWNORMAL;
265
266 CreateProcess(NULL, AppName, NULL, NULL, FALSE, CREATE_NEW_CONSOLE,NULL,
267 CurrentDir,
268 &StartupInfo,
269 &ProcessInfo);
270
271 CloseHandle(ProcessInfo.hProcess);
272 CloseHandle(ProcessInfo.hThread);
273
274 return TRUE;
275 }
276
277
278 static VOID
279 SubclassButton(HWND hWnd)
280 {
281 fnOldBtn = (WNDPROC)SetWindowLongPtr(hWnd, GWL_WNDPROC, (DWORD_PTR)ButtonSubclassWndProc);
282 }
283
284
285 static DWORD
286 GetButtonHeight(HDC hDC,
287 HFONT hFont,
288 PSZ szText,
289 DWORD dwWidth)
290 {
291 HFONT hOldFont;
292 RECT rect;
293
294 rect.left = 0;
295 rect.right = dwWidth - 20;
296 rect.top = 0;
297 rect.bottom = 25;
298
299 hOldFont = SelectObject(hDC, hFont);
300 DrawText(hDC, szText, -1, &rect, DT_TOP | DT_CALCRECT | DT_WORDBREAK);
301 SelectObject(hDC, hOldFont);
302
303 return(rect.bottom-rect.top + 14);
304 }
305
306
307 static LRESULT
308 OnCreate(HWND hWnd, WPARAM wParam, LPARAM lParam)
309 {
310 TCHAR szText[80];
311 int i,nLength;
312 HDC ScreenDC;
313 DWORD dwTop;
314 DWORD dwHeight = 0;
315
316 hbrLightBlue = CreateSolidBrush(LIGHT_BLUE);
317 hbrDarkBlue = CreateSolidBrush(DARK_BLUE);
318 hbrRightPanel = CreateSolidBrush(0x00FFFFFF);
319
320 /* Topic title font */
321 hfontTopicTitle = CreateFont(-18,0,0,0,FW_NORMAL,
322 FALSE,FALSE,FALSE,ANSI_CHARSET,
323 OUT_DEFAULT_PRECIS,
324 CLIP_DEFAULT_PRECIS,
325 DEFAULT_QUALITY,
326 FF_DONTCARE,
327 "Arial");
328
329 /* Topic description font */
330 hfontTopicDescription = CreateFont(-11,0,0,0,FW_THIN,
331 FALSE,FALSE,FALSE,ANSI_CHARSET,
332 OUT_DEFAULT_PRECIS,
333 CLIP_DEFAULT_PRECIS,
334 DEFAULT_QUALITY,
335 FF_DONTCARE,
336 "Arial");
337
338 /* Topic button font */
339 hfontTopicButton = CreateFont(-11,0,0,0,FW_BOLD,
340 FALSE,FALSE,FALSE,ANSI_CHARSET,
341 OUT_DEFAULT_PRECIS,
342 CLIP_DEFAULT_PRECIS,
343 DEFAULT_QUALITY,
344 FF_DONTCARE,
345 "Arial");
346
347 /* Load title bitmap */
348 if (hTitleBitmap != 0)
349 hTitleBitmap = LoadBitmap (hInstance, MAKEINTRESOURCE(IDB_TITLEBITMAP));
350
351 /* Load topic bitmaps */
352 hDefaultTopicBitmap = LoadBitmap (hInstance, MAKEINTRESOURCE(IDB_DEFAULTTOPICBITMAP));
353 for (i=0;i < 10; i++)
354 {
355 hTopicBitmap[i] = LoadBitmap (hInstance, MAKEINTRESOURCE(IDB_TOPICBITMAP0+i));
356 }
357
358 ScreenDC = GetWindowDC(hWnd);
359 hdcMem = CreateCompatibleDC (ScreenDC);
360 ReleaseDC(hWnd, ScreenDC);
361
362 /* load and create buttons */
363 dwTop = rcLeftPanel.top;
364 for (i = 0; i < 10; i++)
365 {
366 nLength = LoadString(hInstance, IDS_TOPICBUTTON0 + i, szText, 80);
367 if (nLength > 0)
368 {
369 dwHeight = GetButtonHeight(hdcMem,
370 hfontTopicButton,
371 szText,
372 rcLeftPanel.right - rcLeftPanel.left);
373
374 hwndTopicButton[i] = CreateWindow(TEXT("BUTTON"),
375 szText,
376 WS_CHILDWINDOW | WS_VISIBLE | WS_TABSTOP | BS_MULTILINE | BS_OWNERDRAW,
377 rcLeftPanel.left,
378 dwTop,
379 rcLeftPanel.right - rcLeftPanel.left,
380 dwHeight,
381 hWnd,
382 (HMENU)i,
383 hInstance,
384 NULL);
385 hwndDefaultTopic = hwndTopicButton[i];
386 nDefaultTopic = i;
387 SubclassButton(hwndTopicButton[i]);
388 SendMessage(hwndTopicButton[i], WM_SETFONT, (WPARAM)hfontTopicButton, MAKELPARAM(TRUE,0));
389 }
390 else
391 {
392 hwndTopicButton[i] = 0;
393 }
394
395 dwTop += dwHeight;
396 }
397
398 /* Create exit button */
399 nLength = LoadString(hInstance, IDS_CLOSETEXT, szText, 80);
400 if (nLength > 0)
401 {
402 hwndCloseButton = CreateWindow(TEXT("BUTTON"),
403 szText,
404 WS_VISIBLE | WS_CHILD | BS_FLAT,
405 rcRightPanel.right - 10 - 57,
406 rcRightPanel.bottom - 10 - 21,
407 57,
408 21,
409 hWnd,
410 (HMENU)IDC_CLOSEBUTTON,
411 hInstance,
412 NULL);
413 hwndDefaultTopic = 0;
414 nDefaultTopic = -1;
415 SendMessage(hwndCloseButton, WM_SETFONT, (WPARAM)hfontTopicButton, MAKELPARAM(TRUE,0));
416 }
417 else
418 {
419 hwndCloseButton = 0;
420 }
421
422 /* Create checkbox */
423 nLength = LoadString(hInstance, IDS_CHECKTEXT,szText,80);
424 if (nLength > 0)
425 {
426 hfontCheckButton = CreateFont(-10,0,0,0,FW_THIN,FALSE,FALSE,FALSE,ANSI_CHARSET,
427 OUT_DEFAULT_PRECIS,
428 CLIP_DEFAULT_PRECIS,
429 DEFAULT_QUALITY,
430 FF_DONTCARE,
431 TEXT("Tahoma"));
432
433 hwndCheckButton = CreateWindow(TEXT("BUTTON"),
434 szText,
435 WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX,
436 rcLeftPanel.left + 8,
437 rcLeftPanel.bottom - 8 - 13,
438 rcLeftPanel.right - rcLeftPanel.left - 16,
439 13,
440 hWnd,
441 (HMENU)IDC_CHECKBUTTON,
442 hInstance,
443 NULL);
444 SendMessage(hwndCheckButton, WM_SETFONT, (WPARAM)hfontCheckButton, MAKELPARAM(TRUE,0));
445 }
446 else
447 {
448 hwndCheckButton = 0;
449 hfontCheckButton = 0;
450 }
451
452 return 0;
453 }
454
455
456 static LRESULT
457 OnCommand(HWND hWnd, WPARAM wParam, LPARAM 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 = 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(hdc, hOldBitmap);
489
490 /* Dark blue line */
491 hOldBrush = 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[256];
516 int nLength;
517 BITMAP bmpInfo;
518 TCHAR version[50];
519
520 hdc = BeginPaint(hWnd, &ps);
521
522 /* Banner panel */
523 PaintBanner(hdc, &rcTitlePanel);
524
525 /* Left panel */
526 hOldBrush = SelectObject (hdc, hbrLightBlue);
527 PatBlt(hdc,
528 rcLeftPanel.left,
529 rcLeftPanel.top,
530 rcLeftPanel.right - rcLeftPanel.left,
531 rcLeftPanel.bottom - rcLeftPanel.top,
532 PATCOPY);
533 SelectObject(hdc, hOldBrush);
534
535 /* Right panel */
536 hOldBrush = SelectObject (hdc, WHITE_BRUSH);
537 PatBlt(hdc,
538 rcRightPanel.left,
539 rcRightPanel.top,
540 rcRightPanel.right - rcRightPanel.left,
541 rcRightPanel.bottom - rcRightPanel.top,
542 PATCOPY);
543 SelectObject(hdc, hOldBrush);
544
545 /* Draw dark verical line */
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
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
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 version information */
608 wsprintf(version, TEXT("ReactOS %d.%d.%d"),
609 KERNEL_VERSION_MAJOR,
610 KERNEL_VERSION_MINOR,
611 KERNEL_VERSION_PATCH_LEVEL);
612
613 rcTitle.left = rcLeftPanel.left + 8;
614 rcTitle.right = rcLeftPanel.right - 5;
615 rcTitle.top = rcLeftPanel.bottom - 40;
616 rcTitle.bottom = rcLeftPanel.bottom - 5;
617 hOldFont = SelectObject(hdc, hfontTopicDescription);
618 DrawText(hdc, version, -1, &rcTitle, DT_BOTTOM | DT_CALCRECT | DT_SINGLELINE);
619 DrawText(hdc, version, -1, &rcTitle, DT_BOTTOM | DT_SINGLELINE);
620 SelectObject(hdc, hOldFont);
621
622 /* Draw topic title */
623 rcTitle.left = rcRightPanel.left + 12;
624 rcTitle.right = rcRightPanel.right - 8;
625 rcTitle.top = rcRightPanel.top + 8;
626 rcTitle.bottom = rcTitle.top + 57;
627 hOldFont = SelectObject(hdc, hfontTopicTitle);
628 DrawText(hdc, szTopicTitle, -1, &rcTitle, DT_TOP | DT_CALCRECT);
629
630 SetTextColor(hdc, DARK_BLUE);
631 DrawText(hdc, szTopicTitle, -1, &rcTitle, DT_TOP);
632
633 /* Draw topic description */
634 rcDescription.left = rcRightPanel.left + 12;
635 rcDescription.right = rcRightPanel.right - 8;
636 rcDescription.top = rcTitle.bottom + 8;
637 rcDescription.bottom = rcRightPanel.bottom - 20;
638
639 SelectObject(hdc, hfontTopicDescription);
640 SetTextColor(hdc, 0x00000000);
641 DrawText(hdc, szTopicDesc, -1, &rcDescription, DT_TOP | DT_WORDBREAK);
642
643 SetBkMode(hdc, OPAQUE);
644 SelectObject(hdc, hOldFont);
645
646 SelectObject (hdcMem, hOldBrush);
647 SelectObject (hdcMem, hOldBitmap);
648
649 EndPaint(hWnd, &ps);
650
651 return 0;
652 }
653
654
655 static LRESULT
656 OnDrawItem(HWND hWnd, WPARAM wParam, LPARAM lParam)
657 {
658 LPDRAWITEMSTRUCT lpDis = (LPDRAWITEMSTRUCT)lParam;
659 HPEN hPen, hOldPen;
660 HBRUSH hOldBrush;
661 TCHAR szText[80];
662 int iBkMode;
663
664 if (lpDis->hwndItem == hwndCloseButton)
665 {
666 DrawFrameControl(lpDis->hDC,
667 &lpDis->rcItem,
668 DFC_BUTTON,
669 DFCS_BUTTONPUSH | DFCS_FLAT);
670 }
671 else
672 {
673 if (lpDis->CtlID == (ULONG)nTopic)
674 hOldBrush = SelectObject(lpDis->hDC, hbrRightPanel);
675 else
676 hOldBrush = SelectObject(lpDis->hDC, hbrLightBlue);
677
678 PatBlt(lpDis->hDC,
679 lpDis->rcItem.left,
680 lpDis->rcItem.top,
681 lpDis->rcItem.right,
682 lpDis->rcItem.bottom,
683 PATCOPY);
684 SelectObject(lpDis->hDC, hOldBrush);
685
686 hPen = CreatePen(PS_SOLID, 0, DARK_BLUE);
687 hOldPen = SelectObject(lpDis->hDC, hPen);
688 MoveToEx(lpDis->hDC, lpDis->rcItem.left, lpDis->rcItem.bottom-1, NULL);
689 LineTo(lpDis->hDC, lpDis->rcItem.right, lpDis->rcItem.bottom-1);
690 SelectObject(lpDis->hDC, hOldPen);
691 DeleteObject(hPen);
692
693 InflateRect(&lpDis->rcItem, -10, -4);
694 OffsetRect(&lpDis->rcItem, 0, 1);
695 GetWindowText(lpDis->hwndItem, szText, 80);
696 SetTextColor(lpDis->hDC, 0x00000000);
697 iBkMode = SetBkMode(lpDis->hDC, TRANSPARENT);
698 DrawText(lpDis->hDC, szText, -1, &lpDis->rcItem, DT_TOP | DT_LEFT | DT_WORDBREAK);
699 SetBkMode(lpDis->hDC, iBkMode);
700 }
701
702 return 0;
703 }
704
705
706 static LRESULT
707 OnMouseMove(HWND hWnd, WPARAM wParam, LPARAM lParam)
708 {
709 if (nTopic != -1)
710 {
711 nTopic = -1;
712 SetFocus(hWnd);
713 InvalidateRect(hwndMain, &rcRightPanel, TRUE);
714 }
715
716 return 0;
717 }
718
719
720 static LRESULT
721 OnCtlColorStatic(HWND hWnd, WPARAM wParam, LPARAM lParam)
722 {
723 if ((HWND)lParam == hwndCheckButton)
724 {
725 SetBkColor((HDC)wParam, LIGHT_BLUE);
726 return((LRESULT)hbrLightBlue);
727 }
728
729 return 0;
730 }
731
732
733 static LRESULT
734 OnActivate(HWND hWnd, WPARAM wParam, LPARAM lParam)
735 {
736 nTopic = -1;
737 InvalidateRect(hwndMain, &rcRightPanel, TRUE);
738
739 return(0);
740 }
741
742
743 static LRESULT
744 OnDestroy(HWND hWnd, WPARAM wParam, LPARAM lParam)
745 {
746 int i;
747
748 for (i=0;i<10;i++)
749 {
750 if (hwndTopicButton[i] != 0)
751 DestroyWindow(hwndTopicButton[i]);
752 }
753
754 if (hwndCloseButton != 0)
755 DestroyWindow(hwndCloseButton);
756
757 if (hwndCheckButton != 0)
758 DestroyWindow(hwndCheckButton);
759
760 DeleteDC(hdcMem);
761
762 /* delete bitmaps */
763 DeleteObject(hDefaultTopicBitmap);
764 DeleteObject(hTitleBitmap);
765 for (i=0;i<10;i++)
766 {
767 if (hTopicBitmap[i] != 0)
768 DeleteObject(hTopicBitmap[i]);
769 }
770
771 DeleteObject(hfontTopicTitle);
772 DeleteObject(hfontTopicDescription);
773 DeleteObject(hfontTopicButton);
774
775 if (hfontCheckButton != 0)
776 DeleteObject(hfontCheckButton);
777
778 DeleteObject(hbrLightBlue);
779 DeleteObject(hbrDarkBlue);
780 DeleteObject(hbrRightPanel);
781
782 return 0;
783 }
784
785
786 LRESULT CALLBACK
787 MainWndProc(HWND hWnd,
788 UINT uMsg,
789 WPARAM wParam,
790 LPARAM lParam)
791 {
792 switch(uMsg)
793 {
794 case WM_CREATE:
795 return(OnCreate(hWnd, wParam, lParam));
796
797 case WM_COMMAND:
798 return(OnCommand(hWnd, wParam, lParam));
799
800 case WM_ACTIVATE:
801 return(OnActivate(hWnd, wParam, lParam));
802
803 case WM_PAINT:
804 return(OnPaint(hWnd, wParam, lParam));
805
806 case WM_DRAWITEM:
807 return(OnDrawItem(hWnd, wParam, lParam));
808
809 case WM_CTLCOLORSTATIC:
810 return(OnCtlColorStatic(hWnd, wParam, lParam));
811
812 case WM_MOUSEMOVE:
813 return(OnMouseMove(hWnd, wParam, lParam));
814
815 case WM_DESTROY:
816 OnDestroy(hWnd, wParam, lParam);
817 PostQuitMessage(0);
818 return(0);
819 }
820
821 return(DefWindowProc(hWnd, uMsg, wParam, lParam));
822 }
823
824 /* EOF */