Skip to content

Instantly share code, notes, and snippets.

@nvictor
Last active February 20, 2020 23:42
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 nvictor/7255a5515196f60501f10fb9d884e2e9 to your computer and use it in GitHub Desktop.
Save nvictor/7255a5515196f60501f10fb9d884e2e9 to your computer and use it in GitHub Desktop.
Win32 API create window
void create_window(HINSTANCE module, LPCTSTR class_name, LPCTSTR title) {
// 1. filling WNDCLASS / WNDCLASSEX
// wc = {} and wc {.hCursor = ..., .hInstance = ...} don't work in VS2017
WNDCLASS wc = {0};
// Only 3 components are necessary
// hCursor sets the cursor for when the mouse is over the window
wc.hCursor = LoadCursor(nullptr, IDC_ARROW);
// hInstance is the handle to the module's instance
// and lpszClassName is the window class name.
// both form a "key" to identify the window within the process
wc.hInstance = module;
wc.lpszClassName = name;
// necessary if the window should handle events immediately after creation
wc.lpfnWndProc = ...
// 2. calling RegisterClass() / RegisterClassEx()
VERIFY(RegisterClass(&wc));
// 3. calling CreateWindow() / CreateWindowEx()
VERIFY(CreateWindow(
// class name
wc.lpszClassName,
// title
title,
// WS_VISIBLE so we don't have an extra call to ShowWindow()
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
// x, y, width, height
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
// parent, menu, module, lpparam (arbitrary LPVOID param)
// nullptr available?
NULL, NULL, module, NULL
));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment