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

Thread: urgent oncreate

  1. #1
    Join Date
    May 2003
    Location
    India
    Posts
    111

    urgent oncreate

    hi gurus
    i am trying to create mainframe window at runtime .in OnCreate function i am creating one dialog and then i am calling the funtion
    if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
    return -1;
    but after this it is giving the assertion failure error in OnCreate function. please help me in solving this error

    thanking all

  2. #2
    Join Date
    Sep 2003
    Posts
    90
    what are you trying to do before the framewnd creation?

  3. #3
    Join Date
    May 2003
    Location
    India
    Posts
    111
    i am creating the dialog box through that i am connecting to the com1(serial port) and after connection , it is establishing the connection properly and and after connection, i am creating the frame window there it is giving assertion failure

  4. #4
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917
    Car problem again?(see link)
    Originally posted by Tejas
    i am trying to create mainframe window at runtime
    It is always runtime creation.
    Originally posted by Tejas
    OnCreate function i am creating one dialog
    OnCreate member of what class?
    Originally posted by Tejas
    but after this it is giving the assertion failure error in OnCreate
    Originally posted by Tejas
    i am creating the dialog box through that i am connecting to the com1(serial port) and after connection , it is establishing the connection properly and and after connection, i am creating the frame window there it is giving assertion failure
    Again OnCreate where (what class)? What line of code the assertion fires?
    Originally posted by Tejas
    please help me in solving this error
    After you give enough information it will probably be possible.
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  5. #5
    Join Date
    May 2003
    Location
    India
    Posts
    111
    hi gurus
    my problem is i ma getting the assertion failure error in the following OnCreate funtion .
    in this function i am invoking an dialog box which is used to connect to the com1(serial communication port) but this process is succesfull. when it comes to this point in the function it will cause assertion failure error
    if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
    return -1;

    in dialog box the error looks like this
    Debug assertion failed!

    Program:C:\vc++programs\win_proj\winviews\debug\winviews.exe
    File:afxwin2.inl
    Line:140

    For information on how your program can cause an assertion
    Failure , see the visual C++ documentation on asserts .

    (Press retry to debug the application)

    abort retry ignore

    and the assertion in afxwin2.inl is at this location

    _AFXWIN_INLINE BOOL CWnd::IsWindowVisible() const
    { ASSERT(::IsWindow(m_hWnd)); return ::IsWindowVisible(m_hWnd); }

    my funtion is
    //##ModelId=3FA62C7E004E

    int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {


    BOOL bFirstPass=TRUE;

    while (TRUE) {
    //Get user a chance to set the port.
    if (!g_IniFile.m_bAutoConnect || !bFirstPass) {
    CComDlg dlg;
    if (IDCANCEL==dlg.DoModal())
    return -1; //User bagged out
    }

    if (g_comPort.init(g_IniFile.m_nComPort))
    break;

    // Also, give user a chance to change port number if bad
    char szBuf[256];
    if (g_IniFile.m_nComPort != 0)
    sprintf(szBuf, "Unable to initialize port %d", g_IniFile.m_nComPort);
    else
    sprintf(szBuf, "Unable to initialize demo port");
    lstrcat(szBuf, "\n\nTry a different port?");

    if (IDYES != MessageBox(szBuf, "Error", MB_ICONSTOP|MB_YESNO|MB_DEFBUTTON2))
    return -1;

    bFirstPass=FALSE;
    }


    if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
    return -1;

    LoadAccelTable(MAKEINTRESOURCE(IDR_MAINFRAME));

    //Create the terminal window for the client area
    if (!m_wndTerminal.init(this, 1, RX_BUF_SIZE, &g_IniFile.m_fontTerminal))
    return -1;

    //Create the data display window for the client area
    if (!m_wndData.init(this, 2, &g_IniFile.m_fontDataDisplay))
    return -1;

    //TESTING - WNDSTATUS
    //Create the data display window for the client area
    if (!m_wndStatus.init(this, 3, &g_IniFile.m_fontDataDisplay))
    return -1;
    //TESTING - WNDSTATUS

    //Show the one which goes with the mode.
    if (!m_wndToolBar.Create(this)
    || !m_wndToolBar.LoadBitmap(IDR_MAINFRAME)
    || !m_wndToolBar.SetButtons(buttons, sizeof(buttons)/sizeof(UINT)))
    {
    MessageBox("Failed to create toolbar", "Error", MB_ICONSTOP|MB_OK);
    return -1; // fail to create
    }
    m_wndToolBar.ShowWindow(g_IniFile.m_bTerminalHasToolBar ? SW_SHOW : SW_HIDE);


    if (!m_wndStatusBar.Create(this)
    || !m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT)))
    {
    MessageBox("Failed to create status bar", "Error", MB_ICONSTOP|MB_OK);
    return -1; // fail to create
    }
    m_wndStatusBar.ShowWindow(g_IniFile.m_bTerminalHasStatusBar ? SW_SHOW : SW_HIDE);

    m_uiTimerID = SetTimer(ID_MAIN_TIMER, MAIN_TIMER_RES, NULL);
    if (!m_uiTimerID)
    return -1;

    //For now, come up in terminal mode
    setTerminalMode();
    return 0;
    }

  6. #6
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917
    So, the assertion fires in a dialog not in OnCreate of the main frame.

    It does not fire in CFrameWnd::OnCreate(lpCreateStruct) as you have posted.

    It fails check (::IsWindow(m_hWnd) meaning window does not exist.

    It is very obvious that you are calling IsWindowVisible member of CWnd from your dialog for some control object but window has not been attached to that object yet (created or subclassed).

    Where are you placed that call? It should not be in constructor (most likely a case) but in WM_INITDIALOG handler – OnInitDialog.
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

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