typedef struct tagMSG { HWND hwnd; UINT message; WPARAM wParam; LPARAM lParam; DWORD time; POINT pt; DWORD lPrivate;} MSG, *PMSG, *NPMSG, *LPMSG;
这个结构体就是windows用来描述消息的。
1. HWND hwnd;//表示消息所属的窗口
A handle to the window whose window procedure receives the message. This member is NULL when the message is a thread message.
HWND是windwos自定义类型。通常用来表示窗口。使用IDE提供的类型声明可以在
#ifdef STRICTtypedef void *HANDLE;#define DECLARE_HANDLE(n) typedef struct n##__{int i;}*n#elsetypedef PVOID HANDLE;#define DECLARE_HANDLE(n) typedef HANDLE n#endif
通过宏定义可以看出HWND的本质就是void*类型。
2.UINT message;//消息常量标识符
The message identifier. Applications can only use the low word; the high word is reserved by the system.
第二个成员表示消息的类型,从官方文档表述中可以得知应用程序仅能使用低位的两个字节。
3.WPARAM wParam; 4.LPARAM lParam;
Additional information about the message. The exact meaning depends on the value of the message member.
第三和第四个成员是对第二层消息类型的详细描述。
5.DWORD time;
The time at which the message was posted.
动作或消息触发的时间。
6.POINT pt;
typedef struct tagPOINT { LONG x; LONG y;} POINT, *PPOINT;
The cursor position, in screen coordinates, when the message was posted.
消息被触发时鼠标的位置。及鼠标在屏幕上的位置,以1024x768屏幕为例,屏幕左上角既是坐标系的起点(0,0);向右是x轴,向下是y轴。
系统消息队列和应用程序消息队列
从流程图中我们可以清晰地看出消息的处理过程。当用户或系统触发某个动作时,系统将动作封装成一个消息及MSG结构体。然后将所属于应用程序的消息存储到应用程序的消息队列。应用程序从自己的消息队列循环的取出,翻译,派发消息。操作系统接受加工过的消息并调用窗口过程函数。
头条发文限制了,此代码略
最简单的窗口
留言与评论(共有 0 条评论) “” |