tools/installer/InstallerMain.cpp
author David Anderson <dvander@alliedmods.net>
Sun Nov 25 18:50:13 2007 +0000 (2007-11-25)
changeset 1725 ea875bcbc286
parent 1722 2c16f160f5dd
child 2289 44045ead61cd
permissions -rw-r--r--
small clarification to param2 in MenuAction_End
     1 #include "InstallerMain.h"
     2 #include "Welcome.h"
     3 
     4 #define WMU_INIT_INSTALLER		WM_USER+1
     5 
     6 HINSTANCE g_hInstance;
     7 NEXT_DIALOG next_dialog = DisplayWelcome;
     8 POINT g_GlobalPosition;
     9 
    10 void UpdateGlobalPosition(HWND hWnd)
    11 {
    12 	WINDOWINFO wi;
    13 
    14 	wi.cbSize = sizeof(WINDOWINFO);
    15 	if (GetWindowInfo(hWnd, &wi))
    16 	{
    17 		g_GlobalPosition.x = wi.rcWindow.left;
    18 		g_GlobalPosition.y = wi.rcWindow.top;
    19 	}
    20 }
    21 
    22 void SetToGlobalPosition(HWND hWnd)
    23 {
    24 	WINDOWINFO wi;
    25 	
    26 	wi.cbSize = sizeof(WINDOWINFO);
    27 	if (GetWindowInfo(hWnd, &wi))
    28 	{
    29 		MoveWindow(hWnd, 
    30 			g_GlobalPosition.x, 
    31 			g_GlobalPosition.y, 
    32 			wi.rcWindow.right - wi.rcWindow.left,
    33 			wi.rcWindow.bottom - wi.rcWindow.top,
    34 			TRUE);
    35 	}
    36 }
    37 
    38 LRESULT CALLBACK MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    39 {
    40 	switch (message)
    41 	{
    42 	case WMU_INIT_INSTALLER:
    43 		{
    44 			UpdateGlobalPosition(hWnd);
    45 			while (next_dialog != NULL)
    46 			{
    47 				next_dialog = (NEXT_DIALOG)next_dialog(hWnd);
    48 			}
    49 			PostQuitMessage(0);
    50 			break;
    51 		}
    52 	case WM_DESTROY:
    53 		{
    54 			PostQuitMessage(0);
    55 			break;
    56 		}
    57 	default:
    58 		{
    59 			return DefWindowProc(hWnd, message, wParam, lParam);
    60 		}
    61 	}
    62 
    63 	return 0;
    64 }
    65 
    66 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
    67 {
    68 	WNDCLASSEX wcex;
    69 	BOOL bRet;
    70 
    71 	wcex.cbSize			= sizeof(wcex);
    72 	wcex.style			= CS_HREDRAW | CS_VREDRAW;
    73 	wcex.lpfnWndProc	= MainWndProc;
    74 	wcex.cbClsExtra		= 0;
    75 	wcex.cbWndExtra		= 0;
    76 	wcex.hInstance		= hInstance;
    77 	wcex.hIcon			= LoadIcon(hInstance, MAKEINTRESOURCE(IDI_INSTALLER));
    78 	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
    79 	wcex.hbrBackground	= (HBRUSH)(COLOR_WINDOW+1);
    80 	wcex.lpszMenuName	= _T("InstallerMenu");
    81 	wcex.lpszClassName	= _T("Installer");
    82 	wcex.hIconSm		= LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
    83 
    84 	if (!RegisterClassEx(&wcex))
    85 	{
    86 		return 1;
    87 	}
    88 
    89 	INITCOMMONCONTROLSEX ccex;
    90 	ccex.dwSize = sizeof(ccex);
    91 	ccex.dwICC = ICC_BAR_CLASSES
    92 		|ICC_HOTKEY_CLASS
    93 		|ICC_LISTVIEW_CLASSES
    94 		|ICC_PROGRESS_CLASS
    95 		|ICC_WIN95_CLASSES
    96 		|ICC_TAB_CLASSES;
    97 
    98 	if (!InitCommonControlsEx(&ccex))
    99 	{
   100 		return 1;
   101 	}
   102 
   103 	g_hInstance = hInstance;
   104 
   105 	HWND hWnd = CreateWindow(
   106 		_T("Installer"),
   107 		_T("InstallerMain"),
   108 		WS_OVERLAPPEDWINDOW,
   109 		CW_USEDEFAULT,
   110 		CW_USEDEFAULT,
   111 		CW_USEDEFAULT,
   112 		CW_USEDEFAULT,
   113 		(HWND)NULL,
   114 		(HMENU)NULL,
   115 		hInstance,
   116 		NULL);
   117 	if (hWnd == NULL)
   118 	{
   119 		return 1;
   120 	}
   121 
   122 	ShowWindow(hWnd, SW_HIDE);
   123 	UpdateWindow(hWnd);
   124 
   125 	PostMessage(hWnd, WMU_INIT_INSTALLER, 0, 0);
   126 
   127 	MSG msg;
   128 	while ((bRet = GetMessage(&msg, NULL, 0, 0)) != 0)
   129 	{
   130 		if (bRet == -1)
   131 		{
   132 			return 1;
   133 		}
   134 		else
   135 		{
   136 			TranslateMessage(&msg);
   137 			DispatchMessage(&msg);
   138 		}
   139 	}
   140 
   141 	return (int)msg.wParam;
   142 }