2013-07-17 52 views
0

我正在使用資源編輯器創建按鈕應用程序。創建按鈕後,我嘗試一些其他的地方做像這個 -getmessage(DispatchMessage(&msg);不工作)中的無限循環

m_hwndPreview = CreateDialogParam(g_hInst,MAKEINTRESOURCE(IDD_MAINDIALOG), m_hwndParent,(DLGPROC)DialogProc, (LPARAM)this); 


     if (m_hwndPreview == NULL) 
     { 
      hr = HRESULT_FROM_WIN32(GetLastError()); 
     } 
    MSG msg; 
     BOOL bRet; 
     while ((bRet=GetMessage (& msg,0, 0,0)) != 0) 
     {// this msg always contains the data like -msg = {msg=0x0000c03e wp=0x0000000000000012//always 12 I don't know why ?? lp=0x0000000000000000} 
      if (bRet == -1) 
      { 
       bRet = HRESULT_FROM_WIN32(GetLastError()); 
       MessageBox(NULL, L"Hurr i am the error",L"Error",MB_ICONERROR | MB_OK); 
      } 

      else if (!IsDialogMessage (m_hwndPreview, & msg)) 
      { 
       TranslateMessage (&msg); //on debugging TranslateMessage = 0x000007feee615480 TranslateMessage 
       DispatchMessage(& msg); //but show nothing when I put cursor on this method to know the value that means it's not called 

       MessageBox(NULL, L"there is no error in receiving before dispatch the message",L"Error", 
       MB_ICONERROR | MB_OK);//this messagebox repeats again and again after the call to DialogProc function and I am not able to come out of the loop and here I need to restart my PC 

我這樣定義這個 - //這個函數createdialog功能就被稱爲上createDialogParam()function.after它的控件去那裏的getMessage一切都循環。

BOOL CALLBACK AMEPreviewHandler::DialogProc(HWND m_hwndPreview, UINT Umsg, WPARAM wParam, LPARAM lParam) 
    { //this dialogProc function is declares Static some where in the code otherwise the createdialogparam will give error DLGPROC is invalid conversion 

//this Umsg alays creates strange value like 48 and 32 etc.. and Wparam contains a very big value like 12335423526 (I mean big and strange) and lparam contains 0. 
     switch(Umsg) 
     { 
     case WM_INITDIALOG: 
      { 
       MessageBox(NULL, L"Inside the WM_INITDIALOG function",L"Error", 
       MB_ICONERROR | MB_OK); 

      return TRUE; 
      } 
      break; 

     case WM_CREATE: 
      { 
      ///////////////// 
      MessageBox(NULL, L"Inside the WM_CREATE",L"Error", 
       MB_ICONERROR | MB_OK); 
      ///////////////////////////////// 
      } 
      break; 

     case WM_COMMAND: 
      { //here are my two buttons created by me which should show messagebox on click 
       int ctl = LOWORD(wParam); 
       int event = HIWORD(wParam);//I don't know why this event is in blue colour .. but its not the pqrt of problem right now. 

       if (ctl == IDC_PREVIOUS && event == BN_CLICKED) 
       {   
        MessageBox(m_hwndPreview,L"Button Clicked is next inside WM_COMMAND ",L"BTN WND",MB_ICONINFORMATION); 
        return 0; 
       }   

       if (ctl == IDC_NEXT && event == BN_CLICKED) 
       {   
        MessageBox(m_hwndPreview,L"Button Clicked is previous inside WM_COMMAND",L"BTN WND",MB_ICONINFORMATION); 
        return 0; 
       }   

       return FALSE; 

      }break; 


     case WM_DESTROY: 
      { 

       ////////////////:: 
        MessageBox(NULL, L"Inside the WM_DESTROY",L"Error", 
       MB_ICONERROR | MB_OK); 
        ////////////////// 

       PostQuitMessage(0); 
       return 0; 

      } 
      break; 
      case WM_CLOSE: 
       { 
        MessageBox(NULL, L"Inside the WM_CLOSE",L"Error", 
       MB_ICONERROR | MB_OK); 

        DestroyWindow (m_hwndPreview); 
        return TRUE;    

       } 
       break;   

     } 
       MessageBox(NULL, L"outside the DefWindowProc function",L"Error", 
       MB_ICONERROR | MB_OK); 

     return 0; 
    } 

問題發生的是,當我登場啦控制先去CreateDialogParam,然後去GETMESSAGE其中控制不出來的循環導致重啓的問題。我沒有在預覽窗格中顯示按鈕和圖像。我期望如果一切順利,調試後它應該在預覽窗格上顯示圖片,並且我有2個按鈕「Next」和「Previous」,但它只顯示一個空白窗口(我已經使用資源編輯器創建的按鈕和照片.. 。這是正確的我很確定)..但我不知道爲什麼我不出來getmessage函數和dispatchmessage不被調用(因爲我看到了調試)。

+0

終於完成了它...剛纔評論了GetMessage函數部分,這工作正常...我仍然無法正確理解GetMessage函數在這裏使用什麼.. – Sss

回答

0

所以現在你可以嘗試評論說,可能會出來,如果這個問題,因爲你正在創建使用IDD_MAINDIALOG按鈕,您的createdialogparam直接調用,您收到WM_COMMAND您dailogproc功能的GetMessage部分代碼,並有人在你的代碼手柄後面。

0

你應該只在DispatchMessage函數(MSG)後寫

return true; 

;

和tehn調試它並通知我調試結果。

+1

yaah真的有效..現在我結束循環但輸出仍然不符合要求... – Sss