Skip to content

Instantly share code, notes, and snippets.

@atoz-programming-tutorials
Last active February 10, 2023 18:47
Show Gist options
  • Save atoz-programming-tutorials/a3cf2ad0341a97020638419d69c96adf to your computer and use it in GitHub Desktop.
Save atoz-programming-tutorials/a3cf2ad0341a97020638419d69c96adf to your computer and use it in GitHub Desktop.
#include <windows.h>
LRESULT CALLBACK WindowProcessMessages(HWND hwnd, UINT msg, WPARAM param, LPARAM lparam);
int WINAPI WinMain(HINSTANCE currentInstance, HINSTANCE previousInstance, PSTR cmdLine, INT cmdCount) {
// Register the window class
const char *CLASS_NAME = "myWin32WindowClass";
WNDCLASS wc{};
wc.hInstance = currentInstance;
wc.lpszClassName = CLASS_NAME;
wc.hCursor = LoadCursor(nullptr, IDC_ARROW);
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.lpfnWndProc = WindowProcessMessages;
RegisterClass(&wc);
// Create the window
CreateWindow(CLASS_NAME, "Win32 Tutorial",
WS_OVERLAPPEDWINDOW | WS_VISIBLE, // Window style
CW_USEDEFAULT, CW_USEDEFAULT, // Window initial position
800, 600, // Window size
nullptr, nullptr, nullptr, nullptr);
// Window loop
MSG msg{};
while (GetMessage(&msg, nullptr, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WindowProcessMessages(HWND hwnd, UINT msg, WPARAM param, LPARAM lparam) {
switch (msg) {
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hwnd, msg, param, lparam);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment