void CMyToolBar::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(PtInRect(m_rect[1], point))
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
CToolBar::OnLButtonUp(nFlags, point);
}
上面一段代码是左键弹起消息处理函数的简化版本,大致意思是在工具栏上自画一个矩形按钮,然后当左键在矩形按钮上弹起时弹出“关于”对话框,这看起来似乎很正常。可是偶然发现对话框跳出时并未完全获取焦点,理由是第一次点击对话框上的按钮时未有任何反应。而是首先要先点击对话框一次,以后的动作就正常了。但是我猜测可能是进入这个左键弹起消息函数时某种信号量被占用,而对话框获取不到,要认为第点击对话框获取,根据这一设想我换了一种思路
void CMyToolBar::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CToolBar::OnLButtonUp(nFlags, point);
if(PtInRect(m_rect[1], point))
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
}
让父类函数CToolBar::OnLButtonUp(nFlags, point)先执行释放某些资源,这样做成功了。对话框一切正常。
可是我在这个函数中还有一个按钮是跳出文件打开对话框,它放在前面执行就很正常,难道它与“关于”对话框有什么不同嘛?
这个现象很怪异,希望看到此文章的高手指点一下。虽然我用上面的方法暂时解决了问题,但是我还是很想知道真正的原因。大侠们不吝赐教。呵呵!