VC中手动添加OnSysCommand函数
VC中手动添加OnSysCommand函数
代码
VC中手动添加消息映射:
1、先在CMainFrame的类定义处加上:
void OnSysCommand(UINT nID, LPARAM lParam);
2、在消息映射处添加ON_WM_SYSCOMMAND():
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_SYSCOMMAND()
......
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
3、然后编写OnSysCommand函数:
void CMainFrame::OnSysCommand(UINT nID, LPARAM lParam)
{
if(nID == SC_MINIMIZE)
{
......
}
else
{
CMDIFrameWnd::OnSysCommand(nID, lParam);
}
}
如果窗体是对话框,则:
void CDlgDataMenu::OnSysCommand(UINT nID, LPARAM lParam)
{
if(nID == SC_CLOSE)
{
::SendMessage(AfxGetMainWnd()->m_hWnd, WM_CLOSE, 0, 0);//关闭主窗体(线程),结束进程
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
1、先在CMainFrame的类定义处加上:
void OnSysCommand(UINT nID, LPARAM lParam);
2、在消息映射处添加ON_WM_SYSCOMMAND():
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_SYSCOMMAND()
......
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
3、然后编写OnSysCommand函数:
void CMainFrame::OnSysCommand(UINT nID, LPARAM lParam)
{
if(nID == SC_MINIMIZE)
{
......
}
else
{
CMDIFrameWnd::OnSysCommand(nID, lParam);
}
}
如果窗体是对话框,则:
void CDlgDataMenu::OnSysCommand(UINT nID, LPARAM lParam)
{
if(nID == SC_CLOSE)
{
::SendMessage(AfxGetMainWnd()->m_hWnd, WM_CLOSE, 0, 0);//关闭主窗体(线程),结束进程
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}