当前位置:网站首页>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 .
边栏推荐
- Unexpected ‘debugger‘ statement no-debugger
- 谷粒商城项目
- After class assignment of module 5 of the construction practice camp
- Is it safe for Hengtai securities to open an account? Ranking of securities
- How to create new user for ORACLE 19c (CDB & PDB)
- 文件包含之日志中毒(User-Agent)
- 【智能QbD风险评估工具】上海道宁为您带来LeanQbD介绍、试用、教程
- 535. TinyURL 的加密与解密 : 设计一个 URL 简化系统
- 《Go题库·14》WaitGroup的坑
- Proteus软件初学笔记
猜你喜欢

多项目开发入门-业务场景关联基础入门测试 工资表

ERP编制物料清单 金蝶

解决问题:ModuleNotFoundError: No module named ‘pip‘

高校如何基于云原生构建面向未来的智慧校园?全栈云原生架构VS传统IT架构

推荐模型复现(四):多任务模型ESMM、MMOE

QQ集体被盗号,猝不及防的大型社死名场面

Imile uses Zadig's multi cloud environment to deploy thousands of times a week to continuously deliver global business across clouds and regions

对p值的理解

谷粒商城项目

How to create new user for ORACLE 19c (CDB & PDB)
随机推荐
When you are young, you should be awake to fight, and when you are young, you should have the courage to try
ArtBench:第一个类平衡的、高质量的、干净注释的和标准化的艺术品生成数据集
1. Opencv实现简单颜色识别
Difficult conversation breaks through the bottleneck of conversation and achieves perfect communication
The blackened honeysnow ice city wants to grasp the hearts of consumers by marketing?
MFC-对话框程序核心-IsDialogMessage函数-MSG 消息结构-GetMessage函数-DispatchMessage函数
文件包含之日志中毒(User-Agent)
After class assignment of module 5 of the construction practice camp
Unexpected ‘debugger‘ statement no-debugger
Titanium dynamic technology: our Zadig landing Road
Wonderful! Miaoying technology fully implements Zadig to help container construction, and fully embraces kubernetes and Yunyuan
ERP preparation of BOM basis
Is it safe for Orient Fortune Securities to open an account? Handling of securities account opening
GBase8s数据库FOR UPDATE 子句
Introduction to multi project development - business scenario Association basic introduction test payroll
nacos启动报错
GBase8s数据库select有ORDER BY 子句1
Interview shock 61: tell me about MySQL transaction isolation level?
如何计算win/tai/loss in paired t-test
架构实战营第五模块课后作业