逆向学习-windows编程第一个窗口程序
【摘要】 typedef struct tagWNDCLASSW { UINT style; WNDPROC lpfnWndProc; int cbClsExtra; int cbWndExtra; HINSTANCE hInstance; HICON hIcon; HCURSOR hCursor; HBRUSH hbrBackg...
typedef struct tagWNDCLASSW {
UINT style;
WNDPROC lpfnWndProc;
int cbClsExtra;
int cbWndExtra;
HINSTANCE hInstance;
HICON hIcon;
HCURSOR hCursor;
HBRUSH hbrBackground;
LPCWSTR lpszMenuName;
LPCWSTR lpszClassName;
} WNDCLASSW, *PWNDCLASSW, *NPWNDCLASSW, *LPWNDCLASSW;
核心的是WNDPROC 和 LPCWSTP lpszClassName 这两个必须有值
#include<Windows.h>
#include<iostream>
LRESULT CALLBACK WindowProc( //消息处理函数
_In_ HWND hwnd,
_In_ UINT uMsg,
_In_ WPARAM wParam,
_In_ LPARAM lParam
) {
switch (uMsg)
{
case WM_CREATE:
MessageBoxW(hwnd, L"窗口创建了", L"提示", MB_OK);
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;
}
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)