|
| 1 | +// WinWebMerge.cpp : Defines the entry point for the application. |
| 2 | +// |
| 3 | + |
| 4 | +#include "framework.h" |
| 5 | +#include "WinWebMerge.h" |
| 6 | +#include "../WinWebMergeLib/WinWebMergeLib.h" |
| 7 | + |
| 8 | +#define MAX_LOADSTRING 100 |
| 9 | + |
| 10 | +// Global Variables: |
| 11 | +HINSTANCE hInst; // current instance |
| 12 | +HINSTANCE hInstDLL; // current instance |
| 13 | +WCHAR szTitle[MAX_LOADSTRING]; // The title bar text |
| 14 | +WCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name |
| 15 | +IWebMergeWindow* m_pWebMergeWindow = nullptr; |
| 16 | + |
| 17 | +// Forward declarations of functions included in this code module: |
| 18 | +ATOM MyRegisterClass(HINSTANCE hInstance); |
| 19 | +BOOL InitInstance(HINSTANCE, int); |
| 20 | +LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); |
| 21 | +INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM); |
| 22 | + |
| 23 | +int APIENTRY wWinMain(_In_ HINSTANCE hInstance, |
| 24 | + _In_opt_ HINSTANCE hPrevInstance, |
| 25 | + _In_ LPWSTR lpCmdLine, |
| 26 | + _In_ int nCmdShow) |
| 27 | +{ |
| 28 | + UNREFERENCED_PARAMETER(hPrevInstance); |
| 29 | + UNREFERENCED_PARAMETER(lpCmdLine); |
| 30 | + |
| 31 | + // TODO: Place code here. |
| 32 | + |
| 33 | + // Initialize global strings |
| 34 | + LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); |
| 35 | + LoadStringW(hInstance, IDC_WINWEBMERGE, szWindowClass, MAX_LOADSTRING); |
| 36 | + MyRegisterClass(hInstance); |
| 37 | + hInstDLL = GetModuleHandleW(L"WinWebMergeLib.dll"); |
| 38 | + |
| 39 | + // Perform application initialization: |
| 40 | + if (!InitInstance (hInstance, nCmdShow)) |
| 41 | + { |
| 42 | + return FALSE; |
| 43 | + } |
| 44 | + |
| 45 | + HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_WINWEBMERGE)); |
| 46 | + |
| 47 | + MSG msg; |
| 48 | + |
| 49 | + // Main message loop: |
| 50 | + while (GetMessage(&msg, nullptr, 0, 0)) |
| 51 | + { |
| 52 | + if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) |
| 53 | + { |
| 54 | + TranslateMessage(&msg); |
| 55 | + DispatchMessage(&msg); |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + return (int) msg.wParam; |
| 60 | +} |
| 61 | + |
| 62 | + |
| 63 | + |
| 64 | +// |
| 65 | +// FUNCTION: MyRegisterClass() |
| 66 | +// |
| 67 | +// PURPOSE: Registers the window class. |
| 68 | +// |
| 69 | +ATOM MyRegisterClass(HINSTANCE hInstance) |
| 70 | +{ |
| 71 | + WNDCLASSEXW wcex; |
| 72 | + |
| 73 | + wcex.cbSize = sizeof(WNDCLASSEX); |
| 74 | + |
| 75 | + wcex.style = CS_HREDRAW | CS_VREDRAW; |
| 76 | + wcex.lpfnWndProc = WndProc; |
| 77 | + wcex.cbClsExtra = 0; |
| 78 | + wcex.cbWndExtra = 0; |
| 79 | + wcex.hInstance = hInstance; |
| 80 | + wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_WINWEBMERGE)); |
| 81 | + wcex.hCursor = LoadCursor(nullptr, IDC_ARROW); |
| 82 | + wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); |
| 83 | + wcex.lpszMenuName = MAKEINTRESOURCEW(IDC_WINWEBMERGE); |
| 84 | + wcex.lpszClassName = szWindowClass; |
| 85 | + wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL)); |
| 86 | + |
| 87 | + return RegisterClassExW(&wcex); |
| 88 | +} |
| 89 | + |
| 90 | +// |
| 91 | +// FUNCTION: InitInstance(HINSTANCE, int) |
| 92 | +// |
| 93 | +// PURPOSE: Saves instance handle and creates main window |
| 94 | +// |
| 95 | +// COMMENTS: |
| 96 | +// |
| 97 | +// In this function, we save the instance handle in a global variable and |
| 98 | +// create and display the main program window. |
| 99 | +// |
| 100 | +BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) |
| 101 | +{ |
| 102 | + hInst = hInstance; // Store instance handle in our global variable |
| 103 | + |
| 104 | + HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, |
| 105 | + CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr); |
| 106 | + |
| 107 | + if (!hWnd) |
| 108 | + { |
| 109 | + return FALSE; |
| 110 | + } |
| 111 | + |
| 112 | + ShowWindow(hWnd, nCmdShow); |
| 113 | + UpdateWindow(hWnd); |
| 114 | + |
| 115 | + return TRUE; |
| 116 | +} |
| 117 | + |
| 118 | +// |
| 119 | +// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) |
| 120 | +// |
| 121 | +// PURPOSE: Processes messages for the main window. |
| 122 | +// |
| 123 | +// WM_COMMAND - process the application menu |
| 124 | +// WM_PAINT - Paint the main window |
| 125 | +// WM_DESTROY - post a quit message and return |
| 126 | +// |
| 127 | +// |
| 128 | +LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) |
| 129 | +{ |
| 130 | + switch (message) |
| 131 | + { |
| 132 | + case WM_CREATE: |
| 133 | + m_pWebMergeWindow = WinWebMerge_CreateWindow(hInstDLL, hWnd); |
| 134 | + break; |
| 135 | + case WM_SIZE: |
| 136 | + { |
| 137 | + RECT rc; |
| 138 | + GetClientRect(hWnd, &rc); |
| 139 | + m_pWebMergeWindow->SetWindowRect(rc); |
| 140 | + break; |
| 141 | + } |
| 142 | + case WM_COMMAND: |
| 143 | + { |
| 144 | + int wmId = LOWORD(wParam); |
| 145 | + // Parse the menu selections: |
| 146 | + switch (wmId) |
| 147 | + { |
| 148 | + case IDM_ABOUT: |
| 149 | + DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); |
| 150 | + break; |
| 151 | + case IDM_EXIT: |
| 152 | + DestroyWindow(hWnd); |
| 153 | + break; |
| 154 | + default: |
| 155 | + return DefWindowProc(hWnd, message, wParam, lParam); |
| 156 | + } |
| 157 | + } |
| 158 | + break; |
| 159 | + case WM_PAINT: |
| 160 | + { |
| 161 | + PAINTSTRUCT ps; |
| 162 | + HDC hdc = BeginPaint(hWnd, &ps); |
| 163 | + // TODO: Add any drawing code that uses hdc here... |
| 164 | + EndPaint(hWnd, &ps); |
| 165 | + } |
| 166 | + break; |
| 167 | + case WM_DESTROY: |
| 168 | + WinWebMerge_DestroyWindow(m_pWebMergeWindow); |
| 169 | + PostQuitMessage(0); |
| 170 | + break; |
| 171 | + default: |
| 172 | + return DefWindowProc(hWnd, message, wParam, lParam); |
| 173 | + } |
| 174 | + return 0; |
| 175 | +} |
| 176 | + |
| 177 | +// Message handler for about box. |
| 178 | +INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) |
| 179 | +{ |
| 180 | + UNREFERENCED_PARAMETER(lParam); |
| 181 | + switch (message) |
| 182 | + { |
| 183 | + case WM_INITDIALOG: |
| 184 | + return (INT_PTR)TRUE; |
| 185 | + |
| 186 | + case WM_COMMAND: |
| 187 | + if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) |
| 188 | + { |
| 189 | + EndDialog(hDlg, LOWORD(wParam)); |
| 190 | + return (INT_PTR)TRUE; |
| 191 | + } |
| 192 | + break; |
| 193 | + } |
| 194 | + return (INT_PTR)FALSE; |
| 195 | +} |
0 commit comments