Horje
how to create a window in c++ Code Example
how to create a window in c++
#include <Windows.h>

#pragma warning ( disable : 28251 )

// window message procedure 
LRESULT CALLBACK WinProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
	
	switch (msg) {
		case WM_CLOSE: PostQuitMessage(69); break;
	}
	
	return DefWindowProc(hwnd,msg,wParam,lParam);
}

// window main
int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {

	// class name 
	const auto pClassName = L"test name";

	// the new window class "ex"
	WNDCLASSEX wc = { 0 };
	wc.cbSize = sizeof(wc);
	wc.style = CS_OWNDC;
	wc.lpfnWndProc = WinProc;
	wc.cbClsExtra = 0;
	wc.cbWndExtra = 0;
	wc.hIcon = nullptr;
	wc.hCursor = nullptr;
	wc.hbrBackground = nullptr;
	wc.lpszClassName = pClassName;
	wc.hIconSm = nullptr;

	// register window class
	RegisterClassEx(&wc);

	// create window instance (window heandeler) 
	HWND hwnd = CreateWindowEx(
		0, pClassName,
		L"Test Window",
		WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU,
		200, 200, 640, 480,
		nullptr, nullptr, hInstance, nullptr
	);

	// show the window 
	ShowWindow(hwnd, SW_SHOW);
	
	// message pump
	MSG msg;
	BOOL gResult;
	
	while ((gResult = GetMessage(&msg, nullptr, 0, 0)) > 0) {
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	
	if (gResult == -1) {
		return -1;
	}
	else {
		return msg.wParam;
	}

	return 0;
}




Cpp

Related
closing a ifstream file c++ Code Example closing a ifstream file c++ Code Example
choose endianness in cpp Code Example choose endianness in cpp Code Example
GCD in cpp Code Example GCD in cpp Code Example
bit++ codeforces in c++ Code Example bit++ codeforces in c++ Code Example
what is meant by pragma once in c++ Code Example what is meant by pragma once in c++ Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7