让状态条响应鼠标事件引发断言失败

liups 2015-01-17 01:01:47
参考这里来的:
http://blog.csdn.net/fishion/article/details/3908542
我的代码如下:
BOOL CMainFrame::PreTranslateMessage(MSG* pMsg) 
{
// TODO: Add your specialized code here and/or call the base class
if(pMsg->message == WM_LBUTTONDOWN && pMsg->hwnd == m_wndStatusBar.GetSafeHwnd())
{
CRect rect;
CPoint pt;
pt = pMsg->pt;
m_wndStatusBar.GetItemRect(4,&rect);
m_wndStatusBar.ClientToScreen(&rect);
if(PtInRect(&rect,pt))
{
//Add your function
//AfxMessageBox("Date");
if (theApp.m_bIsAdmin=="1")
{
CDateDlg Dlg;
if (Dlg.DoModal()==IDOK)
{
CString tmpstr="当前处理时间:"+theApp.m_strOperDate;
m_wndStatusBar.SetPaneText(4,(LPCTSTR)tmpstr);
}
}
else
{
AfxMessageBox("管理员才能运行本模块!");
}

}
}
return CFrameWnd::PreTranslateMessage(pMsg);
}

功能是能正常实现的,但是最后一句
	return CFrameWnd::PreTranslateMessage(pMsg);

会引发断言失败,具体是wincore.cpp中的886行的ASSERT(::IsWindow(m_hWnd));,代码如下:
#ifdef _DEBUG
void CWnd::AssertValid() const
{
if (m_hWnd == NULL)
return; // null (unattached) windows are valid

// check for special wnd??? values
ASSERT(HWND_TOP == NULL); // same as desktop
if (m_hWnd == HWND_BOTTOM)
ASSERT(this == &CWnd::wndBottom);
else if (m_hWnd == HWND_TOPMOST)
ASSERT(this == &CWnd::wndTopMost);
else if (m_hWnd == HWND_NOTOPMOST)
ASSERT(this == &CWnd::wndNoTopMost);
else
{
// should be a normal window
ASSERT(::IsWindow(m_hWnd));

// should also be in the permanent or temporary handle map
CHandleMap* pMap = afxMapHWND();
ASSERT(pMap != NULL);

CObject* p;
ASSERT((p = pMap->LookupPermanent(m_hWnd)) != NULL ||
(p = pMap->LookupTemporary(m_hWnd)) != NULL);
ASSERT((CWnd*)p == this); // must be us

// Note: if either of the above asserts fire and you are
// writing a multithreaded application, it is likely that
// you have passed a C++ object from one thread to another
// and have used that object in a way that was not intended.
// (only simple inline wrapper functions should be used)
//
// In general, CWnd objects should be passed by HWND from
// one thread to another. The receiving thread can wrap
// the HWND with a CWnd object by using CWnd::FromHandle.
//
// It is dangerous to pass C++ objects from one thread to
// another, unless the objects are designed to be used in
// such a manner.
}
}



我感觉这个状态栏本来就不是窗口,所以似乎应该忽略这个断言,请大家教我

...全文
59 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
liups 2015-01-17
  • 打赏
  • 举报
回复
引用 1 楼 dingxz105090 的回复:
if(pMsg->message == WM_LBUTTONDOWN && pMsg->hwnd == m_wndStatusBar.GetSafeHwnd()) { //........Your code here........... return TRUE; } return CFrameWnd::PreTranslateMessage(pMsg);
谢谢,搞定了
凌乱哥 2015-01-17
  • 打赏
  • 举报
回复
if(pMsg->message == WM_LBUTTONDOWN && pMsg->hwnd == m_wndStatusBar.GetSafeHwnd()) { //........Your code here........... return TRUE; } return CFrameWnd::PreTranslateMessage(pMsg);

16,473

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧