像mfc可以重载pretranslatemessage,那sdk的dialogbox怎么控制其消息循环呢,难道是hook getmesssage?太复杂了把...

解决方案 »

  1.   

    lz 你怎么创建的dialog啊?sdk 我记得是用CreateDialog这个函数吧
    msdn 直接输入 CreateDialog 就出来了This function creates a modeless dialog box from a dialog box template resource. HWND CreateDialog( 
      HINSTANCE hInstance, 
      LPCTSTR lpTemplate, 
      HWND hWndParent, 
      DLGPROC lpDialogFunc //这个就是消息响应回函数 
    ); 
    Parameters
    hInstance 
    [in] Handle to the module whose executable file contains the dialog box template. 
    lpTemplate 
    [in] Long pointer to the dialog box template. This parameter is either the pointer to a null-terminated character string that specifies the name of the dialog box template or an integer value that specifies the resource identifier of the dialog box template. If the parameter specifies a resource identifier, its high-order word must be zero and its low-order word must contain the identifier. You can use the MAKEINTRESOURCE macro to create this value. 
    hWndParent 
    [in] Handle to the window that owns the dialog box. 
    lpDialogFunc 
    [in] Long pointer to the dialog box procedure. For more information about the dialog box procedure, see DialogProc. 
    Return Values
    The handle to the dialog box indicates success. NULL indicates failure. To get extended error information, call GetLastError.Res
    The CreateDialog function uses the CreateWindowEx function to create the dialog box. CreateDialog then sends a WM_INITDIALOG message to the dialog box procedure. The function displays the dialog box if the template specifies the WS_VISIBLE style. Finally, CreateDialog returns the window handle to the dialog box. After CreateDialog returns, the application displays the dialog box (if it is not already displayed) by using the ShowWindow function. The application destroys the dialog box by using the DestroyWindow function. Microsoft® Windows® CE does not support all styles in the DLGTEMPLATE structure. This structure is in the template identified by the lpTemplate parameter.Requirements
    OS Versions: Windows CE 1.0 and later.
    Header: Winuser.h.
      

  2.   

    DialogBox Windows在其内部就建立了一个Message Loop 
    不用自己写就是了
      

  3.   


    INT_PTR DialogBox(          HINSTANCE hInstance,
        LPCTSTR lpTemplate,
        HWND hWndParent,
        DLGPROC lpDialogFunc
    );第4个参数就是消息处理过程函数.在这处理即可.
      

  4.   

    //   Main   message   loop: 
    while   (GetMessage(&msg,   NULL,   0,   0))   
    {//If   the   function   retrieves   the   WM_QUIT   message,   the   return   value   is   zero.   
    if   (!TranslateAccelerator(msg.hwnd,   hAccelTable,   &msg))   

    TranslateMessage(&msg); //转换某些键盘消息 
    DispatchMessage(&msg); //发送消息至窗口过程 


    //@@ 函数命名IsDigit,c1,c2 
    return   msg.wParam; 
    }可以在这个里面控制的吧
      

  5.   

    在transtalemessage之前把它过滤掉就可以了
      

  6.   

    to 5l:是消息循环,不是回调函数,你比如对话框有控件处理不了wm_keydown把
      

  7.   

    to 6l:是对话框,不是窗口,对话框有自己的messageloop
      

  8.   

    是消息循环啊
    while (GetMessage(&msg, NULL, 0, 0))  这个不是消息循环吗?
    难道你的SDK代码里没有这一段?
      

  9.   

    to 10l:dialogbox哎,哪来消息循环
      

  10.   

    首先,标准对话框使用PeekMessage()而不是GetMessage()来获取消息,所以你hook GetMessage()是徒劳的
    其次,PeekMessage()调用后,如果是对话框消息(IsDialogMessage()),则接着调用TranslateMessage()和DispatchMessage();如果不是,则调用WaitMessage()让出处理器给其它线程,该线程睡眠
    再次,以上步骤均在User32.dll模块中完成,所以如果你想改变消息循环流程,只有hook一条路了
      

  11.   

    to 12l:我是手机所以没法,另比较郁闷,莫非兄弟没用过dialogbox,dialogbox有自己的消息循环,可视13l,
      

  12.   

    模式对话框的消息循环在DialogBoxParam中,不归你管
    非模式对话框由CreateDialogParam创建,需要你的代码维持消息循环
      

  13.   

    to 13l:感谢您的解答,因为没查资料,所以我大概估摸着说是hook getmesssage的,其实我就是想知道mfc下重载对话框消息是怎么实现的,莫非如同hook一般,只是觉得hook太繁琐
      

  14.   

    使用SetWindowsHookEx安装消息钩子,或者使用SetWindowLong修改窗口过程
      

  15.   

    mfc下重载对话框消息mfc在自己的对话框过程中调用你提供的消息处理例程
      

  16.   

    应该没有这么复杂,你在调用DialogBoxParam或CreateDialogParam时要规定对话框过程的,你在对话框过程中处理消息就行了
    #include <windows.h>
    #include <commctrl.h>
    #include "resource.h"
    #define ImageBase ((HINSTANCE)0x40000)INT_PTR __stdcall DialogFunc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
    {
    static HWND hwndList,hwndEdit[3];
    switch (message)
    {
    case WM_COMMAND://这里处理WM_COMMAND消息
    switch(LOWORD(wParam))
    {
    case IDC_ADD:
    {
    static wchar_t Buffer[512];
    static LVITEM lvitem={LVIF_TEXT|LVIF_IMAGE|LVIF_PARAM,2147483647,0,0,0,Buffer},lvsubitem={LVIF_TEXT,0,1,0,0,Buffer},lvsubitem2={LVIF_TEXT,0,2,0,0,Buffer};
    SendMessage(hwndEdit[0],WM_GETTEXT,512,(LPARAM)Buffer);
    lvsubitem.iItem=lvsubitem2.iItem=ListView_InsertItem(hwndList,&lvitem);
    SendMessage(hwndEdit[1],WM_GETTEXT,512,(LPARAM)Buffer);
    ListView_SetItem(hwndList,&lvsubitem);
    SendMessage(hwndEdit[2],WM_GETTEXT,512,(LPARAM)Buffer);
    ListView_SetItem(hwndList,&lvsubitem2);
    }
    break;
    }
    return 1;
    case WM_INITDIALOG:
    {
    static LVCOLUMN col_H1={LVCF_TEXT|LVCF_WIDTH,0,50,TEXT("H1")},col_H2={LVCF_TEXT|LVCF_WIDTH,0,50,TEXT("H2")},col_H3={LVCF_TEXT|LVCF_WIDTH,0,50,TEXT("H3")};
    hwndList=GetDlgItem(hDlg,IDC_LIST1);
    hwndEdit[0]=GetDlgItem(hDlg,IDC_EDIT1);
    hwndEdit[1]=GetDlgItem(hDlg,IDC_EDIT2);
    hwndEdit[2]=GetDlgItem(hDlg,IDC_EDIT3);
    ListView_InsertColumn(hwndList,0,&col_H1);
    ListView_InsertColumn(hwndList,1,&col_H2);
    ListView_InsertColumn(hwndList,2,&col_H3);
    }
    return 1;
    case WM_CLOSE:
    EndDialog(hDlg,0);
    }
    return 0;
    }void EntryPoint(void)
    {
    static INITCOMMONCONTROLSEX icce={sizeof(INITCOMMONCONTROLSEX),ICC_WIN95_CLASSES};
    InitCommonControlsEx(&icce);
    ExitProcess(DialogBoxParam(ImageBase,MAKEINTRESOURCE(IDD_FORMVIEW),0,DialogFunc,0));
    }
      

  17.   

    MFC的DoModal内部是用CreateDialogIndirect创建对话框,然后在再加消息循环。
    而你用SDK的DialogBox创建后,就直接卡着了,函数内部搞消息循环,所以你截不了它的原始消息。
    至你说到不能处理WM_KEYDOWN,只是表面现象,DialogBox创建一样有方法处理。
    解决方法:
    方法1。用CreateDialogIndirect创建对话框,外加消息循环,然后在GetMessage或PeekMessage后里截住WM_KEYDOWN,实现所谓pretranslatemessage,跟MFC处理方法类似。
    方法2。用DialogBox创建,然后处理消息WM_GETDLGCODE,返回的HRESULT值为DLGC_WANTALLKEYS|DLGC_WANTCHARS,然后你WM_KEYDOWN就有反应了!!
      

  18.   

    也谢谢所有人帮忙解答,总结两点,dialogbox想改变消息循环只有hook,2.想处理wm_keydown可以参照21#,若有不对请指正
    没有管理员改日在结,谢谢所有回答的哥们
      

  19.   

    用asp.net多了,消息循环都全丢光了,咋办呀
      

  20.   

    while (GetMessage(&msg, NULL, 0, 0))