根据<<Programing Microsoft C++>>中的Chapter Seven --The Modeless Dialog and Windows Common Dialogs设计的对话框,其上的OK按钮的代码为:
void CCxlDlg::OnOK() 
{
// TODO: Add extra validation here
if (m_pView != NULL) {
          m_pView->PostMessage(WM_GOODBYE, IDOK);
  AfxMessageBox("Begin");
  for (int i = 0;i<100000;i++)
  {
  if (i == 99999)
  {
AfxMessageBox("End");
  }
  }
    }
else
CDialog::OnOK();
}其中AfxMessageBox("Begin")这句代码不执行,为什么?

解决方案 »

  1.   

    AfxMessageBox("Begin")这句代码不执行?
    m_pView=?
      

  2.   

    AfxMessageBox("End");这个还是执行的,但是AfxMessageBox("Begin");就是不执行,也没有重叠
      

  3.   

    你把
    m_pView->PostMessage(WM_GOODBYE, IDOK);
    给屏了,执行吗?如果执行了的话,看看你的字定义消息。
    不执行的话,想不通
      

  4.   

    if (m_pView != NULL) {
              m_pView->PostMessage(WM_GOODBYE, IDOK);
      AfxMessageBox("Begin0");
      AfxMessageBox("Begin1");
      AfxMessageBox("Begin2");
      AfxMessageBox("Begin3");
      AfxMessageBox("Begin4");
      AfxMessageBox("Begin5");
      for (int i = 0;i<100000;i++)
      {
      if (i == 99999)
      {
    AfxMessageBox("End");
      }
      }
        }
    else
    CDialog::OnOK();
      

  5.   

    to sungengyu(快乐机器) :
     只有AfxMessageBox("Begin0");不执行
      

  6.   

    如果真的如同楼主描述,那这个问题还真的蹊跷了哈;
    DWORD err=GetLastError();
    TRACE("%d",err);
    查查看,有没有错误什么的
      

  7.   

    void CCxlDlg::OnOK() 
    {
    // TODO: Add extra validation here
             ASSERT(m_pView) ;
    if (m_pView != NULL) {
              m_pView->PostMessage(WM_GOODBYE, IDOK);
      AfxMessageBox("Begin");
      for (int i = 0;i<100000;i++)
      {
      if (i == 99999)
      {
    AfxMessageBox("End");
      }
      }
        }
    else
    CDialog::OnOK();
    }如果出现了异常,你就查一查你的 m_pView ,他肯定是空
      

  8.   

    impossible
    拜托重新描述一次
      

  9.   

    稀奇之极,估计是由于m_pView->PostMessage(WM_GOODBYE, IDOK);
    送出消息并执行后引起的
      

  10.   

    重新描述如下:
    根据<<Programing Microsoft C++>>中的Chapter Seven --The Modeless Dialog and Windows Common Dialogs 1、Run AppWizard to produce Single Document 
    2、Use the dialog editor to create a dialog resource
    3、Use ClassWizard to create the CCxlDlg class
    4、Type in the following code in the CCxlDlg class declaration:
    private:
        CView* m_pView;
    Also, add the function prototypes as follows:
    public:
        CEx07aDialog(CView* pView);
        BOOL Create();
    5、Edit CCxlDlg.h to define the WM_GOODBYE message ID. Add the following line of code:#define WM_GOODBYE     WM_USER + 100
    6、Add the modeless constructor in the file CCxlDlg.cpp. You could modify the existing CCxlDlgconstructor, but if you add a separate one, the dialog class can serve for both modal and modeless dialogs. Add the lines shown below. CCxlDlg::CCxlDlg(CView* pView)  // modeless constructor
    {
        m_pView = pView;
    }
    You should also add the following line to the AppWizard-generated modal constructor: 
    m_pView = NULL;
    7、Add the Create function in CCxlDlg.cpp. This derived dialog class Create function calls the base class function with the dialog resource ID as a parameter. Add the following lines: BOOL CCxlDlg::Create()
    {
        return CDialog::Create(CCxlDlg::IDD);
    }8、Edit the OnOK and OnCancel functions in CCxlDlg.cpp
    到这里就是OK的代码:
    void CCxlDlg::OnOK() 
    {
    // TODO: Add extra validation here
    if (m_pView != NULL) {
              m_pView->PostMessage(WM_GOODBYE, IDOK);
      AfxMessageBox("Begin"); ///从这里开始
      for (int i = 0;i<100000;i++)
      {
      if (i == 99999)
      {
    AfxMessageBox("End");
      }
      }//到这里结束是自己加上去的,是想测试一下POSTMESSAGE的作用,但是 AfxMessageBox("Begin"); 就是不执行
        }
    else
    CDialog::OnOK();
    }
    void CCxlDlg::OnCancel()  // not really a message handler
    {
        if (m_pView != NULL) {
            // modeless case -- do not call base class OnCancel
            m_pView->PostMessage(WM_GOODBYE, IDCANCEL);
        }
        else {
            CDialog::OnCancel(); // modal case
        }
    }
    9、Edit the ex07aView.h header file. You need a data member to hold the dialog pointer: 
    private:
        CCxlDlg* m_pDlg;
    10、CEx07aView::CEx07aView()
    {
        m_pDlg = new CEx07aDialog(this);
    }
    CEx07aView::~CEx07aView()
    {
        delete m_pDlg; // destroys window if not already destroyed
    }
    void CEx07aView::OnDraw(CDC* pDC)
    {
        pDC->TextOut(0, 0, "Press the left mouse button here.");
    }
    void CEx07aView::OnLButtonDown(UINT nFlags, CPoint point)
    {
        // creates the dialog if not created already
        if (m_pDlg->GetSafeHwnd() == 0) {
            m_pDlg->Create(); // displays the dialog window
        }
    }
    11、Add your own message code for the WM_GOODBYE message
    In ex07aView.cpp, add the following line after the BEGIN_MESSAGE_MAP statement but outside the AFX_MSG_MAP brackets:ON_MESSAGE(WM_GOODBYE, OnGoodbye)Also in ex07aView.cpp, add the message handler function itself: LRESULT CEx07aView::OnGoodbye(WPARAM wParam, LPARAM lParam)
    {
        // message received in response to modeless dialog OK
        //  and Cancel buttons
        m_pDlg->DestroyWindow();
        return 0L;
    }
    In ex07aView.h, add the following function prototype before the DECLARE_MESSAGE_MAP() statement but outside the AFX_ MSG brackets:afx_msg LRESULT OnGoodbye(WPARAM wParam, LPARAM lParam);Then Build ,Execute,press the OK button on popup dialog,you'll see the result 
      

  11.   

    m_pDlg = new CEx07aDialog(this);改为m_pDlg = new CCxlDlg(this);