在程序中执行到::AfxMessageBox("aaa");时显示不出来消息框。不知道是怎么回事。程序是基于对话框的程序,在APP{}中可以显示,在Dlg{}中就不能显示了,但是能执行过去。

解决方案 »

  1.   

    最好帖出代码来。在Dlg中,用AfxMessageBox()试试,前面不要带上"::"
      

  2.   

    我的代码如下,不管在哪里都可以显示消息框,所以一定是你代码的问题:BOOL CDelApp::InitInstance()
    {
    AfxEnableControlContainer(); // Standard initialization
    // If you are not using these features and wish to reduce the size
    //  of your final executable, you should remove from the following
    //  the specific initialization routines you do not need.#ifdef _AFXDLL
    Enable3dControls(); // Call this when using MFC in a shared DLL
    #else
    Enable3dControlsStatic(); // Call this when linking to MFC statically
    #endif AfxMessageBox("hello app"); CDelDlg dlg;
    m_pMainWnd = &dlg;
    int nResponse = dlg.DoModal();
    if (nResponse == IDOK)
    {
    // TODO: Place code here to handle when the dialog is
    //  dismissed with OK
    }
    else if (nResponse == IDCANCEL)
    {
    // TODO: Place code here to handle when the dialog is
    //  dismissed with Cancel
    } // Since the dialog has been closed, return FALSE so that we exit the
    //  application, rather than start the application's message pump. return FALSE;
    }BOOL CDelDlg::OnInitDialog()
    {
    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

    AfxMessageBox("hello dlg");

    return TRUE;  // return TRUE  unless you set the focus to a control
    }
      

  3.   

    在我上面的代码中,不管AfxMessageBox前是否带上::,都可以弹出消息框的。
      

  4.   

    我一般直接用:
    AfxMessageBox("aaa");不明白为何要用::AfxMessageBox("aaa");
      

  5.   

    在调用对话框的代码后面
    int err = WSAGetLastError();
    并设断点看反回值是什么。
      

  6.   

    使用MessageBox也可以使用AfxMessageBox(strMess);应先使用str.FormatMessage(strMess);格式,然后再使用AfxMessageBox(strMess);
      

  7.   

    CString strMess ;

    strMess.Format("这里是你要显示的字符串或字符变量名");
    AfxMessageBox(strMess);