NO

Author Topic: subclass question  (Read 3988 times)

cl2606

  • Guest
subclass question
« on: July 06, 2008, 07:25:37 PM »
Hello.  I was successful getting subclassing to work one way, but not another (which is what I really wanted). 

I have an edit box in a dialog window (which is the only window, no parent).  When enter is pressed from the edit box I want the same effect as if I clicked on a button.  I tried to subclass and capture the enter but it didn't work.

So, I made a test program and put an edit box in a regular (top level) window.  I used the exact same logic for sublclassing as I did in the above with the dialog box and it worked exactly how I wanted it to. 

Why will my subclassing work in a top level window and not when I subclass within a dialog box?

Thanks

Curt

cl2606

  • Guest
Re: subclass question
« Reply #1 on: July 06, 2008, 11:07:24 PM »
I got it.  Found the answer in an old post on comp.os.ms-wondows.programmer.win32.

For anyone else who is interested, you have to trap WM_GETDLGCODE and return DLGC_WANTALLKEYS in the subclassed edit procedure, here's the code from that procedure:

LRESULT CALLBACK NewEditProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{

   //MessageBox (hWnd, TEXT ("Here in NewWditProc"), TEXT ("NewEditProc"), MB_OK);
   switch (msg)
   {
   case WM_KEYDOWN:
      if (wParam == VK_RETURN)
      {
         MessageBox (hWnd, TEXT ("Got it!"), TEXT ("NewEditProc"), MB_OK);
         return 0;
      }
   case WM_GETDLGCODE:
      return DLGC_WANTALLKEYS;
   }
   return CallWindowProc (g_OldDlgProc, hWnd, msg, wParam, lParam);
         
}