Skip to content

Instantly share code, notes, and snippets.

@donnaken15
Last active January 4, 2021 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save donnaken15/050bade9fc33cdbdf8257d2502e65c4b to your computer and use it in GitHub Desktop.
Save donnaken15/050bade9fc33cdbdf8257d2502e65c4b to your computer and use it in GitHub Desktop.
copy paste for windows dialog applications in c++
#include <Windows.h>
static LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
static HWND hWnd;
static WNDCLASSEX wc;
ZeroMemory(&wc, sizeof(WNDCLASSEX));
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.lpszClassName = "MyApplication32";
RegisterClassEx(&wc);
hWnd = CreateWindowEx(NULL,
"MyApplication32",
"TEST",
WS_OVERLAPPED | WS_SYSMENU,
GetSystemMetrics(SM_CXSCREEN) / 2 - 1024 / 2,
GetSystemMetrics(SM_CYSCREEN) / 2 - 768 / 2,
1024 + 6,
768 + 34,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hWnd, nCmdShow);
static MSG msg;
while (TRUE)
{
//while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
if (msg.message == WM_QUIT)
break;
}
return msg.wParam;
}
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_QUIT:
case WM_CLOSE:
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
} break;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment