CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 21

Threaded View

  1. #1
    Join Date
    Nov 2011
    Posts
    72

    ASSERT when opening dialog box

    Environment: Windows XP Pro, Visual Studio 2008, MFC, C++

    I have regressed since my last post and now am getting an Assert when I click a button to open a second dialog box.
    Note: I cannot cut and paste from my work computer to my internet computer so please forgive any obvious typos.
    In the main window .h file I have:
    Code:
    …
    C_Logging_Control *mp_C_Logging_Control; // the class of the new dialog box
    …
    And in the .cpp file I have:
    Code:
    BOOL CAR2_Messasge_AppDlg::OnInitDialog() 
    {
    …
        // create the class that owns (??) the new dialog
       // I put a break point in C_Logging_Control constructor and it looks ok as it starts up.
    mp_C_Logging_Control = new C_Logging_Control;
    …. }
    
    ….  Much later, the code to open the new dialog
    Void C_AR2_Messasge_AppDlg::OnBnClickedBtnOpenLogControl()
    {
          // I will discuss these four lines in a moment
       bool test = false;
       bool window_value = ::IsWindows( m_hWnd);
       if( m_pCtrlSite != Null )
          test = true;
    
       if( mp_C_Logging_Control != NULL )
          mp_C_Logging_Control->ShowWindow( SW_SHOW );
    }
    Everything works until the call to ShowWindow which generates an ASSERT. I step into the ShowWindow code and the assert is in winocc.cpp and the code is:
    Code:
    BOOL CWnd::ShowWindow( int nCmdShow )
    {
       ASSERT( ::IsWindow( m_hWnd) || (m_pCtrlSite != Null) );
    …
    }
    This is the ASSERT that halts everything.
    I took that ASSERT line of code, broke it up, and put it into my code that calls ShowWindow. That’s the four lines where I said they would be discussed in a moment.
    I was a little bit surprised that it compiled, but that’s cool.
    Bool window_Value is true after the call to IsWindows( m_hWnd )
    As I read it, that means that the assert gets a true and should not bomb out.

    So,…, are those four noted lines valid when I put them in my code?
    Can someone detect the error on my part?

    After another hour of work, the answer to the first question is No! Here is why:
    I copied winocc.cpp into my project, adjusted its include files to reference the normal place, then broke up the ASSERT and discovered that ::IsWindow( m_hWnd) returns a false. Its OK in my code, but once deep down into the dialog’s code, its not. (I think that is the case.)

    But now I don’t know what that means or how to fix it. Can someone clue me in on this?

    Thank you for your time.

    EDIT: I just found someing in some example code that translates to this in my code:
    Code:
     mp_C_Logging_Control->Attach( hWnd );
    The problem is that I don'w know the general meaning of hWind and what I need to use in my code. Is this the answer or is it something else.
    Last edited by bkelly; August 21st, 2012 at 03:25 PM. Reason: New info

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured