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: subsys/system/welcome/welcome.c
24 * PROGRAMMERS: Eric Kohl (ekohl@rz-online.de)
25 * Casper S. Hornstrup (chorns@users.sourceforge.net)
27 #include "../../../include/reactos/version.h"
37 #define LIGHT_BLUE 0x00F0CAA6
38 #define DARK_BLUE 0x00996633
42 /* GLOBALS ******************************************************************/
44 TCHAR szFrameClass [] = "WelcomeWindowClass";
45 TCHAR szAppTitle [80];
50 HWND hwndDefaultTopic = 0;
52 HBITMAP hTitleBitmap = 0;
53 HBITMAP hTopBackgroundBitmap = 0;
54 HBITMAP hRightBackgroundBitmap = 0;
59 int nDefaultTopic = -1;
61 ULONG ulInnerWidth = 480;
62 ULONG ulInnerHeight = 360;
64 HBITMAP hDefaultTopicBitmap;
65 HBITMAP hTopicBitmap[10];
66 HWND hwndTopicButton[10];
70 HFONT hfontTopicButton;
71 HFONT hfontTopicTitle;
72 HFONT hfontTopicDescription;
73 HFONT hfontCheckButton;
75 HFONT hfontBannerTitle;
89 MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
92 /* FUNCTIONS ****************************************************************/
95 WinMain(HINSTANCE hInst,
96 HINSTANCE hPrevInstance,
108 DWORD dwStyle = WS_OVERLAPPED | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_CAPTION | WS_SYSMENU | WS_VISIBLE;
113 hMainIcon = LoadIcon (hInstance, MAKEINTRESOURCE(IDI_MAIN));
115 /* Register the window class */
116 wndclass.style = CS_OWNDC;
117 wndclass.lpfnWndProc = (WNDPROC)MainWndProc;
118 wndclass.cbClsExtra = 0;
119 wndclass.cbWndExtra = 0;
120 wndclass.hInstance = hInstance;
121 wndclass.hIcon = hMainIcon;
122 wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
123 wndclass.hbrBackground = 0;
124 wndclass.lpszMenuName = NULL;
125 wndclass.lpszClassName = szFrameClass;
127 wndclass.cbSize = sizeof(WNDCLASSEX);
128 wndclass.hIconSm = 0;
130 RegisterClassEx(&wndclass);
133 rcWindow.bottom = ulInnerHeight - 1;
135 rcWindow.right = ulInnerWidth - 1;
137 AdjustWindowRect(&rcWindow,
140 xWidth = rcWindow.right - rcWindow.left;
141 yHeight = rcWindow.bottom - rcWindow.top;
143 xPos = (GetSystemMetrics(SM_CXSCREEN) - xWidth) / 2;
144 yPos = (GetSystemMetrics(SM_CYSCREEN) - yHeight) / 2;
146 rcTitlePanel.top = 0;
147 rcTitlePanel.bottom = 93;
148 rcTitlePanel.left = 0;
149 rcTitlePanel.right = ulInnerWidth - 1;
151 rcLeftPanel.top = rcTitlePanel.bottom;
152 rcLeftPanel.bottom = ulInnerHeight - 1;
153 rcLeftPanel.left = 0;
154 rcLeftPanel.right = ulInnerWidth / 3;
156 rcRightPanel.top = rcLeftPanel.top;
157 rcRightPanel.bottom = rcLeftPanel.bottom;
158 rcRightPanel.left = rcLeftPanel.right;
159 rcRightPanel.right = ulInnerWidth - 1;
161 if (!LoadString(hInstance, (UINT)MAKEINTRESOURCE(IDS_APPTITLE), szAppTitle, 80))
162 _tcscpy(szAppTitle, TEXT("ReactOS Welcome"));
164 /* Create main window */
165 hwndMain = CreateWindow(szFrameClass,
177 ShowWindow(hwndMain, nCmdShow);
178 UpdateWindow(hwndMain);
180 while (GetMessage(&msg, NULL, 0, 0) != FALSE)
182 TranslateMessage(&msg);
183 DispatchMessage(&msg);
191 ButtonSubclassWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
195 if (uMsg == WM_MOUSEMOVE)
197 i = GetWindowLong(hWnd, GWL_ID);
202 InvalidateRect(hwndMain, NULL, TRUE);
206 return(CallWindowProc(fnOldBtn, hWnd, uMsg, wParam, lParam));
211 RunApplication(int nTopic)
213 PROCESS_INFORMATION ProcessInfo;
214 STARTUPINFO StartupInfo;
216 CHAR CurrentDir[256];
219 InvalidateRect(hwndMain, NULL, TRUE);
221 GetCurrentDirectory(256, CurrentDir);
223 nLength = LoadString(hInstance, IDS_TOPICACTION0 + nTopic, AppName, 256);
227 if (stricmp(AppName, "explorer.exe") == 0)
229 strcat(AppName, " ");
230 strcat(AppName, CurrentDir);
233 memset(&StartupInfo, 0, sizeof(STARTUPINFO));
234 StartupInfo.cb = sizeof(STARTUPINFO);
235 StartupInfo.lpTitle = "Test";
236 StartupInfo.dwFlags = STARTF_USESHOWWINDOW;
237 StartupInfo.wShowWindow = SW_SHOWNORMAL;
239 CreateProcess(NULL, AppName, NULL, NULL, FALSE, CREATE_NEW_CONSOLE,NULL,
244 CloseHandle(ProcessInfo.hProcess);
245 CloseHandle(ProcessInfo.hThread);
251 SubclassButton(HWND hWnd)
253 fnOldBtn = (WNDPROC)SetWindowLong(hWnd, GWL_WNDPROC, (LPARAM)ButtonSubclassWndProc);
258 GetButtonHeight(HDC hDC,
267 rect.right = dwWidth - 20;
271 hOldFont = SelectObject(hDC, hFont);
272 DrawText(hDC, szText, -1, &rect, DT_TOP | DT_CALCRECT | DT_WORDBREAK);
273 SelectObject(hDC, hOldFont);
275 return(rect.bottom-rect.top + 14);
280 OnCreate(HWND hWnd, WPARAM wParam, LPARAM lParam)
287 hbrLightBlue = CreateSolidBrush (LIGHT_BLUE);
288 hbrDarkBlue = CreateSolidBrush(DARK_BLUE);
289 hbrRightPanel = CreateSolidBrush (0x00FFFFFF);
292 hfontBannerTitle = CreateFont(-30,0,0,0,FW_BOLD,
293 FALSE,FALSE,FALSE,ANSI_CHARSET,
300 hfontTopicTitle = CreateFont(-18,0,0,0,FW_NORMAL,
301 FALSE,FALSE,FALSE,ANSI_CHARSET,
309 hfontTopicDescription = CreateFont(-11,0,0,0,FW_THIN,
310 FALSE,FALSE,FALSE,ANSI_CHARSET,
317 hfontTopicButton = CreateFont(-11,0,0,0,FW_BOLD,
318 FALSE,FALSE,FALSE,ANSI_CHARSET,
326 hTitleBitmap = LoadBitmap (hInstance, MAKEINTRESOURCE(IDB_TITLEBITMAP));
327 hDefaultTopicBitmap = LoadBitmap (hInstance, MAKEINTRESOURCE(IDB_DEFAULTTOPICBITMAP));
329 for (i=0;i < 10; i++)
331 hTopicBitmap[i] = LoadBitmap (hInstance, MAKEINTRESOURCE(IDB_TOPICBITMAP0+i));
334 hTopBackgroundBitmap = LoadBitmap (hInstance, MAKEINTRESOURCE(IDB_TBACKGROUNDBITMAP));
335 hRightBackgroundBitmap = LoadBitmap (hInstance, MAKEINTRESOURCE(IDB_RBACKGROUNDBITMAP));
337 hdcDisplay = CreateDC ("DISPLAY", NULL, NULL, NULL);
338 hdcMem = CreateCompatibleDC (hdcDisplay);
340 /* load and create buttons */
341 dwTop = rcLeftPanel.top;
342 for (i=0;i < 10; i++)
344 nLength = LoadString(hInstance, IDS_TOPICBUTTON0+i,szText,80);
347 dwHeight = GetButtonHeight(hdcMem,
350 rcLeftPanel.right - rcLeftPanel.left);
352 hwndTopicButton[i] = CreateWindow("BUTTON",
354 WS_CHILDWINDOW | WS_VISIBLE | WS_TABSTOP | BS_MULTILINE | BS_OWNERDRAW,
357 rcLeftPanel.right - rcLeftPanel.left,
363 hwndDefaultTopic = hwndTopicButton[i];
365 SubclassButton(hwndTopicButton[i]);
366 SendMessage(hwndTopicButton[i], WM_SETFONT, (WPARAM)hfontTopicButton, MAKELPARAM(TRUE,0));
370 hwndTopicButton[i] = 0;
376 /* Create exit button */
377 nLength = LoadString(hInstance, IDS_CLOSETEXT, szText, 80);
380 hwndCloseButton = CreateWindow("BUTTON",
382 WS_VISIBLE | WS_CHILD | BS_FLAT,
383 rcRightPanel.right - 10 - 57,
384 rcRightPanel.bottom - 10 - 21,
388 (HMENU)IDC_CLOSEBUTTON,
391 hwndDefaultTopic = 0;
393 SendMessage(hwndCloseButton, WM_SETFONT, (WPARAM)hfontTopicButton, MAKELPARAM(TRUE,0));
400 /* Create checkbox */
401 nLength = LoadString(hInstance, IDS_CHECKTEXT,szText,80);
404 hfontCheckButton = CreateFont(-10,0,0,0,FW_THIN,FALSE,FALSE,FALSE,ANSI_CHARSET,
411 hwndCheckButton = CreateWindow("BUTTON",
413 WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX,
414 rcLeftPanel.left + 8,
415 rcLeftPanel.bottom - 8 - 13,
416 rcLeftPanel.right - rcLeftPanel.left - 16,
419 (HMENU)IDC_CHECKBUTTON,
422 SendMessage(hwndCheckButton, WM_SETFONT, (WPARAM)hfontCheckButton, MAKELPARAM(TRUE,0));
427 hfontCheckButton = 0;
435 OnCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
437 if (LOWORD(wParam) == IDC_CLOSEBUTTON)
441 else if ((LOWORD(wParam) < 10))
443 if (RunApplication(LOWORD(wParam)) == FALSE)
453 PaintBanner(HDC hdc, LPRECT rcPanel)
462 /* Gradient background bitmap */
463 hOldBitmap = SelectObject(hdcMem, hTopBackgroundBitmap);
467 rcPanel->right - rcPanel->left,
469 hdcMem, 0, 0, SRCCOPY);
470 SelectObject(hdc, hOldBitmap);
472 hOldFont = SelectObject (hdc, hfontBannerTitle);
473 SetTextColor(hdc, 0x00000000);
475 oldBkMode = GetBkMode(hdc);
476 SetBkMode(hdc, TRANSPARENT);
478 sprintf(version, "ReactOS %d.%d.%d",
479 KERNEL_VERSION_MAJOR,
480 KERNEL_VERSION_MINOR,
481 KERNEL_VERSION_PATCH_LEVEL);
485 DrawTextA(hdc, version, -1, &rcTitle, DT_TOP | DT_CALCRECT);
486 DrawTextA(hdc, version, -1, &rcTitle, DT_TOP);
488 SetBkMode(hdc, oldBkMode);
490 SelectObject(hdc, hOldFont);
493 hOldBrush = SelectObject(hdc, hbrDarkBlue);
497 rcPanel->right - rcPanel->left,
501 SelectObject(hdc, hOldBrush);
506 OnPaint(HWND hWnd, WPARAM wParam, LPARAM lParam)
512 HBITMAP hOldBitmap = 0;
515 RECT rcTitle, rcDescription;
516 TCHAR szTopicTitle[80];
517 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,
536 /* Gradient background bitmap */
537 hOldBitmap = SelectObject(hdcMem, hRightBackgroundBitmap);
541 rcRightPanel.right - rcRightPanel.left,
542 rcRightPanel.bottom - rcRightPanel.top,
543 hdcMem, 0, 0, SRCCOPY);
544 SelectObject(hdc, hOldBitmap);
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 topic title */
608 rcTitle.left = rcRightPanel.left + 12;
609 rcTitle.right = rcRightPanel.right - 8;
610 rcTitle.top = rcRightPanel.top + 8;
611 rcTitle.bottom = rcTitle.top + 57;
612 hOldFont = SelectObject(hdc, hfontTopicTitle);
613 DrawText(hdc, szTopicTitle, -1, &rcTitle, DT_TOP | DT_CALCRECT);
615 SetTextColor(hdc, DARK_BLUE);
616 DrawText(hdc, szTopicTitle, -1, &rcTitle, DT_TOP);
618 /* Draw topic description */
619 rcDescription.left = rcRightPanel.left + 12;
620 rcDescription.right = rcRightPanel.right - 8;
621 rcDescription.top = rcTitle.bottom + 8;
622 rcDescription.bottom = rcRightPanel.bottom - 20;
624 SelectObject(hdc, hfontTopicDescription);
625 SetTextColor(hdc, 0x00000000);
626 DrawText(hdc, szTopicDesc, -1, &rcDescription, DT_TOP | DT_WORDBREAK);
628 SetBkMode(hdc, OPAQUE);
629 SelectObject(hdc, hOldFont);
631 SelectObject (hdcMem, hOldBrush);
632 SelectObject (hdcMem, hOldBitmap);
641 OnDrawItem(HWND hWnd, WPARAM wParam, LPARAM lParam)
643 LPDRAWITEMSTRUCT lpDis = (LPDRAWITEMSTRUCT)lParam;
649 if (lpDis->hwndItem == hwndCloseButton)
651 DrawFrameControl(lpDis->hDC,
654 DFCS_BUTTONPUSH | DFCS_FLAT);
658 if (lpDis->CtlID == (ULONG)nTopic)
659 hOldBrush = SelectObject(lpDis->hDC, hbrRightPanel);
661 hOldBrush = SelectObject(lpDis->hDC, hbrLightBlue);
666 lpDis->rcItem.bottom,
668 SelectObject(lpDis->hDC, hOldBrush);
670 hPen = CreatePen(PS_SOLID, 0, DARK_BLUE);
671 hOldPen = SelectObject(lpDis->hDC, hPen);
672 MoveToEx(lpDis->hDC, lpDis->rcItem.left, lpDis->rcItem.bottom-1, NULL);
673 LineTo(lpDis->hDC, lpDis->rcItem.right, lpDis->rcItem.bottom-1);
674 SelectObject(lpDis->hDC, hOldPen);
677 InflateRect(&lpDis->rcItem, -10, -4);
678 OffsetRect(&lpDis->rcItem, 0, 1);
679 GetWindowText(lpDis->hwndItem, szText, 80);
680 SetTextColor(lpDis->hDC, 0x00000000);
681 iBkMode = SetBkMode(lpDis->hDC, TRANSPARENT);
682 DrawText(lpDis->hDC, szText, -1, &lpDis->rcItem, DT_TOP | DT_LEFT | DT_WORDBREAK);
683 SetBkMode(lpDis->hDC, iBkMode);
691 OnMouseMove(HWND hWnd, WPARAM wParam, LPARAM lParam)
697 InvalidateRect(hwndMain, NULL, TRUE);
705 OnCtlColorStatic(HWND hWnd, WPARAM wParam, LPARAM lParam)
707 if ((HWND)lParam == hwndCheckButton)
709 SetBkColor((HDC)wParam, LIGHT_BLUE);
710 return((LRESULT)hbrLightBlue);
718 OnActivate(HWND hWnd, WPARAM wParam, LPARAM lParam)
721 InvalidateRect(hwndMain, NULL, TRUE);
728 OnDestroy(HWND hWnd, WPARAM wParam, LPARAM lParam)
734 if (hwndTopicButton[i] != 0)
735 DestroyWindow(hwndTopicButton[i]);
738 if (hwndCloseButton != 0)
739 DestroyWindow(hwndCloseButton);
741 if (hwndCheckButton != 0)
742 DestroyWindow(hwndCheckButton);
745 DeleteDC(hdcDisplay);
748 DeleteObject(hDefaultTopicBitmap);
749 DeleteObject(hTitleBitmap);
752 if (hTopicBitmap[i] != 0)
753 DeleteObject(hTopicBitmap[i]);
755 DeleteObject(hTopBackgroundBitmap);
756 DeleteObject(hRightBackgroundBitmap);
758 DeleteObject(hfontTopicTitle);
759 DeleteObject(hfontTopicDescription);
760 DeleteObject(hfontTopicButton);
762 DeleteObject(hfontBannerTitle);
765 if (hfontCheckButton != 0)
766 DeleteObject(hfontCheckButton);
768 DeleteObject(hbrLightBlue);
769 DeleteObject(hbrDarkBlue);
770 DeleteObject(hbrRightPanel);
777 MainWndProc(HWND hWnd,
785 return(OnCreate(hWnd, wParam, lParam));
788 return(OnCommand(hWnd, wParam, lParam));
791 return(OnActivate(hWnd, wParam, lParam));
794 return(OnPaint(hWnd, wParam, lParam));
797 return(OnDrawItem(hWnd, wParam, lParam));
799 case WM_CTLCOLORSTATIC:
800 return(OnCtlColorStatic(hWnd, wParam, lParam));
803 return(OnMouseMove(hWnd, wParam, lParam));
806 OnDestroy(hWnd, wParam, lParam);
811 return(DefWindowProc(hWnd, uMsg, wParam, lParam));