winapibuttondialogdispatchgetmessage

infinite loop inside the getmessage (DispatchMessage(& msg ); is not working)


I am creating a button application using resource editor. After creating button I try to do like this-

 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

at some other place I define createdialog function like this- //this function is called just on createDialogParam() function.after it the controls go to getmessage where everything loops.

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;
    }

The problem occurring is that when I debut it the control first go to CreateDialogParam and then it go to getmessage where the control don't come out of the loop causing restart problem. And I have no display of button and image at preview pane. What I expect if everything go fine is after debugging it should show picture on preview pane and I have 2 buttons "Next" and "Previous" but it show just a blank window (the buttons and photo I have already created using Resource editor... That's correct I am sure about that) .. but I don't know why I am not coming out getmessage function and dispatchmessage is not called (because I saw on debugging).


Solution

  • so now you can try to comment the getmessage part code that will probably out if the problem because you are creating button using IDD_MAINDIALOG and your createdialogparam directly calls your dailogproc function where you receive WM_COMMAND and that you handle by your code behind.