Skip to content

Instantly share code, notes, and snippets.

@Acebond
Created May 25, 2024 02:12
Show Gist options
  • Save Acebond/a5af0e14c22f0870d9ab34cd1dae0b46 to your computer and use it in GitHub Desktop.
Save Acebond/a5af0e14c22f0870d9ab34cd1dae0b46 to your computer and use it in GitHub Desktop.
WindowAppExample.cpp
#include <Windows.h>
LRESULT CALLBACK WndProc(
_In_ HWND hWnd,
_In_ UINT msg,
_In_ WPARAM wParam,
_In_ LPARAM lParam) {
switch (msg) {
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}
int APIENTRY wWinMain(
_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPWSTR lpCmdLine,
_In_ int nCmdShow) {
const TCHAR szTitle[] = TEXT("Example Windows App");
const TCHAR szWindowClass[] = TEXT("Example Windows App");
WNDCLASSEX wc = {
.cbSize = sizeof(wc),
.lpfnWndProc = WndProc,
.hInstance = hInstance,
.lpszClassName = szWindowClass,
};
if (!RegisterClassEx(&wc)) {
return 1;
}
HWND hWnd = CreateWindowEx(
0, // No extended style
szWindowClass, // Class name
szTitle, // Window title
WS_OVERLAPPEDWINDOW, // Window style
CW_USEDEFAULT, // Initial x position
CW_USEDEFAULT, // Initial y position
1280, // Width
720, // Height
nullptr, // No parent window
nullptr, // No menu
wc.hInstance, // Instance handle
nullptr); // No additional data
if (!hWnd) {
return 1;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
MSG msg;
while (GetMessage(&msg, nullptr, 0, 0) > 0) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
DestroyWindow(hWnd);
UnregisterClass(wc.lpszClassName, wc.hInstance);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment