逆向学习-windows编程消息处理
【摘要】 #include<Windows.h>#include<iostream>int a = 1;const UINT WM_USERMSG = WM_USER + 1; //自定义消息事件void print(LPCWSTR format, ...) { WCHAR wchar_buff[100]{ 0 }; va_list arglist; va_start(argl...
#include<Windows.h>
#include<iostream>
int a = 1;
const UINT WM_USERMSG = WM_USER + 1; //自定义消息事件
void print(LPCWSTR format, ...) {
WCHAR wchar_buff[100]{ 0 };
va_list arglist;
va_start(arglist, format);
wvsprintfW(wchar_buff, format, arglist);
va_end(arglist);
OutputDebugStringW(wchar_buff);
}
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;
case WM_MOUSEMOVE:
//print(L"鼠标移动了!/n,%d",a);
//a++;
{
WORD X = LOWORD(lParam);
WORD Y = HIWORD(lParam);
print(L"鼠标移动了!X坐标%d,Y坐标%d", X, Y);
break;
}
case WM_LBUTTONDOWN:
print(L"鼠标左键按下了/n");
SendMessageW(hwnd, WM_USERMSG, 0, 0);
case WM_USERMSG:
print(L"自定义消息!/n");
break;
default:
break;
}
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
}
int WINAPI WinMain(
_In_ HINSTANCE hInstance, // handle to current instance
_In_opt_ HINSTANCE hPrevInstance, // handle to previous instance
_In_ LPSTR lpCmdLine, // command line
_In_ int nCmdShow // show state
)
{
//创建一个窗口类
WNDCLASSW myClass = { 0 };
myClass.lpszClassName = L"51hook";
myClass.lpfnWndProc = WindowProc;
//2.注册窗口类
RegisterClassW(&myClass);
//3.创建窗口
HWND hwnd = CreateWindowW(
myClass.lpszClassName,
L"51hook",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
0,
CW_USEDEFAULT,
0,
NULL,
NULL,
hInstance,
0
);
//4.显示窗口
ShowWindow(hwnd, SW_SHOWNORMAL);
//5.获取消息
MSG msg = { 0 };
while (GetMessageW(&msg,0,0,0)){
DispatchMessage(&msg);
}
return 0;
}
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)