请问:
   在VC6中,在资源Dialog中用SetWindowLong去实现窗口子类化(如Edit)时;总是出现问题。
   
   如:
      得不到WM_CHAR消息等。
      能得到WM_LBUTTONDOWN,但是这个消息的处理不能跳出它的处理函数。   但是用masm32v8,用上述的实现方法,就没有任何问题。   这是什么原因呢?是不是在VC6中有什么保护呢?

解决方案 »

  1.   

    SetWindowLong(hDlg, DWL_MSGRESULT, lRet);
    return TRUE;
      

  2.   

    补充一下:
        在模态对话框中,会出现问题。(即在模态对话框中,加入一个Edit,实现Edit的子类化)
        用CreateWindow自建窗口,再加控件实现窗口子类化时,不会出现问题。    今天,我又试了一次,这次连WM_LBUTTONDOWN消息都捕捉不到。    我用    
    lpOldProcEdit = SetWindowLong(GetDlgItem(hDlg, IDC_EDIT), GWL_WNDPROC, _MyEditProc);在_MyEditProc中
       调用CallWindowProc(lpOldProcEdit, hDlg, message, wParam, lParam);退出_MyEditProc函数。
      

  3.   

    http://www.titilima.cn/readarticle.php?id=38
    其中我也做了一个Edit的子类化
      

  4.   

    goodboyws版主说的SetWindowLong(hDlg, DWL_MSGRESULT, lRet);return TRUE;放在哪?
        
        作子类化与对话框的返回值(说得对吧?我英文不好!)有关吗?
                  ……………………
      

  5.   

    李马大哥说的我回去再试试。
        
        我记得我也是这么作的,您用得也是用DialogBox建得模态对话框吗?
      

  6.   

    > 您用得也是用DialogBox建得模态对话框吗?
    对,可参照源代码
      

  7.   

    李马大哥:
        我试了,还是不好使。
        
        ProcFloat()函数,捕捉不到WM_CHAR消息。    晚上,我再把我的源码贴上吧。
      

  8.   

    我以前的,不知对你有没用:SendMessage(GetDlgItem(hWnd, IDC_NEWBUT), BM_SETSTYLE, (WPARAM)BS_OWNERDRAW, (LPARAM)TRUE);
    NewProc = (WNDPROC)SetWindowLong(GetDlgItem(hWnd, IDC_NEWBUT), GWL_WNDPROC, (LONG)WndNewButProc);
    DialogBox(p_hInstance, MAKEINTRESOURCE(IDD_SETDLG), hWnd, (DLGPROC)WndSetDlgProc);
    BOOL CALLBACK WndNewButProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
    switch(uMsg)
    {
    case WM_CREATE:
    return 0;
    case WM_MOUSEMOVE:
    return 0;
    case WM_MOUSELEAVE:
    return 0;
    case WM_MOUSEHOVER:
    return 0;
    }
    return CallWindowProc(NewProc, hWnd, uMsg, wParam, lParam);
    }
      

  9.   

    为了节省空间,我删除了一些VC在rc文件中自动生成的预处理操作(我认为这些是非常没用的,你们认为呢?)。//resource.h文件
    #define IDD_DIALOG                      101
    #define IDC_EDIT                        1000//Edit.rc文件
    #include "resource.h"#define APSTUDIO_READONLY_SYMBOLS    //不知道它是干什么的?#include "afxres.h" //会是它的问题吗?masm32v8中用的是resouce.h#undef APSTUDIO_READONLY_SYMBOLS     //这个又是干什么用的?IDD_DIALOG DIALOG DISCARDABLE  0, 0, 187, 94
    STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
    CAPTION "Dialog"
    FONT 10, "System"
    BEGIN
        EDITTEXT        IDC_EDIT,26,19,40,14,ES_AUTOHSCROLL
    END//Edit.cpp/Edit.c文件
    #include <windows.h>
    #include "resource.h"WNDPROC EditProc;
    LRESULT CALLBACK ProcFloat(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
    {
    if (Msg == WM_CHAR)
    {
    wParam = '&';
    return 0;
    }
    else {
    return CallWindowProc(EditProc, hWnd, Msg, wParam, lParam);
    }}LRESULT CALLBACK MyEditProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
    {
    if (message == WM_INITDIALOG)
    {
    EditProc = (WNDPROC)SetWindowLong(GetDlgItem(hDlg, IDC_EDIT), 
    GWL_WNDPROC, (LONG)ProcFloat);
    }

    if (message == WM_CLOSE)
    {
    EndDialog(hDlg, 0);
    } return FALSE;
    }
    int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance, 
                         LPSTR lpCmdLine, int nCmdShow)
    {
    DialogBoxParam(hInstance, (LPCTSTR)IDD_DIALOG, 
                            NULL, (DLGPROC)MyEditProc, 0); return 0;
    }
      

  10.   

    上面那句
    DialogBox(p_hInstance, MAKEINTRESOURCE(IDD_SETDLG), hWnd, (DLGPROC)WndSetDlgProc);
    多余的
      

  11.   

    cgd0282:
        咱们俩的没什么区别呀!
      

  12.   

    来自msdn
    Subclassing a Window
    To subclass an instance of a window, call the SetWindowLong function and specify the handle to the window to subclass the GWL_WNDPROC flag and a pointer to the subclass procedure. SetWindowLong returns a pointer to the original window procedure; use this pointer to pass messages to the original procedure. The subclass window procedure must use the CallWindowProc function to call the original window procedure. The following example shows how to subclass an instance of an edit control in a dialog box. The subclass window procedure enables the edit control to receive all keyboard input, including the ENTER and TAB keys, whenever the control has the input focus. 
      

  13.   

    上面对Dialog中Edit的子类化操作,有源码吗?在哪个部分(msdn)?
      

  14.   

    msdn子类化源代码
    WNDPROC wpOrigEditProc; 
     
    LRESULT APIENTRY EditBoxProc(
        HWND hwndDlg, 
        UINT uMsg, 
        WPARAM wParam, 
        LPARAM lParam) 

        HWND hwndEdit; 
     
        switch(uMsg) 
        { 
            case WM_INITDIALOG: 
                // Retrieve the handle to the edit control. 
                hwndEdit = GetDlgItem(hwndDlg, ID_EDIT); 
     
                // Subclass the edit control. 
                wpOrigEditProc = (WNDPROC) SetWindowLong(hwndEdit, 
                    GWL_WNDPROC, (LONG) EditSubclassProc); 
                // 
                // Continue the initialization procedure. 
                // 
                return TRUE; 
     
            case WM_DESTROY: 
                // Remove the subclass from the edit control. 
                SetWindowLong(hwndEdit, GWL_WNDPROC, 
                    (LONG) wpOrigEditProc); 
                // 
                // Continue the cleanup procedure. 
                // 
                break; 
        } 
        return FALSE; 
            UNREFERENCED_PARAMETER(lParam); 

     
    // Subclass procedure 
    LRESULT APIENTRY EditSubclassProc(
        HWND hwnd, 
        UINT uMsg, 
        WPARAM wParam, 
        LPARAM lParam) 

        if (uMsg == WM_GETDLGCODE) 
            return DLGC_WANTALLKEYS; 
     
        return CallWindowProc(wpOrigEditProc, hwnd, uMsg, 
            wParam, lParam); 

      

  15.   

    上面的好像是非模态对话框,好像是因为有WM_DESTROY消息。而模态对话框的销毁窗口应该是WM_CLOSE消息,用EndDialog()关闭窗口。我回去试试吧。
      

  16.   

    我的问题解决一半了!仅仅是一半哟!!!将我的源码中的MyEditProc改成:
    LRESULT CALLBACK ProcFloat(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
    {
    if (Msg == WM_CHAR)
    {
    wParam = '&';
    }
    return CallWindowProc(EditProc, hWnd, Msg, wParam, lParam);}
    就可以了。
      

  17.   

    但是还有问题:
        用上述方法,Dialog是子窗口时,Dialog中的Edit不显示。    这是为什么呀?    我是在VC自动生成的Hello World!的源码实验的。