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