forked from vsite-nwp/v01
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
73 lines (56 loc) · 1.65 KB
/
Copy pathmain.cpp
File metadata and controls
73 lines (56 loc) · 1.65 KB
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
65
66
67
68
69
70
71
72
73
#include <windows.h>
enum { id_button1 = 1, id_button2 };
void OnCreate(HWND hw) {
CreateWindow("BUTTON", "one", WS_CHILD | WS_VISIBLE, 150, 150, 70, 30, hw, (HMENU)id_button1, 0, 0);
CreateWindow("BUTTON", "two", WS_CHILD | WS_VISIBLE, 150, 200, 70, 30, hw, (HMENU)id_button2, 0, 0);
}
void OnCommand(HWND hw, int id) {
if(id==id_button1)
MessageBox(hw, "first", NULL, MB_OK | MB_ICONWARNING);
if(id==id_button2)
MessageBox(hw, "second", NULL, MB_OK | MB_ICONWARNING);
}
void OnDestroy() {
PostQuitMessage(0);
}
LRESULT CALLBACK WndProc(HWND hw, UINT msg, WPARAM wp, LPARAM lp)
{
switch (msg)
{
case WM_CREATE:
OnCreate(hw);
return 0;
case WM_COMMAND:
OnCommand(hw, LOWORD(wp));
return 0;
case WM_DESTROY:
OnDestroy();
return 0;
}
return DefWindowProc(hw, msg, wp, lp);
}
int RegisterMyClass(HINSTANCE hInstance, char* className)
{
WNDCLASS wc;
ZeroMemory(&wc, sizeof wc);
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.lpszClassName = className;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = CreateSolidBrush((RGB(0,200,200)));
return RegisterClass(&wc);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hp, LPSTR cmdLine, int nShow)
{
char clsName[] = "NWPClass";
if(!RegisterMyClass(hInstance, clsName))
return 0;
HWND hwnd = CreateWindow(clsName, "NWP 1", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);
MSG msg;
while(GetMessage(&msg, NULL, 0, 0))
DispatchMessage(&msg);
return msg.wParam;
}