Click here to Skip to main content
15,888,401 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
Hi
I have got an CInvalidArgException in OnSize() message handler of a CDialog class
C++
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;
    }
}

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
Posted
Updated 13-May-10 0:03am
v5
Comments
Moak 13-May-10 6:02am    
Updated subject and tags, hope this is what you are looking for.

Just replace:

C++
m_txtImageCtrl.SetWindowText( _T("0/0" ));


with:

C++
if (::IsWindow(m_txtImageCtrl.m_hWnd))
   m_txtImageCtrl.SetWindowText( _T( "0/0" ));
 
Share this answer
 
OnSize is called several times during dialog startup. Just check to see if m_txtImageCtrl is null before doing anything with it.
 
Share this answer
 
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 to true after CDialog::OnInitDialog()
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900