MFC对话框消息处理程序中的异常 [英] Exception in MFC dialog message handler
本文介绍了MFC对话框消息处理程序中的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我在CDialog
类的OnSize()
消息处理程序中有一个CInvalidArgException
Hi
I have got an CInvalidArgException
in OnSize()
message handler of a CDialog
class
void CDlgTestAppDlg::OnSize(UINT nType, int cx, int cy)
{
try
{
CDialog::OnSize(nType, cx, cy);
m_txtImageCtrl.SetWindowText( _T( "0/0" ));
}
catch( CException *pExp_i )
{
// CInvalidArgException
delete pExp_i;
pExp_i = 0;
}
}
这里m_ txtImageCtrl
是CEdit
的实例,编辑控件是在dailog资源中创建的.问题是OnSize()
在创建OnInitDialog()
之前的编辑ctrl的window(hWnd handle)之前被调用.我已使用Visual Studio 2008创建应用程序
关于如何解决此问题的任何想法
here m_txtImageCtrl
is an instance of CEdit
, edit control is created in dailog resource. Problem is that OnSize()
is called before creating the window( hWnd handle ) of the edit ctrl that is before OnInitDialog()
. I have used Visual Studio 2008 for creating the application
Any idea about how to resolve this
推荐答案
只需替换:
Just replace:
m_txtImageCtrl.SetWindowText( _T("0/0" ));
与:
with:
if (::IsWindow(m_txtImageCtrl.m_hWnd))
m_txtImageCtrl.SetWindowText( _T( "0/0" ));
对话框启动期间,多次调用了
OnSize
.只需在执行任何操作之前检查m_txtImageCtrl
是否为空.
OnSize
is called several times during dialog startup. Just check to see ifm_txtImageCtrl
is null before doing anything with it.
是的,
我的对话框中有太多控件无法归类,
除了检查手柄外,没有其他方法.
现在我为此使用了一个布尔值,它在CDialog::OnInitDialog()
Yes,
I have too many controls to be subclassed with in the dialog,
Is any other way than checking the handle.
Now I used a boolean for this, it is set totrue
afterCDialog::OnInitDialog()
这篇关于MFC对话框消息处理程序中的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文