1. Windows消息
Windows是一个基于事件的操作系统, 事件的本质是对消息的封装, 如鼠标移动点击, 键盘按键, 窗口移动尺寸变化等都会发送相应的消息.
Windows操作系统中包括以下几种消息:
消息范围 | 说 明 |
0 ~ WM_USER – 1 | 系统消息 |
WM_USER ~ 0x7FFF | 自定义窗口类整数消息 |
WM_APP ~ 0xBFFF | 应用程序自定义消息 |
0xC000 ~ 0xFFFF | 应用程序字符串消息 |
> 0xFFFF | 为以后系统应用保留 |
1、标准Windows消息:这种消息以WM_打头。
2、通知消息:通知消息是针对标准Windows控件的消息。这些控件包括:按钮(Button)、组合框(ComboBox)、编辑框(TextBox)、列表框(ListBox)、ListView控件、Treeview控件、工具条(Toolbar)、菜单(Menu)等。每种消息以不同的字符串打头。
具体见下表:
Prefix Message category
ABM Application desktop toolbar
BM Button control
CB Combo box control
CBEM Extended combo box control
CDM Common dialog box
DBT Device
DL Drag list box
DM Default push button control
DTM Date and time picker control
EM Edit control
HDM Header control
HKM Hot key control
IPM IP address control
LB List box control
LVM List view control
MCM Month calendar control
PBM Progress bar
PGM Pager control
PSM Property sheet
RB Rebar control
SB Status bar window
SBM Scroll bar control
STM Static control
TB Toolbar
TBM Trackbar
TCM Tab control
TTM Tooltip control
TVM Tree-view control
UDM Up-down control
WM General window
3、自定义消息:值在WM_USER以上的消息。
2. SendMessage/PostMessage发送消息
LRESULT SendMessage(
HWND hWnd,
UINT Msg,
WPARAM wParam,
LPARAM lParam
);
LRESULT PostMessage(
HWND hWnd,
UINT Msg,
WPARAM wParam,
LPARAM lParam
);
// 发送左键点击事件,坐标(32,34)
SendMessage(hWnd, WM_LBUTTONDOWN, 0, MAKELPARAM(32, 34));
Sleep(10);
SendMessage(hWnd, WM_LBUTTONUP, 0, MAKELPARAM(32, 34));
// 如果是标准Windows控件
SendMessage(hWnd, BM_CLICK, 0, 0);