一个Wizard生成多文档MFC应用,如下
BOOL CMyApp::InitInstance()
{
.....
// 创建主 MDI 框架窗口
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame || !pMainFrame->LoadFrame(IDR_MAINFRAME))
return FALSE;
m_pMainWnd = pMainFrame;
.....
pMainFrame->DoSomething(); return TRUE;
}int CMainFrame::DoSomething()
{
m_dlgBar.DoSomething(); // CDialogBar m_dlgBar   return 0;
}int CDialogBar::DoSomething()
{  m_ComboBox.reset();
  return 0;
}ComboBox:: DoSomething()
{
  ResetContent();  //出错
}在CDialogBar上放个按钮,执行m_ComboBox.ResetContent();  一切正常,而通过CMyApp的initInstance()调用Dosometing()则出错,提示在AfxWin2.inl出错,通过debug看CDialogBar的hWnd = 00000000
这是为什么?正常情况下hWnd应该为0么?

解决方案 »

  1.   

    抱歉,问题的
    最后一个函数写错了
    应该是
    ComboBox:: Reset()
    {
      ResetContent();  //出错
    }请各位大虾指教
      

  2.   

    是因为hwnd = 0x00000000,所以说dialogBar尚未创建成功吗?请问,在CMyApp的什么事件时,Doc, mainFrame,都创建完成了?
    我该在什么事件调用?
      

  3.   

    是的
    该在mainFrame的OnCreate函数时调用
      

  4.   

    我试图将
    void CMyApp::OnAppAbout()
    {
    CMainFrame *pMainFrame = (CMainFrame*) AfxGetMainWnd();

    pMainFrame->DoSomething();
    //CAboutDlg aboutDlg;
    //aboutDlg.DoModal();
    }
    还是在那个地方出错
    应该是调用的问题
    因为此时,整个应用的初始化都完成了,我用帮助菜单下的关于来调用还是不行
      

  5.   

    ComboBox:: Reset()
    { // 该处设断点,执行后,debug提示如下
      ResetContent();  //出错
    }在debug中,
    this     cxx0069:error: variable needs stack frame
    是什么意思?
    谢谢各位帮忙
      

  6.   

    m_dlgBar does not create itself, even after CMyApp::InitInstance. You have to create it manually at some point.
      

  7.   

    创建时肯定成功了,因为在CMyApp::OnAppAbout()中执行同样的操作,还是出现同样的问题我都可以执行菜单命令了,怎么回还有没创建成功的呢?此时如果我使用m_dlgBar上的按钮执行该操作
    虽然debug也提示
    在debug中,
    this     cxx0069:error: variable needs stack frame
    但一切都可以执行,而且没有任何弹出错误