3 * Copyright (C) 2001, 2002, 2003 ReactOS Team
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.
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.
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.
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)
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!
33 #include "../../../include/reactos/version.h"
43 #define LIGHT_BLUE 0x00F7EFD6
44 #define DARK_BLUE 0x008C7B6B
46 #define TITLE_WIDTH 480
47 #define TITLE_HEIGHT 93
50 /* GLOBALS ******************************************************************/
52 TCHAR szFrameClass
[] = TEXT("WelcomeWindowClass");
53 TCHAR szAppTitle
[80];
58 HWND hwndDefaultTopic
= 0;
63 int nDefaultTopic
= -1;
65 ULONG ulInnerWidth
= TITLE_WIDTH
;
66 ULONG ulInnerHeight
= (TITLE_WIDTH
* 3) / 4;
67 ULONG ulTitleHeight
= TITLE_HEIGHT
+ 3;
69 HBITMAP hTitleBitmap
= 0;
70 HBITMAP hDefaultTopicBitmap
= 0;
71 HBITMAP hTopicBitmap
[10];
72 HWND hwndTopicButton
[10];
76 HFONT hfontTopicButton
;
77 HFONT hfontTopicTitle
;
78 HFONT hfontTopicDescription
;
79 HFONT hfontCheckButton
;
93 MainWndProc (HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
96 /* FUNCTIONS ****************************************************************/
99 WinMain(HINSTANCE hInst
,
100 HINSTANCE hPrevInstance
,
113 DWORD dwStyle
= WS_OVERLAPPED
| WS_CLIPCHILDREN
| WS_CLIPSIBLINGS
|
114 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
;
120 hMainIcon
= LoadIcon (hInstance
, MAKEINTRESOURCE(IDI_MAIN
));
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
;
134 wndclass
.cbSize
= sizeof(WNDCLASSEX
);
135 wndclass
.hIconSm
= 0;
137 RegisterClassEx(&wndclass
);
139 hTitleBitmap
= LoadBitmap (hInstance
, MAKEINTRESOURCE(IDB_TITLEBITMAP
));
140 if (hTitleBitmap
!= NULL
)
142 GetObject(hTitleBitmap
, sizeof(BITMAP
), &BitmapInfo
);
143 ulInnerWidth
= BitmapInfo
.bmWidth
;
144 ulInnerHeight
= (ulInnerWidth
* 3) / 4;
145 ulTitleHeight
= BitmapInfo
.bmHeight
+ 3;
146 DeleteObject(hTitleBitmap
);
148 ulInnerHeight
-= GetSystemMetrics(SM_CYCAPTION
);
151 rcWindow
.bottom
= ulInnerHeight
- 1;
153 rcWindow
.right
= ulInnerWidth
- 1;
155 AdjustWindowRect(&rcWindow
,
158 xWidth
= rcWindow
.right
- rcWindow
.left
;
159 yHeight
= rcWindow
.bottom
- rcWindow
.top
;
161 xPos
= (GetSystemMetrics(SM_CXSCREEN
) - xWidth
) / 2;
162 yPos
= (GetSystemMetrics(SM_CYSCREEN
) - yHeight
) / 2;
164 rcTitlePanel
.top
= 0;
165 rcTitlePanel
.bottom
= ulTitleHeight
;
166 rcTitlePanel
.left
= 0;
167 rcTitlePanel
.right
= ulInnerWidth
- 1;
169 rcLeftPanel
.top
= rcTitlePanel
.bottom
;
170 rcLeftPanel
.bottom
= ulInnerHeight
- 1;
171 rcLeftPanel
.left
= 0;
172 rcLeftPanel
.right
= ulInnerWidth
/ 3;
174 rcRightPanel
.top
= rcLeftPanel
.top
;
175 rcRightPanel
.bottom
= rcLeftPanel
.bottom
;
176 rcRightPanel
.left
= rcLeftPanel
.right
;
177 rcRightPanel
.right
= ulInnerWidth
- 1;
179 if (!LoadString(hInstance
, (UINT
)MAKEINTRESOURCE(IDS_APPTITLE
), szAppTitle
, 80))
180 _tcscpy(szAppTitle
, TEXT("ReactOS Welcome"));
182 /* Create main window */
183 hwndMain
= CreateWindow(szFrameClass
,
195 hSystemMenu
= GetSystemMenu(hwndMain
, FALSE
);
198 RemoveMenu(hSystemMenu
, SC_SIZE
, MF_BYCOMMAND
);
199 RemoveMenu(hSystemMenu
, SC_MAXIMIZE
, MF_BYCOMMAND
);
202 ShowWindow(hwndMain
, nCmdShow
);
203 UpdateWindow(hwndMain
);
205 while (GetMessage(&msg
, NULL
, 0, 0) != FALSE
)
207 TranslateMessage(&msg
);
208 DispatchMessage(&msg
);
216 ButtonSubclassWndProc (HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
220 if (uMsg
== WM_MOUSEMOVE
)
222 i
= GetWindowLong(hWnd
, GWL_ID
);
227 InvalidateRect(hwndMain
, &rcRightPanel
, TRUE
);
231 return(CallWindowProc(fnOldBtn
, hWnd
, uMsg
, wParam
, lParam
));
236 RunApplication(int nTopic
)
238 PROCESS_INFORMATION ProcessInfo
;
239 STARTUPINFO StartupInfo
;
241 TCHAR CurrentDir
[256];
244 InvalidateRect(hwndMain
, NULL
, TRUE
);
246 GetCurrentDirectory(256, CurrentDir
);
248 nLength
= LoadString(hInstance
, IDS_TOPICACTION0
+ nTopic
, AppName
, 256);
252 if (!_tcsicmp(AppName
, TEXT("<exit>")))
255 if (_tcsicmp(AppName
, TEXT("explorer.exe")) == 0)
257 _tcscat(AppName
, TEXT(" "));
258 _tcscat(AppName
, CurrentDir
);
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
;
267 CreateProcess(NULL
, AppName
, NULL
, NULL
, FALSE
, CREATE_NEW_CONSOLE
,NULL
,
272 CloseHandle(ProcessInfo
.hProcess
);
273 CloseHandle(ProcessInfo
.hThread
);
280 SubclassButton(HWND hWnd
)
282 fnOldBtn
= (WNDPROC
)SetWindowLongPtr(hWnd
, GWL_WNDPROC
, (DWORD_PTR
)ButtonSubclassWndProc
);
287 GetButtonHeight(HDC hDC
,
296 rect
.right
= dwWidth
- 20;
300 hOldFont
= SelectObject(hDC
, hFont
);
301 DrawText(hDC
, szText
, -1, &rect
, DT_TOP
| DT_CALCRECT
| DT_WORDBREAK
);
302 SelectObject(hDC
, hOldFont
);
304 return(rect
.bottom
-rect
.top
+ 14);
309 OnCreate(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
317 hbrLightBlue
= CreateSolidBrush(LIGHT_BLUE
);
318 hbrDarkBlue
= CreateSolidBrush(DARK_BLUE
);
319 hbrRightPanel
= CreateSolidBrush(0x00FFFFFF);
321 /* Topic title font */
322 hfontTopicTitle
= CreateFont(-18,0,0,0,FW_NORMAL
,
323 FALSE
,FALSE
,FALSE
,ANSI_CHARSET
,
330 /* Topic description font */
331 hfontTopicDescription
= CreateFont(-11,0,0,0,FW_THIN
,
332 FALSE
,FALSE
,FALSE
,ANSI_CHARSET
,
339 /* Topic button font */
340 hfontTopicButton
= CreateFont(-11,0,0,0,FW_BOLD
,
341 FALSE
,FALSE
,FALSE
,ANSI_CHARSET
,
348 /* Load title bitmap */
349 if (hTitleBitmap
!= 0)
350 hTitleBitmap
= LoadBitmap (hInstance
, MAKEINTRESOURCE(IDB_TITLEBITMAP
));
352 /* Load topic bitmaps */
353 hDefaultTopicBitmap
= LoadBitmap (hInstance
, MAKEINTRESOURCE(IDB_DEFAULTTOPICBITMAP
));
354 for (i
=0;i
< 10; i
++)
356 hTopicBitmap
[i
] = LoadBitmap (hInstance
, MAKEINTRESOURCE(IDB_TOPICBITMAP0
+i
));
359 ScreenDC
= GetWindowDC(hWnd
);
360 hdcMem
= CreateCompatibleDC (ScreenDC
);
361 ReleaseDC(hWnd
, ScreenDC
);
363 /* load and create buttons */
364 dwTop
= rcLeftPanel
.top
;
365 for (i
= 0; i
< 10; i
++)
367 nLength
= LoadString(hInstance
, IDS_TOPICBUTTON0
+ i
, szText
, 80);
370 dwHeight
= GetButtonHeight(hdcMem
,
373 rcLeftPanel
.right
- rcLeftPanel
.left
);
375 hwndTopicButton
[i
] = CreateWindow(TEXT("BUTTON"),
377 WS_CHILDWINDOW
| WS_VISIBLE
| WS_TABSTOP
| BS_MULTILINE
| BS_OWNERDRAW
,
380 rcLeftPanel
.right
- rcLeftPanel
.left
,
386 hwndDefaultTopic
= hwndTopicButton
[i
];
388 SubclassButton(hwndTopicButton
[i
]);
389 SendMessage(hwndTopicButton
[i
], WM_SETFONT
, (WPARAM
)hfontTopicButton
, MAKELPARAM(TRUE
,0));
393 hwndTopicButton
[i
] = 0;
399 /* Create exit button */
400 nLength
= LoadString(hInstance
, IDS_CLOSETEXT
, szText
, 80);
403 hwndCloseButton
= CreateWindow(TEXT("BUTTON"),
405 WS_VISIBLE
| WS_CHILD
| BS_FLAT
,
406 rcRightPanel
.right
- 10 - 57,
407 rcRightPanel
.bottom
- 10 - 21,
411 (HMENU
)IDC_CLOSEBUTTON
,
414 hwndDefaultTopic
= 0;
416 SendMessage(hwndCloseButton
, WM_SETFONT
, (WPARAM
)hfontTopicButton
, MAKELPARAM(TRUE
,0));
423 /* Create checkbox */
424 nLength
= LoadString(hInstance
, IDS_CHECKTEXT
,szText
,80);
427 hfontCheckButton
= CreateFont(-10,0,0,0,FW_THIN
,FALSE
,FALSE
,FALSE
,ANSI_CHARSET
,
434 hwndCheckButton
= CreateWindow(TEXT("BUTTON"),
436 WS_VISIBLE
| WS_CHILD
| BS_AUTOCHECKBOX
,
437 rcLeftPanel
.left
+ 8,
438 rcLeftPanel
.bottom
- 8 - 13,
439 rcLeftPanel
.right
- rcLeftPanel
.left
- 16,
442 (HMENU
)IDC_CHECKBUTTON
,
445 SendMessage(hwndCheckButton
, WM_SETFONT
, (WPARAM
)hfontCheckButton
, MAKELPARAM(TRUE
,0));
450 hfontCheckButton
= 0;
458 OnCommand(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
460 if (LOWORD(wParam
) == IDC_CLOSEBUTTON
)
464 else if ((LOWORD(wParam
) < 10))
466 if (RunApplication(LOWORD(wParam
)) == FALSE
)
476 PaintBanner(HDC hdc
, LPRECT rcPanel
)
482 hOldBitmap
= SelectObject(hdcMem
, hTitleBitmap
);
486 rcPanel
->right
- rcPanel
->left
,
488 hdcMem
, 0, 0, SRCCOPY
);
489 SelectObject(hdcMem
, hOldBitmap
);
492 hOldBrush
= SelectObject(hdc
, hbrDarkBlue
);
496 rcPanel
->right
- rcPanel
->left
,
500 SelectObject(hdc
, hOldBrush
);
505 OnPaint(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
511 HBITMAP hOldBitmap
= 0;
514 RECT rcTitle
, rcDescription
;
515 TCHAR szTopicTitle
[80];
516 TCHAR szTopicDesc
[256];
521 hdc
= BeginPaint(hWnd
, &ps
);
524 PaintBanner(hdc
, &rcTitlePanel
);
527 hOldBrush
= SelectObject (hdc
, hbrLightBlue
);
531 rcLeftPanel
.right
- rcLeftPanel
.left
,
532 rcLeftPanel
.bottom
- rcLeftPanel
.top
,
534 SelectObject(hdc
, hOldBrush
);
537 hOldBrush
= SelectObject (hdc
, WHITE_BRUSH
);
541 rcRightPanel
.right
- rcRightPanel
.left
,
542 rcRightPanel
.bottom
- rcRightPanel
.top
,
544 SelectObject(hdc
, hOldBrush
);
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
);
554 /* Draw topic bitmap */
555 if ((nTopic
== -1) && (hDefaultTopicBitmap
!= 0))
557 GetObject(hDefaultTopicBitmap
, sizeof(BITMAP
), &bmpInfo
);
558 hOldBitmap
= SelectObject (hdcMem
, hDefaultTopicBitmap
);
560 rcRightPanel
.right
- bmpInfo
.bmWidth
,
561 rcRightPanel
.bottom
- bmpInfo
.bmHeight
,
569 else if (hTopicBitmap
[nTopic
] != 0)
571 GetObject(hTopicBitmap
[nTopic
], sizeof(BITMAP
), &bmpInfo
);
572 hOldBitmap
= SelectObject (hdcMem
, hTopicBitmap
[nTopic
]);
574 rcRightPanel
.right
- bmpInfo
.bmWidth
,
575 rcRightPanel
.bottom
- bmpInfo
.bmHeight
,
586 nLength
= LoadString(hInstance
, IDS_DEFAULTTOPICTITLE
, szTopicTitle
, 80);
590 nLength
= LoadString(hInstance
, IDS_TOPICTITLE0
+ nTopic
, szTopicTitle
, 80);
592 nLength
= LoadString(hInstance
, IDS_DEFAULTTOPICTITLE
, szTopicTitle
, 80);
597 nLength
= LoadString(hInstance
, IDS_DEFAULTTOPICDESC
, szTopicDesc
, 256);
601 nLength
= LoadString(hInstance
, IDS_TOPICDESC0
+ nTopic
, szTopicDesc
, 256);
603 nLength
= LoadString(hInstance
, IDS_DEFAULTTOPICDESC
, szTopicDesc
, 256);
606 SetBkMode(hdc
, TRANSPARENT
);
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
);
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
);
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
);
631 SetTextColor(hdc
, DARK_BLUE
);
632 DrawText(hdc
, szTopicTitle
, -1, &rcTitle
, DT_TOP
);
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;
640 SelectObject(hdc
, hfontTopicDescription
);
641 SetTextColor(hdc
, 0x00000000);
642 DrawText(hdc
, szTopicDesc
, -1, &rcDescription
, DT_TOP
| DT_WORDBREAK
);
644 SetBkMode(hdc
, OPAQUE
);
645 SelectObject(hdc
, hOldFont
);
647 SelectObject (hdcMem
, hOldBrush
);
648 SelectObject (hdcMem
, hOldBitmap
);
657 OnDrawItem(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
659 LPDRAWITEMSTRUCT lpDis
= (LPDRAWITEMSTRUCT
)lParam
;
665 if (lpDis
->hwndItem
== hwndCloseButton
)
667 DrawFrameControl(lpDis
->hDC
,
670 DFCS_BUTTONPUSH
| DFCS_FLAT
);
674 if (lpDis
->CtlID
== (ULONG
)nTopic
)
675 hOldBrush
= SelectObject(lpDis
->hDC
, hbrRightPanel
);
677 hOldBrush
= SelectObject(lpDis
->hDC
, hbrLightBlue
);
683 lpDis
->rcItem
.bottom
,
685 SelectObject(lpDis
->hDC
, hOldBrush
);
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
);
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
);
708 OnMouseMove(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
714 InvalidateRect(hwndMain
, &rcRightPanel
, TRUE
);
722 OnCtlColorStatic(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
724 if ((HWND
)lParam
== hwndCheckButton
)
726 SetBkColor((HDC
)wParam
, LIGHT_BLUE
);
727 return((LRESULT
)hbrLightBlue
);
735 OnActivate(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
738 InvalidateRect(hwndMain
, &rcRightPanel
, TRUE
);
745 OnDestroy(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
751 if (hwndTopicButton
[i
] != 0)
752 DestroyWindow(hwndTopicButton
[i
]);
755 if (hwndCloseButton
!= 0)
756 DestroyWindow(hwndCloseButton
);
758 if (hwndCheckButton
!= 0)
759 DestroyWindow(hwndCheckButton
);
764 DeleteObject(hDefaultTopicBitmap
);
765 DeleteObject(hTitleBitmap
);
768 if (hTopicBitmap
[i
] != 0)
769 DeleteObject(hTopicBitmap
[i
]);
772 DeleteObject(hfontTopicTitle
);
773 DeleteObject(hfontTopicDescription
);
774 DeleteObject(hfontTopicButton
);
776 if (hfontCheckButton
!= 0)
777 DeleteObject(hfontCheckButton
);
779 DeleteObject(hbrLightBlue
);
780 DeleteObject(hbrDarkBlue
);
781 DeleteObject(hbrRightPanel
);
788 MainWndProc(HWND hWnd
,
796 return(OnCreate(hWnd
, wParam
, lParam
));
799 return(OnCommand(hWnd
, wParam
, lParam
));
802 return(OnActivate(hWnd
, wParam
, lParam
));
805 return(OnPaint(hWnd
, wParam
, lParam
));
808 return(OnDrawItem(hWnd
, wParam
, lParam
));
810 case WM_CTLCOLORSTATIC
:
811 return(OnCtlColorStatic(hWnd
, wParam
, lParam
));
814 return(OnMouseMove(hWnd
, wParam
, lParam
));
817 OnDestroy(hWnd
, wParam
, lParam
);
822 return(DefWindowProc(hWnd
, uMsg
, wParam
, lParam
));