这是我的一段程序。我想用OnButtonVisionGrab()跳出OnButtonVisionInit()中的while循环,怎么做。谢谢了!
void CTestDlg::OnButtonVisionInit() 
{
// TODO: Add your control notification handler code here m_TempFlag = 1; CWnd* pStartButton = GetDlgItem(IDC_BUTTON_VISION_INIT);
if(pStartButton != NULL)
{
pStartButton->EnableWindow(FALSE);
} m_Digitizer.Halt();
m_Digitizer.Grab();

CApplicationTimer m_TimerMode;
m_TimerMode = m_Application.GetTimer();
m_TimerMode.SetSynchronizationMode(appTimerSynchronous);
m_TimerMode.Reset(); while(m_TempFlag == 1)
{
m_Digitizer.Grab();
} UpdateData(FALSE);
}void CTestDlg::OnButtonVisionGrab() 
{
// TODO: Add your control notification handler code here m_TempFlag = 2; CWnd* pGrabButton = GetDlgItem(IDC_BUTTON_VISION_GRAB);
if(pGrabButton != NULL)
{
pGrabButton->EnableWindow(FALSE);
} m_Digitizer.GrabWait(digGrabEnd); UpdateData(FALSE);

}

解决方案 »

  1.   

    使用多线程SetEvent CreateEvent WaitForSingleObject
      

  2.   

    你可以用一个BOOL值来控制,如果为真或为假就用break结束while循环
      

  3.   

    OnButtonVisionGrab()里设置一个Bool变量,并用break跳出循环
      

  4.   

    恩~
    方法就是设置一个BOOL型变量,然后直接跳出就可以了~~~
      

  5.   

    我是这样做的:做了一个标记,当标记值改变时就跳出。可是根本不响应啊。一旦进入while循环,Dialog上的按键就不响应了,怎么办。--不用多线程。    谢谢
      

  6.   

    反正一句话 不到万不得已 别用 
    goto
    :P
      

  7.   

    //void CDlg::DoEvents()
    {
      MSG msg;
      while (::PeekMessage(&msg,NULL,0,0,PM_NOREMOVE) && !m_bCancel)
      {
         if (!AfxGetThread()->PumpMessage())
            return;
      }
    }
    void CDlg::Start() // On Button Start
    {
       m_btnStart.EnableWindow( FALSE );
        m_bCancel = false;
        while( ! m_bCancel )
        {
            ... // operator code
            DoEvents();
        }
       m_btnStart.EnableWindow( TRUE );
    }
    void CDlg::BreakIt // On Button Cancel
    {
       m_bCancel = true;
    }//
    因为循环时消息是被阻塞的,所以要在循环中加入代接消息和转发消息的DoEvents
    类似DoEvetns的使用在16位时代是最常用的,后来多线程出来大家都忘了.
    DoEvents 的坏处是可能因用户误操作出现多次调用的问题,所以要在循环前后禁用/使能该BUTTON