2
votes

I subclassed an edit box control like

lpfnOldWndProc = (FARPROC)SetWindowLong(hEdit,GWL_WNDPROC, (DWORD)SubClassFunc);




LRESULT FAR PASCAL SubClassFunc(   HWND hWnd,
                                UINT Message,
                                WPARAM wParam,
                                LPARAM lParam)
{

    switch(Message)
    {

    case WM_CHAR:
        //Process this message to avoid message beeps.
        if ((wParam == VK_RETURN) || (wParam == VK_TAB))
        {
            //Do Something
            return 0;
        }

        break;
    case WM_KEYDOWN:
        if ((wParam == VK_RETURN) || (wParam == VK_TAB)) {
            //Do Something
            return 0;
        }

        break ;

    default:
        break;
    }

    return CallWindowProc((WNDPROC)lpfnOldWndProc, hWnd, Message, wParam, lParam);

}

Now when I enter char in editbox this subclassed procedure gets called. But I am not able to get it when enter key is pressed.

Is this something wrong in above procedure.

1

1 Answers

6
votes

No, the system uses WM_GETDLGCODE to determine which key presses the control is interested in. By default a edit box doesn't process Return (the dialog procedure interprets it as pressing the default button) and therefore doesn't require that VK_RETURNS are sent to it. You need to process the WM_GETDLGCODE message and return DLGC_WANTALLKEYS then you should get your VK_RETURNS.

The MS documentation outlines this sub-classing scenario pretty well.