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