为什么我的对话框程序在使用dlg.DoModal();   
      后不调用OnInitDialog()了?哪位大哥能分析一下会是什么原因吗?搞得我初始化对话框的程序都不调用了,好郁闷。。

解决方案 »

  1.   

    OnInitDialog()不用你专门来调用吧。你只需要在里面添加初始化代码就可以了。    比如   CMyDlg dlg;
       dlg.Domodal;
      
       这两句已经调用了OnInitDialog()。
      

  2.   

    是啊,我就是这样写的,
    CMyDlg dlg;
       dlg.Domodal;
     但是跟踪调试的时候发现没有调用OnInitDialog(),
       在里面写的初始化代码也都没执行
            不知什么原因?
      

  3.   

    这是我的代码,内容也就是在状态栏中加一些信息,测试用的MesasgeBox()也不执行啊 :
    BOOL CBitBookDlg::OnInitDialog()
    {
    MessageBox("OnInit");
    CDialog::OnInitDialog();
    // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range.
    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE);
    if (pSysMenu != NULL)
    {
    CString strAboutMenu;
    strAboutMenu.LoadString(IDS_ABOUTBOX);
    if (!strAboutMenu.IsEmpty())
    {
    pSysMenu->AppendMenu(MF_SEPARATOR);
    pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
    }
    } // Set the icon for this dialog.  The framework does this automatically
    //  when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE); // Set big icon
    SetIcon(m_hIcon, FALSE); // Set small icon

    // TODO: Add extra initialization here

    CTime t=CTime::GetCurrentTime();
    CString s=t.Format("%H:%M:%S");
       CBitBookApp* app=(CBitBookApp*)::AfxGetApp();
    s="当前系统时间:"+s;
    CString str; CRect rect;
    this->GetClientRect(&rect); m_StatusBarCtrl.Create(WS_CHILD|WS_VISIBLE|CCS_BOTTOM,rect,this,ID_STATUS_BAR_CTRL);

    int indicators[3];
    indicators[0]=rect.Width()/2;
    indicators[1]=rect.Width()*3/4;
    indicators[2]=rect.Width();
    m_StatusBarCtrl.SetParts(3,&indicators[0]); str.LoadString(IDS_COMPANY); m_StatusBarCtrl.SetText(str,0,0);
    m_StatusBarCtrl.SetText("当前操作员:"+app->m_sUserName,1,0);
    m_StatusBarCtrl.SetText(s,2,0); this->SetTimer(12,1000,NULL);
    InitPurview(); return TRUE;  // return TRUE  unless you set the focus to a control
    }
      

  4.   

    可能是你用NEW或在消息函数外定义dlg了,这样用的老是同一个对象,自然也就不会OnInitDialog()了。
      

  5.   

    估计是你的OnInitDialog()是自己写的吧?不是在VC的IDE上添加的,如果是你自己写的话可能在消息映射里忘记添加此类消息了