Changeset 533
- Timestamp:
- 11/13/2008 9:34:33 AM (5 years ago)
- File:
-
- 1 edited
-
branches/eraser6/Installer/Bootstrapper/Main.cpp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eraser6/Installer/Bootstrapper/Main.cpp
r532 r533 23 23 #include "Bootstrapper.h" 24 24 25 #define STATIC_CLASS L"STATIC"26 #define BUTTON_CLASS L"BUTTON"27 28 25 //Common Controls Version 6 29 26 #pragma comment(linker, "\"/manifestdependency:type='Win32' " \ … … 33 30 34 31 namespace { 35 wchar_t* szWindowClass = L"EraserBootstrapper"; 32 //Constants 33 const wchar_t* STATIC_CLASS = L"STATIC"; 34 const wchar_t* BUTTON_CLASS = L"BUTTON"; 35 const wchar_t* szWindowClass = L"EraserBootstrapper"; 36 37 //Static variables 36 38 HINSTANCE hInstance = NULL; 37 39 HWND hWndParent = NULL; 38 } 39 40 bool InitInstance(HINSTANCE hInstance, HWND& hWnd); 41 void SetWindowFont(HWND hWnd); 42 LRESULT __stdcall WndProc(HWND, UINT, WPARAM, LPARAM); 40 41 bool InitInstance(HINSTANCE hInstance, HWND& hWnd); 42 void SetWindowFont(HWND hWnd); 43 LRESULT __stdcall WndProc(HWND, UINT, WPARAM, LPARAM); 44 45 /// Creates a temporary directory with the given name. The directory and files in it 46 /// are deleted when this object is destroyed. 47 class TempDir 48 { 49 public: 50 /// Constructor. 51 /// 52 /// \param[in] dirName The path to the directory. This directory will be created. 53 TempDir(std::wstring dirName) 54 : DirName(dirName) 55 { 56 if (!CreateDirectoryW(dirName.c_str(), NULL)) 57 throw GetErrorMessage(GetLastError()); 58 } 59 60 ~TempDir() 61 { 62 RemoveDirectoryW(DirName.c_str()); 63 } 64 65 private: 66 std::wstring DirName; 67 }; 68 69 /// Registers the main window class and creates it. 70 bool InitInstance(HINSTANCE hInstance, HWND& hWnd) 71 { 72 WNDCLASSEX wcex; 73 ::ZeroMemory(&wcex, sizeof(wcex)); 74 75 wcex.cbSize = sizeof(WNDCLASSEX); 76 wcex.style = CS_HREDRAW | CS_VREDRAW; 77 wcex.lpfnWndProc = WndProc; 78 wcex.cbClsExtra = 0; 79 wcex.cbWndExtra = 0; 80 wcex.hInstance = hInstance; 81 wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(BOOTSTRAPPER_ICON)); 82 wcex.hCursor = LoadCursor(NULL, IDC_ARROW); 83 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); 84 wcex.lpszClassName = szWindowClass; 85 wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(BOOTSTRAPPER_ICON)); 86 RegisterClassExW(&wcex); 87 InitCommonControls(); 88 89 //Create the window 90 hWnd = CreateWindowW(szWindowClass, L"Eraser Setup", WS_CAPTION | WS_SYSMENU, 91 CW_USEDEFAULT, 0, 300, 130, NULL, NULL, hInstance, NULL); 92 93 if (!hWnd) 94 return false; 95 96 //Set default settings (font) 97 SetWindowFont(hWnd); 98 return true; 99 } 100 101 /// Helper function to set the window font for created windows to the system default. 102 void SetWindowFont(HWND hWnd) 103 { 104 HFONT hWndFont = NULL; 105 if (!hWndFont) 106 { 107 NONCLIENTMETRICS ncm; 108 ::ZeroMemory(&ncm, sizeof(ncm)); 109 ncm.cbSize = sizeof(ncm); 110 111 if ( !::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncm, 0) ) 112 { 113 #if WINVER >= 0x0600 114 // a new field has been added to NONCLIENTMETRICS under Vista, so 115 // the call to SystemParametersInfo() fails if we use the struct 116 // size incorporating this new value on an older system -- retry 117 // without it 118 ncm.cbSize -= sizeof(int); 119 if ( !::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncm, 0) ) 120 #endif 121 return; 122 } 123 124 hWndFont = CreateFontIndirectW(&ncm.lfMessageFont); 125 } 126 127 SendMessage(hWnd, WM_SETFONT, (WPARAM)hWndFont, MAKELPARAM(TRUE, 0)); 128 } 129 130 /// Processes messages for the main window. 131 /// 132 /// Current messages processed: 133 /// WM_COMMAND - process the application menu 134 /// WM_PAINT - Paint the main window 135 /// WM_DESTROY - post a quit message and return 136 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) 137 { 138 switch (message) 139 { 140 case WM_COMMAND: 141 { 142 /*int wmId = LOWORD(wParam); 143 switch (wmId) 144 { 145 default: 146 147 }*/ 148 return DefWindowProc(hWnd, message, wParam, lParam); 149 } 150 151 case WM_PAINT: 152 { 153 PAINTSTRUCT ps; 154 HDC hdc = BeginPaint(hWnd, &ps); 155 156 // TODO: Add any drawing code here... 157 EndPaint(hWnd, &ps); 158 break; 159 } 160 161 case WM_DESTROY: 162 PostQuitMessage(0); 163 break; 164 165 default: 166 return DefWindowProc(hWnd, message, wParam, lParam); 167 } 168 169 return 0; 170 } 171 } 43 172 44 173 int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, … … 69 198 ShowWindow(hWndParent, nCmdShow); 70 199 UpdateWindow(hWndParent); 71 72 //Check for .NET Framework 73 if (!HasNetFramework()) 74 { 75 //Install the .NET framework. 76 } 77 78 ExtractTempFiles(); 200 201 //OK, now we do the hard work. Create a folder to place our payload into 202 wchar_t tempPath[MAX_PATH]; 203 DWORD result = GetTempPathW(sizeof(tempPath) / sizeof(tempPath[0]), tempPath); 204 if (!result) 205 throw GetErrorMessage(GetLastError()); 206 207 std::wstring tempDir(tempPath, result); 208 if (std::wstring(L"\\/").find(tempDir[tempDir.length() - 1]) == std::wstring::npos) 209 tempDir += L"\\"; 210 tempDir += L"eraserInstallBootstrapper\\"; 211 TempDir dir(tempDir); 212 ExtractTempFiles(tempDir); 79 213 80 214 // Main message loop: … … 87 221 88 222 return (int) msg.wParam; 89 }90 91 /// Registers the main window class and creates it.92 bool InitInstance(HINSTANCE hInstance, HWND& hWnd)93 {94 WNDCLASSEX wcex;95 ::ZeroMemory(&wcex, sizeof(wcex));96 97 wcex.cbSize = sizeof(WNDCLASSEX);98 wcex.style = CS_HREDRAW | CS_VREDRAW;99 wcex.lpfnWndProc = WndProc;100 wcex.cbClsExtra = 0;101 wcex.cbWndExtra = 0;102 wcex.hInstance = hInstance;103 wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(BOOTSTRAPPER_ICON));104 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);105 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);106 wcex.lpszClassName = szWindowClass;107 wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(BOOTSTRAPPER_ICON));108 RegisterClassExW(&wcex);109 InitCommonControls();110 111 //Create the window112 hWnd = CreateWindowW(szWindowClass, L"Eraser Setup", WS_CAPTION | WS_SYSMENU,113 CW_USEDEFAULT, 0, 300, 130, NULL, NULL, hInstance, NULL);114 115 if (!hWnd)116 return false;117 118 //Set default settings (font)119 SetWindowFont(hWnd);120 return true;121 }122 123 /// Helper function to set the window font for created windows to the system default.124 void SetWindowFont(HWND hWnd)125 {126 HFONT hWndFont = NULL;127 if (!hWndFont)128 {129 NONCLIENTMETRICS ncm;130 ::ZeroMemory(&ncm, sizeof(ncm));131 ncm.cbSize = sizeof(ncm);132 133 if ( !::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncm, 0) )134 {135 #if WINVER >= 0x0600136 // a new field has been added to NONCLIENTMETRICS under Vista, so137 // the call to SystemParametersInfo() fails if we use the struct138 // size incorporating this new value on an older system -- retry139 // without it140 ncm.cbSize -= sizeof(int);141 if ( !::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncm, 0) )142 #endif143 return;144 }145 146 hWndFont = CreateFontIndirectW(&ncm.lfMessageFont);147 }148 149 SendMessage(hWnd, WM_SETFONT, (WPARAM)hWndFont, MAKELPARAM(TRUE, 0));150 }151 152 /// Processes messages for the main window.153 ///154 /// Current messages processed:155 /// WM_COMMAND - process the application menu156 /// WM_PAINT - Paint the main window157 /// WM_DESTROY - post a quit message and return158 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)159 {160 switch (message)161 {162 case WM_COMMAND:163 {164 /*int wmId = LOWORD(wParam);165 switch (wmId)166 {167 default:168 169 }*/170 return DefWindowProc(hWnd, message, wParam, lParam);171 }172 173 case WM_PAINT:174 {175 PAINTSTRUCT ps;176 HDC hdc = BeginPaint(hWnd, &ps);177 178 // TODO: Add any drawing code here...179 EndPaint(hWnd, &ps);180 break;181 }182 183 case WM_DESTROY:184 PostQuitMessage(0);185 break;186 187 default:188 return DefWindowProc(hWnd, message, wParam, lParam);189 }190 191 return 0;192 223 } 193 224
Note: See TracChangeset
for help on using the changeset viewer.
