当前位置:网站首页>MFC dialog program core -isdialogmessage function -msg message structure -getmessage function -dispatchmessage function
MFC dialog program core -isdialogmessage function -msg message structure -getmessage function -dispatchmessage function
2022-06-29 12:38:00 【Plug in development】
List of articles
stay MFC Programming , Common messages are as follows :
#define WM_INITDIALOG 0x0110
#define WM_COMMAND 0x0111
#define WM_MOUSEMOVE 0x0200
#define WM_CREATE 0x0001
#define WM_DESTROY 0x0002
#define WM_MOVE 0x0003
#define WM_SIZE 0x0005
#define WM_PAINT 0x000F
#define WM_CLOSE 0x0010
#define WM_SHOWWINDOW 0x0018
#define SPI_SETGRADIENTCAPTIONS 0x1009
if necessary Hook Window message , These functions must have some understanding of the program .
1.IsDialogMessage function
The functionality : This function determines whether a message is assigned to the specified dialog , If it is , Then process the message .
The function prototype :BOOL IsDialogMessage(HWND hDlg,LPMSG IpMsg);
hDlg: Identification dialog .
IpMsg: Point to a that contains a message to be detected MSG structure .
Return value : If the message is processed , The return value is nonzero ; If the message is not processed , The return value is zero .
Check whether the message is the dialog message of the corresponding handle , If it is , Then hand in one user32.dll Module alignment for processing , actually user32.dll The module forwards it to the window function to which the dialog belongs , Judge the message in the window function of the dialog box , Finally, call the function corresponding to the message , The function corresponding to the message is mapped previously , Already exists in the dialog message mapping table .
while(GetMessage(&stMsg,NULL,0,0))
{
if(!IsDialogMessage(hDlg,&stMsg))
{
TranslateMessage(&stMsg);
DispatchMessage(&stMsg);
}
}
MSG Message structure
stay Windows In the program , The news is from MSG To express by structure .
Structural prototype :
typedef struct tagMSG {
HWND hwnd;
UINT message;
WPARAM wParam;
LPARAM lParam;
DWORD time;
POINT pt;
} MSG, *PMSG, *LPMSG;
To obtain parameters , Then forward .
2.GetMessage function
In the create window 、 Display window 、 After updating the window , We need to write a message loop , Constantly pulling messages from the message queue , And respond . To get a message from the message queue , We need to call GetMessage() function , The prototype declaration of this function is as follows :
BOOL GetMessage(
LPMSG lpMsg, // address of structure with message
HWND hWnd, // handle of window
UINT wMsgFilterMin, // first message
UINT wMsgFilterMax // last message
);
Parameters lpMsg Point to a message (MSG) Structure .GetMessage The message information retrieved from the thread's message queue will be saved in the structure object .
Parameters hWnd Specify which window to receive messages from . Usually we set it to NULL, Used to receive window messages for all windows belonging to the calling thread .
Parameters wMsgFilterMin Specify the minimum value of the message to get , Usually set to 0.
Parameters wMsgFilterMax Specify the maximum number of messages to get . If wMsgFilterMin and wMsgFilter Max Set to 0, Then all messages are received .
GetMessage Function received Division WM_QUIT All messages except return non-zero values . about WM_QUIT news , This function returns zero . If something goes wrong , This function returns -1, for example , When parameters hWnd Is an invalid window handle or lpMsg Is an invalid pointer .
3.DispatchMessage function
WINUSERAPI
LRESULT
WINAPI
DispatchMessageA(
_In_ CONST MSG *lpMsg);
The function prototype :LONG DispatchMessage(CONST MSG*lpmsg);
Parameters :lpmsg: Point to the... Containing the message MSG Pointer to structure .
Return value : The return value is the value returned by the window program . Although the meaning of the return value depends on the message being scheduled , But the return value is usually ignored .
4. Window procedure function model
LONG OldWndProc = 0;
LRESULT CALLBACK WindowProc2( HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
if (uMsg == WM_KEYDOWN)
{
if (wParam == VK_F6)
{
AfxMessageBox(L" You pressed F6 key ");
}
}
return CallWindowProc((WNDPROC)OldWndProc,hwnd,uMsg,wParam,lParam);
}
void CttDlg::OnBnClickedOk()
{
// TODO: Add control notification handler code here
OldWndProc = ::SetWindowLong(m_hWnd,GWL_WNDPROC,(LONG)WindowProc2);
}
5. Author Q & A
If you have any questions , Please leave a message .
边栏推荐
- Titanium dynamic technology: our Zadig landing Road
- MySQL master-slave synchronous asynchronous replication semi synchronous replication full synchronous replication
- [pbootcms template] composition website / document download website source code
- Is it safe for Hengtai securities to open an account? Ranking of securities
- 《高难度谈话》突破谈话瓶颈,实现完美沟通
- Cereal mall project
- Inferiority complex and transcendence the meaning of life to you
- The blackened honeysnow ice city wants to grasp the hearts of consumers by marketing?
- ArtBench:第一个类平衡的、高质量的、干净注释的和标准化的艺术品生成数据集
- Is it safe for Orient Fortune Securities to open an account? Handling of securities account opening
猜你喜欢

Cocos star meetings at Hangzhou station in 2022

如何计算win/tai/loss in paired t-test

模糊图片变清晰,一键双色图片,快速整理本地图片...这8个在线图片工具申请加入你的收藏夹!

MIT线性代数中文笔记

Method area of JVM

How to install oracle19c in Centos8

测试--自动化测试:关于unittest框架
![[JUC series] ThreadLocal of synchronization tool class](/img/15/2f8ce68b9e5ee8dab03fb688712935.png)
[JUC series] ThreadLocal of synchronization tool class

Earth observation satellite data

多项目开发入门-业务场景关联基础入门测试 工资表
随机推荐
Go高级工程师必修课 | 真心建议你来听听,别错过~
oracle 19c : change the user sys/system username pasword under Linux
1. Opencv实现简单颜色识别
GBase8s数据库select有ORDER BY 子句1
GBase8s数据库在组合查询中的集合运算符
Pangolin compilation error: 'numeric_ limits’ is not a member of ‘std’
cmake 报错
ERP preparation of BOM basis
GBase8s数据库select有ORDER BY 子句
架构实战营第五模块课后作业
Li Kou daily question - day 31 -13 Roman array to integer
对p值的理解
Gbase8s database sorts standard or raw result tables
GBase8s数据库INTO table 子句
GBase8s数据库FOR READ ONLY 子句
Inferiority complex and transcendence the meaning of life to you
[leetcode] 14. Longest public prefix
NvtBack
多项目开发入门-业务场景关联基础入门测试 工资表
Is it safe for Hengtai securities to open an account? Ranking of securities