This repository has been archived by the owner on Jul 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
winapi_window.c
64 lines (52 loc) · 2.15 KB
/
winapi_window.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/***************************************************************************
* File: winapi_window.c
* Created: 2024-05-21
* Modified: 2024-05-21
* Author: oknauta
* Description: Creates a generic window in C.
* Note: Created with Microsoft Notepad.
***************************************************************************/
#include <windows.h> // Library to create a window in Windows.
// This function is "what is happening in your application".
LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
// The main function to create a window with `winapi`.
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASS wc = {}; // Declares a window class.
wc.lpszClassName = "Generic Window Class"; // The class name.
wc.hInstance = hInstance; // The class handle instance.
wc.lpfnWndProc = WindowProc; // The class window procedural.
wc.style = CS_HREDRAW | CS_VREDRAW; // The class style.
wc.hCursor = LoadCursor(NULL, IDC_ARROW); // The class cursor.
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); // The class background color.
RegisterClass(&wc); // Register the class in Windows.
// Creates the window.
HWND hWnd;
hWnd = CreateWindow("Generic Window Class", "Generic Window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, NULL, NULL, hInstance, NULL);
if(hWnd == NULL)
{
return 1;
}
// Shows the window.
ShowWindow(hWnd, nCmdShow);
// Loop to handle the window.
MSG Msg;
while(GetMessage(&Msg, NULL, 0, 0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return 0;
}
LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg) // The user message.
{
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, uMsg, wParam, lParam); // Treats what isn't happening.
}
return 0;
}