windows窗口控件

2

3

4

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
#include<Windows.h>
#include<iostream>
#include<CommCtrl.h>
LRESULT CALLBACK WindowProc( //消息处理函数
_In_ HWND hwnd,
_In_ UINT uMsg,
_In_ WPARAM wParam,
_In_ LPARAM lParam
) {
static HINSTANCE hInstance = GetModuleHandleW(NULL);
switch (uMsg)
{
case WM_CREATE:
//MessageBoxW(hwnd, L"窗口创建了", L"提示", MB_OK);
//添加控件
CreateWindowW(WC_BUTTON, L"按钮1", WS_CHILD | WS_VISIBLE, 10, 10, 100, 40, hwnd, (HMENU)0x100, hInstance, 0);
break;
case WM_CLOSE:
MessageBoxW(hwnd, L"窗口关闭了", L"提示", MB_OK);
DestroyWindow(hwnd);
PostQuitMessage(0);
break;
default:
break;
}
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
}
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPreInstance,
LPSTR lpCmdeLine,
int nCmdShow
)
{
//1.创建一个窗口类
WNDCLASSW myClass = { 0 };
myClass.lpszClassName = L"51hook";
myClass.lpfnWndProc = WindowProc;
//2.注册窗口类
RegisterClassW(&myClass);
//3.创建窗口
HWND hwindow = CreateWindowW(
myClass.lpszClassName,
L"51hook",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
0,
CW_USEDEFAULT,
0,
NULL,
NULL,
hInstance,
0
);
//4.显示窗口
ShowWindow(hwindow, SW_SHOWNORMAL);

//5.获取消息
MSG msg = { 0 };
while (GetMessageW(&msg, 0, 0, 0)) {
DispatchMessageW(&msg);//分发消息给消息处理函数
}

return 0;
}

本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!