Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Subclass Procedure failed for edit control

Subclass Procedure failed for edit control

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionlearning
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vishalgpt
    wrote on last edited by
    #1

    Hi to all, I am subclassing an EDIT Control. But the WM_CREATE is not fired in Subclassed Procedure EditProc. What is wrong, i am unable to find. I had tried WM_NCCREATE also, but failed. pls help.. :( :confused:

    #include
    #include "resource.h"

    WNDPROC OldEditProc;
    HINSTANCE hInst;
    HFONT hFont;

    WNDPROC SUBCLASS(HWND hControl,WNDPROC newWindowProc)
    {
    return (WNDPROC)SetWindowLong(hControl,GWL_WNDPROC,(LONG)newWindowProc);
    }

    LRESULT CALLBACK EditProc(HWND hWnd,UINT Msg, WPARAM wParam, LPARAM lParam)
    {
    switch(Msg)
    {
    case WM_CREATE:
    SetWindowText(hWnd,L"Welcome");
    break;
    }
    return OldEditProc(hWnd,Msg,wParam,lParam);
    }

    LRESULT CALLBACK stdEditProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
    {

    switch(Msg)
    {
    case WM\_INITDIALOG:
    	OldEditProc = SUBCLASS(GetDlgItem(hWnd,IDC\_EDIT1),EditProc);
    	break;
    case WM\_CLOSE:
    	EndDialog(hWnd,TRUE);
    	break;
    }
    return FALSE;
    

    }

    INT APIENTRY wWinMain( __in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance, __in_opt LPWSTR lpCmdLine, __in int nShowCmd )
    {
    hInst = hInstance;
    return DialogBox(hInst,MAKEINTRESOURCE(IDD_DIALOG1),NULL,(DLGPROC)stdEditProc);
    }

    Regards, Vishal

    _ 1 Reply Last reply
    0
    • V vishalgpt

      Hi to all, I am subclassing an EDIT Control. But the WM_CREATE is not fired in Subclassed Procedure EditProc. What is wrong, i am unable to find. I had tried WM_NCCREATE also, but failed. pls help.. :( :confused:

      #include
      #include "resource.h"

      WNDPROC OldEditProc;
      HINSTANCE hInst;
      HFONT hFont;

      WNDPROC SUBCLASS(HWND hControl,WNDPROC newWindowProc)
      {
      return (WNDPROC)SetWindowLong(hControl,GWL_WNDPROC,(LONG)newWindowProc);
      }

      LRESULT CALLBACK EditProc(HWND hWnd,UINT Msg, WPARAM wParam, LPARAM lParam)
      {
      switch(Msg)
      {
      case WM_CREATE:
      SetWindowText(hWnd,L"Welcome");
      break;
      }
      return OldEditProc(hWnd,Msg,wParam,lParam);
      }

      LRESULT CALLBACK stdEditProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
      {

      switch(Msg)
      {
      case WM\_INITDIALOG:
      	OldEditProc = SUBCLASS(GetDlgItem(hWnd,IDC\_EDIT1),EditProc);
      	break;
      case WM\_CLOSE:
      	EndDialog(hWnd,TRUE);
      	break;
      }
      return FALSE;
      

      }

      INT APIENTRY wWinMain( __in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance, __in_opt LPWSTR lpCmdLine, __in int nShowCmd )
      {
      hInst = hInstance;
      return DialogBox(hInst,MAKEINTRESOURCE(IDD_DIALOG1),NULL,(DLGPROC)stdEditProc);
      }

      Regards, Vishal

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      WM_CREATE and WM_NCCREATE will not be sent to the sub-classed procedure because they have already been sent to the original procedure. But you will get other WM_COMMAND messages and notifications.

      «_Superman_»  _I love work. It gives me something to do between weekends.

      _Microsoft MVP (Visual C++)

      Polymorphism in C

      V 1 Reply Last reply
      0
      • _ _Superman_

        WM_CREATE and WM_NCCREATE will not be sent to the sub-classed procedure because they have already been sent to the original procedure. But you will get other WM_COMMAND messages and notifications.

        «_Superman_»  _I love work. It gives me something to do between weekends.

        _Microsoft MVP (Visual C++)

        Polymorphism in C

        V Offline
        V Offline
        vishalgpt
        wrote on last edited by
        #3

        got it, but one small doubt, if i want to set font for a control i usually do it in WM_INITDIALOG or WM_CREATE section, but in this case which Message has to be used for setting font, As i had found this can be done in WM_PAINT section also, but WM_PAINT is triggered every now and then, resulting in extra overload. Please guide which message will be better to set a font for a control in its subclassed procedure. Thanks.. :)

        Regards, Vishal

        _ 1 Reply Last reply
        0
        • V vishalgpt

          got it, but one small doubt, if i want to set font for a control i usually do it in WM_INITDIALOG or WM_CREATE section, but in this case which Message has to be used for setting font, As i had found this can be done in WM_PAINT section also, but WM_PAINT is triggered every now and then, resulting in extra overload. Please guide which message will be better to set a font for a control in its subclassed procedure. Thanks.. :)

          Regards, Vishal

          _ Offline
          _ Offline
          _Superman_
          wrote on last edited by
          #4

          So if you do this before you sub-class the control in the original procedure, does it change after sub-classing? Don't do it in WM_PAINT. It will be an unnecessary overhead. Instead, you could define a custom message and do a PostMessage with the custom message to the control after it is sub-classed in WM_INITDIALOG.

          «_Superman_»  _I love work. It gives me something to do between weekends.

          _Microsoft MVP (Visual C++)

          Polymorphism in C

          V 1 Reply Last reply
          0
          • _ _Superman_

            So if you do this before you sub-class the control in the original procedure, does it change after sub-classing? Don't do it in WM_PAINT. It will be an unnecessary overhead. Instead, you could define a custom message and do a PostMessage with the custom message to the control after it is sub-classed in WM_INITDIALOG.

            «_Superman_»  _I love work. It gives me something to do between weekends.

            _Microsoft MVP (Visual C++)

            Polymorphism in C

            V Offline
            V Offline
            vishalgpt
            wrote on last edited by
            #5

            thanx, I will check and update the result. Thanx once again for your guidance.

            Regards, Vishal

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups