WM_KEYDOWN never happens in dialog

2»

Comments

  • : [blue]Subclassing is replacing the original WndProc of a control (in your case the standard multi-line edit box from your resource) with your own procedure, so your procedure get called first. It is your resposibility to call the original procedure or the control will stop working. Here is small example:
    : [code]
    : // Declared outside:
    : static WNDPROC pfnSysEditWndProc;
    :
    : // Your message interceptor for edit box:
    : LRESULT CALLBACK YourOwnEditProc (
    : HWND hEdit, UINT uiMsg, WPARAm wp, LPARAM lp)
    : {
    : if (uiMsg == WM_CHAR) {
    : if ((wp == '
    ') && (GetKeyState (VK_CONTROL) & 0x8000)) {
    : // CTRL+ENTER !! Do whatever your need here..., but always
    : // fall back to the last line to return the system processing.
    : }
    : }
    : // ALWAYS return the result from system function!
    : return CallWndProc (pfnSysEditWndProc, hEdit, uiMsg, wp, lp);
    : }
    :
    : // In your dialog procedure...
    : case WM_INITDIALOG:
    : {
    : HWND hEdit = GetDlgItem (hDlg, IDC_YOUR_EDIT);
    :
    : // Replace window procedure for this HWND:
    : pfnSysEditWndProc = (WNDPROC) SetWindowLong (hEdit,
    : GWL_WNDPROC, (LONG) YourOwnEditProc);
    : }
    : break;
    :
    : case WM_COMMAND:
    : if (...time to close...) {
    : HWND hEdit = GetDlgItem (hDlg, IDC_YOUR_EDIT);
    :
    : // Return the system procedure back:
    : SetWindowLong (hEdit, GWL_WNDPROC, (LONG) pfnSysEditWndProc);
    : EndDialog (hDlg, IDOK /*or ID_CANCEL*/);
    : }
    : break;
    : [/code]
    : [/blue]
    :
    That is subclassing,i didn't know i could do something like that
    on a HWND,i think the point becomes a perfect circle now.
    [b]Thank to all of you that answer ![/b]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories