mirror of
https://github.com/janbodnar/Windows-API-examples.git
synced 2026-08-06 18:04:46 -04:00
55 lines
1.2 KiB
C
55 lines
1.2 KiB
C
#include <windows.h>
|
|
|
|
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
|
|
|
|
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
|
PWSTR lpCmdLine, int nCmdShow) {
|
|
|
|
MSG msg;
|
|
WNDCLASSW wc = {0};
|
|
|
|
wc.style = CS_HREDRAW | CS_VREDRAW;
|
|
wc.lpszClassName = L"Rectangle";
|
|
wc.hInstance = hInstance;
|
|
wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
|
|
wc.lpfnWndProc = WndProc;
|
|
wc.hCursor = LoadCursor(0, IDC_ARROW);
|
|
|
|
RegisterClassW(&wc);
|
|
CreateWindowW(wc.lpszClassName, L"Rectangle",
|
|
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
|
|
100, 100, 250, 200, NULL, NULL, hInstance, NULL);
|
|
|
|
while (GetMessage(&msg, NULL, 0, 0)) {
|
|
|
|
TranslateMessage(&msg);
|
|
DispatchMessage(&msg);
|
|
}
|
|
|
|
return (int) msg.wParam;
|
|
}
|
|
|
|
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg,
|
|
WPARAM wParam, LPARAM lParam) {
|
|
|
|
HDC hdc;
|
|
PAINTSTRUCT ps;
|
|
|
|
switch(msg) {
|
|
|
|
case WM_PAINT:
|
|
|
|
hdc = BeginPaint(hwnd, &ps);
|
|
Rectangle(hdc, 50, 50, 200, 100);
|
|
EndPaint(hwnd, &ps);
|
|
break;
|
|
|
|
case WM_DESTROY:
|
|
|
|
PostQuitMessage(0);
|
|
return 0;
|
|
}
|
|
|
|
return DefWindowProcW(hwnd, msg, wParam, lParam);
|
|
}
|