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.
19 /* $Id: welcome.c,v 1.6 2004/09/26 15:55:53 weiden Exp $
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;
147 ulInnerHeight
-= GetSystemMetrics(SM_CYCAPTION
);
150 rcWindow
.bottom
= ulInnerHeight
- 1;
152 rcWindow
.right
= ulInnerWidth
- 1;
154 AdjustWindowRect(&rcWindow
,
157 xWidth
= rcWindow
.right
- rcWindow
.left
;
158 yHeight
= rcWindow
.bottom
- rcWindow
.top
;
160 xPos
= (GetSystemMetrics(SM_CXSCREEN
) - xWidth
) / 2;
161 yPos
= (GetSystemMetrics(SM_CYSCREEN
) - yHeight
) / 2;
163 rcTitlePanel
.top
= 0;
164 rcTitlePanel
.bottom
= ulTitleHeight
;
165 rcTitlePanel
.left
= 0;
166 rcTitlePanel
.right
= ulInnerWidth
- 1;
168 rcLeftPanel
.top
= rcTitlePanel
.bottom
;
169 rcLeftPanel
.bottom
= ulInnerHeight
- 1;
170 rcLeftPanel
.left
= 0;
171 rcLeftPanel
.right
= ulInnerWidth
/ 3;
173 rcRightPanel
.top
= rcLeftPanel
.top
;
174 rcRightPanel
.bottom
= rcLeftPanel
.bottom
;
175 rcRightPanel
.left
= rcLeftPanel
.right
;
176 rcRightPanel
.right
= ulInnerWidth
- 1;
178 if (!LoadString(hInstance
, (UINT
)MAKEINTRESOURCE(IDS_APPTITLE
), szAppTitle
, 80))
179 lstrcpy(szAppTitle
, TEXT("ReactOS Welcome"));
181 /* Create main window */
182 hwndMain
= CreateWindow(szFrameClass
,
194 hSystemMenu
= GetSystemMenu(hwndMain
, FALSE
);
197 RemoveMenu(hSystemMenu
, SC_SIZE
, MF_BYCOMMAND
);
198 RemoveMenu(hSystemMenu
, SC_MAXIMIZE
, MF_BYCOMMAND
);
201 ShowWindow(hwndMain
, nCmdShow
);
202 UpdateWindow(hwndMain
);
204 while (GetMessage(&msg
, NULL
, 0, 0) != FALSE
)
206 TranslateMessage(&msg
);
207 DispatchMessage(&msg
);
215 ButtonSubclassWndProc (HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
219 if (uMsg
== WM_MOUSEMOVE
)
221 i
= GetWindowLong(hWnd
, GWL_ID
);
226 InvalidateRect(hwndMain
, &rcRightPanel
, TRUE
);
230 return(CallWindowProc(fnOldBtn
, hWnd
, uMsg
, wParam
, lParam
));
235 RunApplication(int nTopic
)
237 PROCESS_INFORMATION ProcessInfo
;
238 STARTUPINFO StartupInfo
;
240 TCHAR CurrentDir
[256];
243 InvalidateRect(hwndMain
, NULL
, TRUE
);
245 GetCurrentDirectory(256, CurrentDir
);
247 nLength
= LoadString(hInstance
, IDS_TOPICACTION0
+ nTopic
, AppName
, 256);
251 if (!lstrcmpi(AppName
, TEXT("<exit>")))
254 if (lstrcmpi(AppName
, TEXT("explorer.exe")) == 0)
256 lstrcat(AppName
, TEXT(" "));
257 lstrcat(AppName
, CurrentDir
);
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
;
266 CreateProcess(NULL
, AppName
, NULL
, NULL
, FALSE
, CREATE_NEW_CONSOLE
,NULL
,
271 CloseHandle(ProcessInfo
.hProcess
);
272 CloseHandle(ProcessInfo
.hThread
);
279 SubclassButton(HWND hWnd
)
281 fnOldBtn
= (WNDPROC
)SetWindowLongPtr(hWnd
, GWL_WNDPROC
, (DWORD_PTR
)ButtonSubclassWndProc
);
286 GetButtonHeight(HDC hDC
,
295 rect
.right
= dwWidth
- 20;
299 hOldFont
= SelectObject(hDC
, hFont
);
300 DrawText(hDC
, szText
, -1, &rect
, DT_TOP
| DT_CALCRECT
| DT_WORDBREAK
);
301 SelectObject(hDC
, hOldFont
);
303 return(rect
.bottom
-rect
.top
+ 14);
308 OnCreate(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
316 hbrLightBlue
= CreateSolidBrush(LIGHT_BLUE
);
317 hbrDarkBlue
= CreateSolidBrush(DARK_BLUE
);
318 hbrRightPanel
= CreateSolidBrush(0x00FFFFFF);
320 /* Topic title font */
321 hfontTopicTitle
= CreateFont(-18,0,0,0,FW_NORMAL
,
322 FALSE
,FALSE
,FALSE
,ANSI_CHARSET
,
329 /* Topic description font */
330 hfontTopicDescription
= CreateFont(-11,0,0,0,FW_THIN
,
331 FALSE
,FALSE
,FALSE
,ANSI_CHARSET
,
338 /* Topic button font */
339 hfontTopicButton
= CreateFont(-11,0,0,0,FW_BOLD
,
340 FALSE
,FALSE
,FALSE
,ANSI_CHARSET
,
347 /* Load title bitmap */
348 if (hTitleBitmap
!= 0)
349 hTitleBitmap
= LoadBitmap (hInstance
, MAKEINTRESOURCE(IDB_TITLEBITMAP
));
351 /* Load topic bitmaps */
352 hDefaultTopicBitmap
= LoadBitmap (hInstance
, MAKEINTRESOURCE(IDB_DEFAULTTOPICBITMAP
));
353 for (i
=0;i
< 10; i
++)
355 hTopicBitmap
[i
] = LoadBitmap (hInstance
, MAKEINTRESOURCE(IDB_TOPICBITMAP0
+i
));
358 ScreenDC
= GetWindowDC(hWnd
);
359 hdcMem
= CreateCompatibleDC (ScreenDC
);
360 ReleaseDC(hWnd
, ScreenDC
);
362 /* load and create buttons */
363 dwTop
= rcLeftPanel
.top
;
364 for (i
= 0; i
< 10; i
++)
366 nLength
= LoadString(hInstance
, IDS_TOPICBUTTON0
+ i
, szText
, 80);
369 dwHeight
= GetButtonHeight(hdcMem
,
372 rcLeftPanel
.right
- rcLeftPanel
.left
);
374 hwndTopicButton
[i
] = CreateWindow(TEXT("BUTTON"),
376 WS_CHILDWINDOW
| WS_VISIBLE
| WS_TABSTOP
| BS_MULTILINE
| BS_OWNERDRAW
,
379 rcLeftPanel
.right
- rcLeftPanel
.left
,
385 hwndDefaultTopic
= hwndTopicButton
[i
];
387 SubclassButton(hwndTopicButton
[i
]);
388 SendMessage(hwndTopicButton
[i
], WM_SETFONT
, (WPARAM
)hfontTopicButton
, MAKELPARAM(TRUE
,0));
392 hwndTopicButton
[i
] = 0;
398 /* Create exit button */
399 nLength
= LoadString(hInstance
, IDS_CLOSETEXT
, szText
, 80);
402 hwndCloseButton
= CreateWindow(TEXT("BUTTON"),
404 WS_VISIBLE
| WS_CHILD
| BS_FLAT
,
405 rcRightPanel
.right
- 10 - 57,
406 rcRightPanel
.bottom
- 10 - 21,
410 (HMENU
)IDC_CLOSEBUTTON
,
413 hwndDefaultTopic
= 0;
415 SendMessage(hwndCloseButton
, WM_SETFONT
, (WPARAM
)hfontTopicButton
, MAKELPARAM(TRUE
,0));
422 /* Create checkbox */
423 nLength
= LoadString(hInstance
, IDS_CHECKTEXT
,szText
,80);
426 hfontCheckButton
= CreateFont(-10,0,0,0,FW_THIN
,FALSE
,FALSE
,FALSE
,ANSI_CHARSET
,
433 hwndCheckButton
= CreateWindow(TEXT("BUTTON"),
435 WS_VISIBLE
| WS_CHILD
| BS_AUTOCHECKBOX
,
436 rcLeftPanel
.left
+ 8,
437 rcLeftPanel
.bottom
- 8 - 13,
438 rcLeftPanel
.right
- rcLeftPanel
.left
- 16,
441 (HMENU
)IDC_CHECKBUTTON
,
444 SendMessage(hwndCheckButton
, WM_SETFONT
, (WPARAM
)hfontCheckButton
, MAKELPARAM(TRUE
,0));
449 hfontCheckButton
= 0;
457 OnCommand(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
459 if (LOWORD(wParam
) == IDC_CLOSEBUTTON
)
463 else if ((LOWORD(wParam
) < 10))
465 if (RunApplication(LOWORD(wParam
)) == FALSE
)
475 PaintBanner(HDC hdc
, LPRECT rcPanel
)
481 hOldBitmap
= SelectObject(hdcMem
, hTitleBitmap
);
485 rcPanel
->right
- rcPanel
->left
,
487 hdcMem
, 0, 0, SRCCOPY
);
488 SelectObject(hdc
, hOldBitmap
);
491 hOldBrush
= SelectObject(hdc
, hbrDarkBlue
);
495 rcPanel
->right
- rcPanel
->left
,
499 SelectObject(hdc
, hOldBrush
);
504 OnPaint(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
510 HBITMAP hOldBitmap
= 0;
513 RECT rcTitle
, rcDescription
;
514 TCHAR szTopicTitle
[80];
515 TCHAR szTopicDesc
[256];
520 hdc
= BeginPaint(hWnd
, &ps
);
523 PaintBanner(hdc
, &rcTitlePanel
);
526 hOldBrush
= SelectObject (hdc
, hbrLightBlue
);
530 rcLeftPanel
.right
- rcLeftPanel
.left
,
531 rcLeftPanel
.bottom
- rcLeftPanel
.top
,
533 SelectObject(hdc
, hOldBrush
);
536 hOldBrush
= SelectObject (hdc
, WHITE_BRUSH
);
540 rcRightPanel
.right
- rcRightPanel
.left
,
541 rcRightPanel
.bottom
- rcRightPanel
.top
,
543 SelectObject(hdc
, hOldBrush
);
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
);
553 /* Draw topic bitmap */
554 if ((nTopic
== -1) && (hDefaultTopicBitmap
!= 0))
556 GetObject(hDefaultTopicBitmap
, sizeof(BITMAP
), &bmpInfo
);
557 hOldBitmap
= SelectObject (hdcMem
, hDefaultTopicBitmap
);
559 rcRightPanel
.right
- bmpInfo
.bmWidth
,
560 rcRightPanel
.bottom
- bmpInfo
.bmHeight
,
568 else if (hTopicBitmap
[nTopic
] != 0)
570 GetObject(hTopicBitmap
[nTopic
], sizeof(BITMAP
), &bmpInfo
);
571 hOldBitmap
= SelectObject (hdcMem
, hTopicBitmap
[nTopic
]);
573 rcRightPanel
.right
- bmpInfo
.bmWidth
,
574 rcRightPanel
.bottom
- bmpInfo
.bmHeight
,
585 nLength
= LoadString(hInstance
, IDS_DEFAULTTOPICTITLE
, szTopicTitle
, 80);
589 nLength
= LoadString(hInstance
, IDS_TOPICTITLE0
+ nTopic
, szTopicTitle
, 80);
591 nLength
= LoadString(hInstance
, IDS_DEFAULTTOPICTITLE
, szTopicTitle
, 80);
596 nLength
= LoadString(hInstance
, IDS_DEFAULTTOPICDESC
, szTopicDesc
, 256);
600 nLength
= LoadString(hInstance
, IDS_TOPICDESC0
+ nTopic
, szTopicDesc
, 256);
602 nLength
= LoadString(hInstance
, IDS_DEFAULTTOPICDESC
, szTopicDesc
, 256);
605 SetBkMode(hdc
, TRANSPARENT
);
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
);
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
);
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
);
630 SetTextColor(hdc
, DARK_BLUE
);
631 DrawText(hdc
, szTopicTitle
, -1, &rcTitle
, DT_TOP
);
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;
639 SelectObject(hdc
, hfontTopicDescription
);
640 SetTextColor(hdc
, 0x00000000);
641 DrawText(hdc
, szTopicDesc
, -1, &rcDescription
, DT_TOP
| DT_WORDBREAK
);
643 SetBkMode(hdc
, OPAQUE
);
644 SelectObject(hdc
, hOldFont
);
646 SelectObject (hdcMem
, hOldBrush
);
647 SelectObject (hdcMem
, hOldBitmap
);
656 OnDrawItem(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
658 LPDRAWITEMSTRUCT lpDis
= (LPDRAWITEMSTRUCT
)lParam
;
664 if (lpDis
->hwndItem
== hwndCloseButton
)
666 DrawFrameControl(lpDis
->hDC
,
669 DFCS_BUTTONPUSH
| DFCS_FLAT
);
673 if (lpDis
->CtlID
== (ULONG
)nTopic
)
674 hOldBrush
= SelectObject(lpDis
->hDC
, hbrRightPanel
);
676 hOldBrush
= SelectObject(lpDis
->hDC
, hbrLightBlue
);
682 lpDis
->rcItem
.bottom
,
684 SelectObject(lpDis
->hDC
, hOldBrush
);
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
);
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
);
707 OnMouseMove(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
713 InvalidateRect(hwndMain
, &rcRightPanel
, TRUE
);
721 OnCtlColorStatic(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
723 if ((HWND
)lParam
== hwndCheckButton
)
725 SetBkColor((HDC
)wParam
, LIGHT_BLUE
);
726 return((LRESULT
)hbrLightBlue
);
734 OnActivate(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
737 InvalidateRect(hwndMain
, &rcRightPanel
, TRUE
);
744 OnDestroy(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
750 if (hwndTopicButton
[i
] != 0)
751 DestroyWindow(hwndTopicButton
[i
]);
754 if (hwndCloseButton
!= 0)
755 DestroyWindow(hwndCloseButton
);
757 if (hwndCheckButton
!= 0)
758 DestroyWindow(hwndCheckButton
);
763 DeleteObject(hDefaultTopicBitmap
);
764 DeleteObject(hTitleBitmap
);
767 if (hTopicBitmap
[i
] != 0)
768 DeleteObject(hTopicBitmap
[i
]);
771 DeleteObject(hfontTopicTitle
);
772 DeleteObject(hfontTopicDescription
);
773 DeleteObject(hfontTopicButton
);
775 if (hfontCheckButton
!= 0)
776 DeleteObject(hfontCheckButton
);
778 DeleteObject(hbrLightBlue
);
779 DeleteObject(hbrDarkBlue
);
780 DeleteObject(hbrRightPanel
);
787 MainWndProc(HWND hWnd
,
795 return(OnCreate(hWnd
, wParam
, lParam
));
798 return(OnCommand(hWnd
, wParam
, lParam
));
801 return(OnActivate(hWnd
, wParam
, lParam
));
804 return(OnPaint(hWnd
, wParam
, lParam
));
807 return(OnDrawItem(hWnd
, wParam
, lParam
));
809 case WM_CTLCOLORSTATIC
:
810 return(OnCtlColorStatic(hWnd
, wParam
, lParam
));
813 return(OnMouseMove(hWnd
, wParam
, lParam
));
816 OnDestroy(hWnd
, wParam
, lParam
);
821 return(DefWindowProc(hWnd
, uMsg
, wParam
, lParam
));