1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
#include <windows.h>
// Forward declarations of functions included in this code module:
LRESULT CALLBACK WindowProc(_In_ HWND hwnd, _In_ UINT uMsg, _In_ WPARAM wParam, _In_ LPARAM lParam);
int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow)
{
// Register the window class.
const wchar_t CLASS_NAME[] = L"Sample Window";
WNDCLASSEX wcex = { };
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WindowProc;
wcex.cbClsExtra = NULL;
wcex.cbWndExtra = NULL;
wcex.hInstance = hInstance;
wcex.hCursor = reinterpret_cast<HCURSOR>(LoadImage(0, IDC_ARROW, IMAGE_CURSOR, 0, 0, LR_SHARED));
wcex.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_BTNFACE + 1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = CLASS_NAME;
wcex.hIcon = reinterpret_cast<HICON>(LoadImage(0, IDI_APPLICATION, IMAGE_ICON, 0, 0, LR_SHARED));
wcex.hIconSm = reinterpret_cast<HICON>(LoadImage(0, IDI_APPLICATION, IMAGE_ICON, 0, 0, LR_SHARED));
//if (RegisterClassEx(&wcex) == NULL) { return 0; }
if (!RegisterClassEx(&wcex)) return 0;
// Create the window.
HWND hwnd_Main = CreateWindowEx(
WS_EX_CONTROLPARENT | WS_EX_WINDOWEDGE, // Optional window styles.
CLASS_NAME, // Window class
L"C++ Window with a button", // Window text
WS_VISIBLE | WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, // Window style
200, 100, 1000, 640, // Size and position
NULL, // Parent window
NULL, // Menu
hInstance, // Instance handle
NULL); // Additional application data
// Dispatch Windows messages
MSG msg = { };
while (GetMessage(&msg, 0, 0, 0))
{
if (IsDialogMessage(hwnd_Main, &msg) == 0) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return 0;
}
LRESULT CALLBACK WindowProc(_In_ HWND hwnd, _In_ UINT uMsg, _In_ WPARAM wParam, _In_ LPARAM lParam)
{
switch (uMsg)
{
case WM_CREATE:
// create button
::CreateWindowEx(NULL, L"button", L"&Close", WS_CHILD | WS_VISIBLE | WS_TABSTOP, 100, 100, 100, 100, hwnd, (HMENU)IDCANCEL, NULL, &lParam);
return 0;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDCANCEL:
::SendMessage(hwnd, WM_CLOSE, 0, 0);
return 0; //break;
}
case WM_SIZE:
{
int width = LOWORD(lParam);
int height = HIWORD(lParam);
::MoveWindow(GetDlgItem(hwnd, IDCANCEL), width - 200, height - 80, 175, 50, TRUE);
}
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
|