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. How to extend the all edit-like control in my code? Any idea?

How to extend the all edit-like control in my code? Any idea?

Scheduled Pinned Locked Moved C / C++ / MFC
windows-adminlinuxtutorialquestion
3 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.
  • A Offline
    A Offline
    Aaron K B Huang
    wrote on last edited by
    #1

    I want to add a item to the right-click popup menu wherever the edit-lick control, which can belong to any program instance. I thought there are two ways maybe, one is change the registry, like some "shell extending" articles in codeproject; two is hooking. But I never touch those two domain before. Can you give me some suggestions? I've got the base info of hooking, but have no good info or source-code of mouse hooking. I have no info of registry. Thanks ahead! with Best Regards, Kamp Huang:)

    P 1 Reply Last reply
    0
    • A Aaron K B Huang

      I want to add a item to the right-click popup menu wherever the edit-lick control, which can belong to any program instance. I thought there are two ways maybe, one is change the registry, like some "shell extending" articles in codeproject; two is hooking. But I never touch those two domain before. Can you give me some suggestions? I've got the base info of hooking, but have no good info or source-code of mouse hooking. I have no info of registry. Thanks ahead! with Best Regards, Kamp Huang:)

      P Offline
      P Offline
      Paul M Watt
      wrote on last edited by
      #2

      You can do that with local superclassing. Subclassing is where you replace the windowproc of a window or control after it is created. Local Superclassing is where you register a new class in your process that has the same name as one of the controls that have already been defined. When windows attempts to create a new control that has been superclasses, it will look in the local class definitions before it looks in the global definitions. Here is an example of the code that you can add to make it so that every time that you hit a key in the edit box, a beep will sound. You can make the changes to do what you need to do.

      WNDPROC lpfnEditClassProc = NULL;

      LRESULT CALLBACK LocalEdit_WndProc(HWND hwnd, UINT msg,
      WPARAM wParam, LPARAM lParam)
      {
      if (msg == WM_CHAR ) {
      MessageBeep(-1);
      }
      return CallWindowProc(lpfnEditClassProc, hwnd, msg, wParam, lParam);
      }

      BOOL CreateLocalEditClass()
      {
      WNDCLASS wc;

      if ( lpfnEditClassProc == NULL ) {
      GetClassInfo(NULL, "Edit", &wc);
      lpfnEditClassProc = (WNDPROC) wc.lpfnWndProc;
      wc.lpfnWndProc = LocalEdit_WndProc;
      wc.lpszClassName = "Edit";
      wc.hInstance = _hInstance;
      if (!RegisterClass(&wc))
      return FALSE;

        return TRUE;
      

      }
      }

      void DeleteLocalEditClass()
      {
      if ( lpfnEditClassProc != NULL ) {
      UnregisterClass("Edit", _hInstance);
      lpfnEditClassProc = NULL;
      }
      }

      If you need to change every edit control in windows to do what you want, you can look into global superclassing, but this is generally not a good idea.

      A 1 Reply Last reply
      0
      • P Paul M Watt

        You can do that with local superclassing. Subclassing is where you replace the windowproc of a window or control after it is created. Local Superclassing is where you register a new class in your process that has the same name as one of the controls that have already been defined. When windows attempts to create a new control that has been superclasses, it will look in the local class definitions before it looks in the global definitions. Here is an example of the code that you can add to make it so that every time that you hit a key in the edit box, a beep will sound. You can make the changes to do what you need to do.

        WNDPROC lpfnEditClassProc = NULL;

        LRESULT CALLBACK LocalEdit_WndProc(HWND hwnd, UINT msg,
        WPARAM wParam, LPARAM lParam)
        {
        if (msg == WM_CHAR ) {
        MessageBeep(-1);
        }
        return CallWindowProc(lpfnEditClassProc, hwnd, msg, wParam, lParam);
        }

        BOOL CreateLocalEditClass()
        {
        WNDCLASS wc;

        if ( lpfnEditClassProc == NULL ) {
        GetClassInfo(NULL, "Edit", &wc);
        lpfnEditClassProc = (WNDPROC) wc.lpfnWndProc;
        wc.lpfnWndProc = LocalEdit_WndProc;
        wc.lpszClassName = "Edit";
        wc.hInstance = _hInstance;
        if (!RegisterClass(&wc))
        return FALSE;

          return TRUE;
        

        }
        }

        void DeleteLocalEditClass()
        {
        if ( lpfnEditClassProc != NULL ) {
        UnregisterClass("Edit", _hInstance);
        lpfnEditClassProc = NULL;
        }
        }

        If you need to change every edit control in windows to do what you want, you can look into global superclassing, but this is generally not a good idea.

        A Offline
        A Offline
        Aaron K B Huang
        wrote on last edited by
        #3

        Oh! :-D New idea! I never thought of that before! But I really need to detect every edit-like controls to get the user selected text. I found that there are some many edit-like control with various class-name. Can I superclassing without specified a class-name? I wondered that. Hooking maybe the best way to do the tast. Thanks anyway!:)

        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