0

我正在使用资源编辑器创建一个按钮应用程序。创建按钮后,我尝试这样做 -

 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()函数上调用。在它之后,控件转到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 个按钮“下一步”和“上一个”,但它只显示一个空白窗口(我已经使用资源编辑器创建的按钮和照片.. .这是正确的我很确定)..但我不知道为什么我没有出来getmessage函数并且没有调用dispatchmessage(因为我在调试时看到了)。

4

2 回答 2

0

你应该写

return true;

就在 DispatchMessage(msg) 之后;

然后调试它并告诉我调试的结果。

于 2013-07-18T18:32:40.703 回答
0

因此,现在您可以尝试注释 getmessage 部分代码,如果问题可能会出现,因为您正在使用 IDD_MAINDIALOG 创建按钮,并且您的 createdialogparam 直接调用您收到 WM_COMMAND 的 dailogproc 函数,并且您在后面的代码中处理。

于 2013-07-18T18:38:33.227 回答