MFC,按"X"或“关闭",则应向其发送WM_close消息 [英] MFC, Press "X" or "Close” it should be sent a WM_close message

查看:487
本文介绍了MFC,按"X"或“关闭",则应向其发送WM_close消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 我有一个简单的MFC应用程序,当我按"X"或关闭"时,应该向它发送WM_close消息,并尝试在PreTranslateMessage(MSG * pMsg)中捕获它. WM_close消息?
在此先感谢
M.H

Hi I have a simple MFC applications which when I press "X" or "Close" it should be sent a WM_close message which I try to catch it in my PreTranslateMessage(MSG* pMsg). But It dosent come. What should I do to catch the WM_close message?
Thanks in advance
M.H

BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
{
	TRACE("\n MSG %d", pMsg->message);
	if(pMsg->message == WM_CLOSE)
		MessageBox("WM_CLOSE");
	else if(pMsg->message == WM_QUIT)
		MessageBox("WM_QUIT");
	else if(pMsg->message == WM_DESTROY )
		MessageBox("WM_DESTROY");
    return __super::PreTranslateMessage(pMsg); // allow default behavior
}

推荐答案

关闭(Alt + F4)的Big [X]或系统菜单(在图标中)通过"ON_WM_SYSCOMMAND"进入.在处理中寻找"SC_CLOSE"

The Big [X] or system menu (in the icon) of Close (Alt+F4) comes in through "ON_WM_SYSCOMMAND". In your processing look for "SC_CLOSE"

void YourClass::OnSysCommand(UINT nID, LPARAM lParam)
{
    if ((nID & 0xFFF0) == SC_CLOSE)
        {
        }
}


您需要分别处理WM_CLOSE消息

ON_WM_CLOSE()添加到您的消息映射中,然后向afx_msg void OnClose();类型的CMainFrame添加一个函数.
you need to handle the WM_CLOSE message seperatly

add ON_WM_CLOSE() to your message map, and then add a function to CMainFrame of type afx_msg void OnClose();


看看WM_SYSCOMMAND.我认为这是覆盖默认关闭和退出类型行为的方法.
Have a look at WM_SYSCOMMAND. I think that is how to override default close and exit type behaviour.


这篇关于MFC,按"X"或“关闭",则应向其发送WM_close消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆