事件和信息
事件,例如鼠标的单机 会保存很多数据 这个便是信息
Windows为了能够准确的描述这些信息,提供了一个结构体:MSG,该结构体里面记录的事件的详细信息.
typedef struct tagMSG {
HWND hwnd; //窗口句柄
UINT message; ///信息类别 下面信息类型
WPARAM wParam;
LPARAM lParam;
DWORD time; //信息创建时间
、
POINT pt; //创建时 鼠标的位置
} MSG, *PMSG;
信息与事件的对应关系
流程
鼠标按下--事件
创建信息-包含鼠标位置 还有类别(左单机 右单机)
将信息放入队列中 队列获取信息 对信息进行处理
将dis加工的信息传递给操作系统
系统调用窗口过程函数
第一个win32 代码编写
点击查看代码
// WindowsProject1.cpp : 定义应用程序的入口点。
//
#include "framework.h"
#include "WindowsProject1.h"
#include <Windows.h>
HINSTANCE hAppInstance;
#define MAX_LOADSTRING 100
// 此代码模块中包含的函数的前向声明:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK WindowProc(
IN HWND hwnd,
IN UINT uMsg,
IN WPARAM wParam,
IN LPARAM lParam
)
{
switch (uMsg)
{
//窗口消息
case WM_CREATE:
{
DbgPrintf("WM_CREATE %d %d\n", wParam, lParam);
CREATESTRUCT* createst = (CREATESTRUCT*)lParam;
DbgPrintf("CREATESTRUCT %s\n", createst->lpszClass);
return 0;
}
case WM_MOVE:
{
DbgPrintf("WM_MOVE %d %d\n", wParam, lParam);
POINTS points = MAKEPOINTS(lParam);
DbgPrintf("X Y %d %d\n", points.x, points.y);
return 0;
}
case WM_SIZE:
{
DbgPrintf("WM_SIZE %d %d\n", wParam, lParam);
int newWidth = (int)(short)LOWORD(lParam);
int newHeight = (int)(short)HIWORD(lParam);
DbgPrintf("WM_SIZE %d %d\n", newWidth, newHeight);
return 0;
}
case WM_DESTROY:
{
DbgPrintf("WM_DESTROY %d %d\n", wParam, lParam);
PostQuitMessage(0);
return 0;
}
//键盘消息
case WM_KEYUP:
{
DbgPrintf("WM_KEYUP %d %d\n", wParam, lParam);
return 0;
}
case WM_KEYDOWN:
{
DbgPrintf("WM_KEYDOWN %d %d\n", wParam, lParam);
return 0;
}
//鼠标消息
case WM_LBUTTONDOWN:
{
DbgPrintf("WM_LBUTTONDOWN %d %d\n", wParam, lParam);
POINTS points = MAKEPOINTS(lParam);
DbgPrintf("WM_LBUTTONDOWN %d %d\n", points.x, points.y);
return 0;
}
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPWSTR lpCmdLine,
_In_ int nCmdShow)
{
hAppInstance = hInstance;
LPCWSTR className = (LPCWSTR)"My First Window";
WNDCLASS wndclass = { 0 };
wndclass.hbrBackground = (HBRUSH)COLOR_MENU;
wndclass.lpfnWndProc = WindowProc;
wndclass.lpszClassName = className;
wndclass.hInstance = hInstance;
RegisterClass(&wndclass);
// 创建窗口
HWND hwnd = CreateWindow(
className,
TEXT("我的第一个窗口"),
WS_OVERLAPPEDWINDOW,
10,
10,
600,
300,
NULL,
NULL,
hInstance,
NULL);
if (hwnd == NULL)
return 0;
// 显示窗口
ShowWindow(hwnd, SW_SHOW);
// 更新窗口
UpdateWindow(hwnd);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
手机扫一扫
移动阅读更方便
你可能感兴趣的文章