3 * Copyright (C) 2001, 2002 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: welcome/welcome.c
24 * PROGRAMMERS: Eric Kohl (ekohl@rz-online.de)
35 #define LIGHT_BLUE 0x00F0CAA6
36 #define DARK_BLUE 0x00996633
40 /* GLOBALS ******************************************************************/
42 TCHAR szFrameClass
[] = "WelcomeWindowClass";
43 TCHAR szAppTitle
[80];
48 HWND hwndDefaultTopic
= 0;
50 HBITMAP hTitleBitmap
= 0;
55 int nDefaultTopic
= -1;
57 ULONG ulInnerWidth
= 480;
58 ULONG ulInnerHeight
= 360;
60 HBITMAP hDefaultTopicBitmap
;
61 HBITMAP hTopicBitmap
[10];
62 HWND hwndTopicButton
[10];
67 HFONT hfontTopicButton
;
68 HFONT hfontTopicTitle
;
69 HFONT hfontTopicDescription
;
70 HFONT hfontCheckButton
;
72 HFONT hfontBannerTitle
;
86 MainWndProc (HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
89 /* FUNCTIONS ****************************************************************/
92 WinMain(HINSTANCE hInst
,
93 HINSTANCE hPrevInstance
,
104 DWORD dwStyle
= WS_OVERLAPPED
| WS_CLIPCHILDREN
| WS_CLIPSIBLINGS
| WS_CAPTION
| WS_SYSMENU
| WS_VISIBLE
;
108 /* Register the window class */
109 wndclass
.style
= CS_OWNDC
;
110 wndclass
.lpfnWndProc
= (WNDPROC
)MainWndProc
;
111 wndclass
.cbClsExtra
= 0;
112 wndclass
.cbWndExtra
= 0;
113 wndclass
.hInstance
= hInstance
;
115 wndclass
.hCursor
= LoadCursor (NULL
, IDC_ARROW
);
116 wndclass
.hbrBackground
= 0;
117 wndclass
.lpszMenuName
= NULL
;
118 wndclass
.lpszClassName
= szFrameClass
;
120 wndclass
.cbSize
= sizeof(WNDCLASSEX
);
121 wndclass
.hIconSm
= 0;
123 RegisterClassEx(&wndclass
);
126 rcWindow
.bottom
= ulInnerHeight
- 1;
128 rcWindow
.right
= ulInnerWidth
- 1;
130 AdjustWindowRect(&rcWindow
,
133 xWidth
= rcWindow
.right
- rcWindow
.left
;
134 yHeight
= rcWindow
.bottom
- rcWindow
.top
;
136 xPos
= (GetSystemMetrics(SM_CXSCREEN
) - xWidth
) / 2;
137 yPos
= (GetSystemMetrics(SM_CYSCREEN
) - yHeight
) / 2;
139 rcTitlePanel
.top
= 0;
140 rcTitlePanel
.bottom
= 93;
141 rcTitlePanel
.left
= 0;
142 rcTitlePanel
.right
= ulInnerWidth
- 1;
144 rcLeftPanel
.top
= rcTitlePanel
.bottom
;
145 rcLeftPanel
.bottom
= ulInnerHeight
- 1;
146 rcLeftPanel
.left
= 0;
147 rcLeftPanel
.right
= ulInnerWidth
/ 3;
149 rcRightPanel
.top
= rcLeftPanel
.top
;
150 rcRightPanel
.bottom
= rcLeftPanel
.bottom
;
151 rcRightPanel
.left
= rcLeftPanel
.right
;
152 rcRightPanel
.right
= ulInnerWidth
- 1;
154 if (!LoadString(hInstance
, (UINT
)MAKEINTRESOURCE(IDS_APPTITLE
), szAppTitle
, 80))
155 _tcscpy(szAppTitle
, TEXT("ReactOS Welcome"));
157 /* Create main window */
158 hwndMain
= CreateWindow(szFrameClass
,
170 ShowWindow(hwndMain
, nCmdShow
);
171 UpdateWindow(hwndMain
);
173 while (GetMessage(&msg
, NULL
, 0, 0) != FALSE
)
175 TranslateMessage(&msg
);
176 DispatchMessage(&msg
);
184 ButtonSubclassWndProc (HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
188 if (uMsg
== WM_MOUSEMOVE
)
190 i
= GetWindowLong(hWnd
, GWL_ID
);
195 InvalidateRect(hwndMain
, NULL
, TRUE
);
199 return(CallWindowProc(fnOldBtn
, hWnd
, uMsg
, wParam
, lParam
));
204 RunApplication(int nTopic
)
206 PROCESS_INFORMATION ProcessInfo
;
207 STARTUPINFO StartupInfo
;
209 CHAR CurrentDir
[256];
212 InvalidateRect(hwndMain
, NULL
, TRUE
);
214 GetCurrentDirectory(256, CurrentDir
);
216 nLength
= LoadString(hInstance
, IDS_TOPICACTION0
+ nTopic
, AppName
, 256);
220 if (stricmp(AppName
, "explorer.exe") == 0)
222 strcat(AppName
, " ");
223 strcat(AppName
, CurrentDir
);
226 memset(&StartupInfo
, 0, sizeof(STARTUPINFO
));
227 StartupInfo
.cb
= sizeof(STARTUPINFO
);
228 StartupInfo
.lpTitle
= "Test";
229 StartupInfo
.dwFlags
= STARTF_USESHOWWINDOW
;
230 StartupInfo
.wShowWindow
= SW_SHOWNORMAL
;
232 CreateProcess(NULL
, AppName
, NULL
, NULL
, FALSE
, CREATE_NEW_CONSOLE
,NULL
,
237 CloseHandle(ProcessInfo
.hProcess
);
238 CloseHandle(ProcessInfo
.hThread
);
244 SubclassButton(HWND hWnd
)
246 fnOldBtn
= (WNDPROC
)SetWindowLong(hWnd
, GWL_WNDPROC
, (LPARAM
)ButtonSubclassWndProc
);
251 GetButtonHeight(HDC hDC
,
260 rect
.right
= dwWidth
- 20;
264 hOldFont
= SelectObject(hDC
, hFont
);
265 DrawText(hDC
, szText
, -1, &rect
, DT_TOP
| DT_CALCRECT
| DT_WORDBREAK
);
266 SelectObject(hDC
, hOldFont
);
268 return(rect
.bottom
-rect
.top
+ 14);
273 OnCreate(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
280 hbrLightBlue
= CreateSolidBrush (LIGHT_BLUE
);
281 hbrDarkBlue
= CreateSolidBrush(DARK_BLUE
);
282 hbrRightPanel
= CreateSolidBrush (0x00FFFFFF);
285 hfontBannerTitle
= CreateFont(-30,0,0,0,FW_BOLD
,
286 FALSE
,FALSE
,FALSE
,ANSI_CHARSET
,
293 hfontTopicTitle
= CreateFont(-18,0,0,0,FW_NORMAL
,
294 FALSE
,FALSE
,FALSE
,ANSI_CHARSET
,
302 hfontTopicDescription
= CreateFont(-11,0,0,0,FW_THIN
,
303 FALSE
,FALSE
,FALSE
,ANSI_CHARSET
,
310 hfontTopicButton
= CreateFont(-11,0,0,0,FW_BOLD
,
311 FALSE
,FALSE
,FALSE
,ANSI_CHARSET
,
319 hTitleBitmap
= LoadBitmap (hInstance
, MAKEINTRESOURCE(IDB_TITLEBITMAP
));
320 hDefaultTopicBitmap
= LoadBitmap (hInstance
, MAKEINTRESOURCE(IDB_DEFAULTTOPICBITMAP
));
321 for (i
=0;i
< 10; i
++)
323 hTopicBitmap
[i
] = LoadBitmap (hInstance
, MAKEINTRESOURCE(IDB_TOPICBITMAP0
+i
));
326 hdcDisplay
= CreateDC ("DISPLAY", NULL
, NULL
, NULL
);
327 hdcMem
= CreateCompatibleDC (hdcDisplay
);
329 /* load and create buttons */
330 dwTop
= rcLeftPanel
.top
;
331 for (i
=0;i
< 10; i
++)
333 nLength
= LoadString(hInstance
, IDS_TOPICBUTTON0
+i
,szText
,80);
336 dwHeight
= GetButtonHeight(hdcMem
,
339 rcLeftPanel
.right
- rcLeftPanel
.left
);
341 hwndTopicButton
[i
] = CreateWindow("BUTTON",
343 WS_CHILDWINDOW
| WS_VISIBLE
| WS_TABSTOP
| BS_MULTILINE
| BS_OWNERDRAW
,
346 rcLeftPanel
.right
- rcLeftPanel
.left
,
352 hwndDefaultTopic
= hwndTopicButton
[i
];
354 SubclassButton(hwndTopicButton
[i
]);
355 SendMessage(hwndTopicButton
[i
], WM_SETFONT
, (WPARAM
)hfontTopicButton
, MAKELPARAM(TRUE
,0));
359 hwndTopicButton
[i
] = 0;
365 /* Create exit button */
366 nLength
= LoadString(hInstance
, IDS_CLOSETEXT
, szText
, 80);
369 hwndCloseButton
= CreateWindow("BUTTON",
371 WS_VISIBLE
| WS_CHILD
| BS_FLAT
,
372 rcRightPanel
.right
- 10 - 57,
373 rcRightPanel
.bottom
- 10 - 21,
377 (HMENU
)IDC_CLOSEBUTTON
,
380 hwndDefaultTopic
= 0;
382 SendMessage(hwndCloseButton
, WM_SETFONT
, (WPARAM
)hfontTopicButton
, MAKELPARAM(TRUE
,0));
389 /* Create checkbox */
390 nLength
= LoadString(hInstance
, IDS_CHECKTEXT
,szText
,80);
393 hfontCheckButton
= CreateFont(-10,0,0,0,FW_THIN
,FALSE
,FALSE
,FALSE
,ANSI_CHARSET
,
400 hwndCheckButton
= CreateWindow("BUTTON",
402 WS_VISIBLE
| WS_CHILD
| BS_AUTOCHECKBOX
,
403 rcLeftPanel
.left
+ 8,
404 rcLeftPanel
.bottom
- 8 - 13,
405 rcLeftPanel
.right
- rcLeftPanel
.left
- 16,
408 (HMENU
)IDC_CHECKBUTTON
,
411 SendMessage(hwndCheckButton
, WM_SETFONT
, (WPARAM
)hfontCheckButton
, MAKELPARAM(TRUE
,0));
416 hfontCheckButton
= 0;
424 OnCommand(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
426 if (LOWORD(wParam
) == IDC_CLOSEBUTTON
)
430 else if ((LOWORD(wParam
) < 10))
432 if (RunApplication(LOWORD(wParam
)) == FALSE
)
442 PaintBanner(HDC hdc
, LPRECT rcPanel
)
450 hOldBitmap
= SelectObject(hdcMem
, hTitleBitmap
);
456 hdcMem
, 0, 0, SRCCOPY
);
457 SelectObject(hdc
, hOldBitmap
);
460 /* white background */
461 hOldBrush
= SelectObject(hdc
, hbrRightPanel
);
465 rcPanel
->right
- rcPanel
->left
,
469 hOldFont
= SelectObject (hdc
, hfontBannerTitle
);
470 SetTextColor(hdc
, 0x00000000);
474 DrawText(hdc
, "ReactOS 0.0.20", -1,
475 &rcTitle
, DT_TOP
| DT_CALCRECT
);
477 DrawText(hdc
, "ReactOS 0.0.20", -1,
480 SelectObject(hdc
, hOldFont
);
483 hOldBrush
= SelectObject(hdc
, hbrDarkBlue
);
487 rcPanel
->right
- rcPanel
->left
,
491 SelectObject(hdc
, hOldBrush
);
496 OnPaint(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
500 HBITMAP hOldBitmap
= 0;
503 RECT rcTitle
, rcDescription
;
504 TCHAR szTopicTitle
[80];
505 TCHAR szTopicDesc
[256];
509 hdc
= BeginPaint(hWnd
, &ps
);
512 PaintBanner(hdc
, &rcTitlePanel
);
515 hOldBrush
= SelectObject (hdc
, hbrLightBlue
);
519 rcLeftPanel
.right
- rcLeftPanel
.left
,
520 rcLeftPanel
.bottom
- rcLeftPanel
.top
,
524 SelectObject (hdc
, hbrRightPanel
);
528 rcRightPanel
.right
- rcRightPanel
.left
,
529 rcRightPanel
.bottom
- rcRightPanel
.top
,
532 /* Draw topic bitmap */
533 if ((nTopic
== -1) && (hDefaultTopicBitmap
!= 0))
535 GetObject(hDefaultTopicBitmap
, sizeof(BITMAP
), &bmpInfo
);
536 hOldBitmap
= SelectObject (hdcMem
, hDefaultTopicBitmap
);
538 rcRightPanel
.right
- bmpInfo
.bmWidth
,
539 rcRightPanel
.bottom
- bmpInfo
.bmHeight
,
547 else if (hTopicBitmap
[nTopic
] != 0)
549 GetObject(hTopicBitmap
[nTopic
], sizeof(BITMAP
), &bmpInfo
);
550 hOldBitmap
= SelectObject (hdcMem
, hTopicBitmap
[nTopic
]);
552 rcRightPanel
.right
- bmpInfo
.bmWidth
,
553 rcRightPanel
.bottom
- bmpInfo
.bmHeight
,
564 nLength
= LoadString(hInstance
, IDS_DEFAULTTOPICTITLE
, szTopicTitle
, 80);
568 nLength
= LoadString(hInstance
, IDS_TOPICTITLE0
+ nTopic
, szTopicTitle
, 80);
570 nLength
= LoadString(hInstance
, IDS_DEFAULTTOPICTITLE
, szTopicTitle
, 80);
575 nLength
= LoadString(hInstance
, IDS_DEFAULTTOPICDESC
, szTopicDesc
, 256);
579 nLength
= LoadString(hInstance
, IDS_TOPICDESC0
+ nTopic
, szTopicDesc
, 256);
581 nLength
= LoadString(hInstance
, IDS_DEFAULTTOPICDESC
, szTopicDesc
, 256);
584 SetBkMode(hdc
, TRANSPARENT
);
586 /* Draw topic title */
587 rcTitle
.left
= rcRightPanel
.left
+ 12;
588 rcTitle
.right
= rcRightPanel
.right
- 8;
589 rcTitle
.top
= rcRightPanel
.top
+ 8;
590 rcTitle
.bottom
= rcTitle
.top
+ 57;
591 hOldFont
= SelectObject(hdc
, hfontTopicTitle
);
592 DrawText(hdc
, szTopicTitle
, -1, &rcTitle
, DT_TOP
| DT_CALCRECT
);
594 SetTextColor(hdc
, DARK_BLUE
);
595 DrawText(hdc
, szTopicTitle
, -1, &rcTitle
, DT_TOP
);
597 /* Draw topic description */
598 rcDescription
.left
= rcRightPanel
.left
+ 12;
599 rcDescription
.right
= rcRightPanel
.right
- 8;
600 rcDescription
.top
= rcTitle
.bottom
+ 8;
601 rcDescription
.bottom
= rcRightPanel
.bottom
- 20;
603 SelectObject(hdc
, hfontTopicDescription
);
604 SetTextColor(hdc
, 0x00000000);
605 DrawText(hdc
, szTopicDesc
, -1, &rcDescription
, DT_TOP
| DT_WORDBREAK
);
607 SetBkMode(hdc
, OPAQUE
);
608 SelectObject(hdc
, hOldFont
);
610 SelectObject (hdcMem
, hOldBrush
);
611 SelectObject (hdcMem
, hOldBitmap
);
619 OnDrawItem(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
621 LPDRAWITEMSTRUCT lpDis
= (LPDRAWITEMSTRUCT
)lParam
;
627 if (lpDis
->hwndItem
== hwndCloseButton
)
629 DrawFrameControl(lpDis
->hDC
,
632 DFCS_BUTTONPUSH
| DFCS_FLAT
);
636 if (lpDis
->CtlID
== (ULONG
)nTopic
)
637 hOldBrush
= SelectObject(lpDis
->hDC
, hbrRightPanel
);
639 hOldBrush
= SelectObject(lpDis
->hDC
, hbrLightBlue
);
644 lpDis
->rcItem
.bottom
,
646 SelectObject(lpDis
->hDC
, hOldBrush
);
648 hPen
= CreatePen(PS_SOLID
, 0, DARK_BLUE
);
649 hOldPen
= SelectObject(lpDis
->hDC
, hPen
);
650 MoveToEx(lpDis
->hDC
, lpDis
->rcItem
.left
, lpDis
->rcItem
.bottom
-1, NULL
);
651 LineTo(lpDis
->hDC
, lpDis
->rcItem
.right
, lpDis
->rcItem
.bottom
-1);
652 SelectObject(lpDis
->hDC
, hOldPen
);
655 InflateRect(&lpDis
->rcItem
, -10, -4);
656 OffsetRect(&lpDis
->rcItem
, 0, 1);
657 GetWindowText(lpDis
->hwndItem
, szText
, 80);
658 SetTextColor(lpDis
->hDC
, 0x00000000);
659 iBkMode
= SetBkMode(lpDis
->hDC
, TRANSPARENT
);
660 DrawText(lpDis
->hDC
, szText
, -1, &lpDis
->rcItem
, DT_TOP
| DT_LEFT
| DT_WORDBREAK
);
661 SetBkMode(lpDis
->hDC
, iBkMode
);
669 OnMouseMove(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
675 InvalidateRect(hwndMain
, NULL
, TRUE
);
683 OnCtlColorStatic(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
685 if ((HWND
)lParam
== hwndCheckButton
)
687 SetBkColor((HDC
)wParam
, LIGHT_BLUE
);
688 return((LRESULT
)hbrLightBlue
);
696 OnActivate(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
699 InvalidateRect(hwndMain
, NULL
, TRUE
);
706 OnDestroy(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
712 if (hwndTopicButton
[i
] != 0)
713 DestroyWindow(hwndTopicButton
[i
]);
716 if (hwndCloseButton
!= 0)
717 DestroyWindow(hwndCloseButton
);
719 if (hwndCheckButton
!= 0)
720 DestroyWindow(hwndCheckButton
);
723 DeleteDC(hdcDisplay
);
726 DeleteObject(hDefaultTopicBitmap
);
727 DeleteObject(hTitleBitmap
);
730 if (hTopicBitmap
[i
] != 0)
731 DeleteObject(hTopicBitmap
[i
]);
734 DeleteObject(hfontTopicTitle
);
735 DeleteObject(hfontTopicDescription
);
736 DeleteObject(hfontTopicButton
);
738 DeleteObject(hfontBannerTitle
);
741 if (hfontCheckButton
!= 0)
742 DeleteObject(hfontCheckButton
);
744 DeleteObject(hbrLightBlue
);
745 DeleteObject(hbrDarkBlue
);
746 DeleteObject(hbrRightPanel
);
753 MainWndProc(HWND hWnd
,
761 return(OnCreate(hWnd
, wParam
, lParam
));
764 return(OnCommand(hWnd
, wParam
, lParam
));
767 return(OnActivate(hWnd
, wParam
, lParam
));
770 return(OnPaint(hWnd
, wParam
, lParam
));
773 return(OnDrawItem(hWnd
, wParam
, lParam
));
775 case WM_CTLCOLORSTATIC
:
776 return(OnCtlColorStatic(hWnd
, wParam
, lParam
));
779 return(OnMouseMove(hWnd
, wParam
, lParam
));
782 OnDestroy(hWnd
, wParam
, lParam
);
787 return(DefWindowProc(hWnd
, uMsg
, wParam
, lParam
));