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. Get window handle on which mouse button was clicked

Get window handle on which mouse button was clicked

Scheduled Pinned Locked Moved C / C++ / MFC
questioncomhostinghelp
8 Posts 3 Posters 1 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.
  • S Offline
    S Offline
    staticv
    wrote on last edited by
    #1

    Hey, I'm using Windows Hook, I installed the mouse hook, system-wide and its working perfectly. Now there is a problem, I need to the get window handle on which the mouse was clicked.. How do I do that? Does the Mouse hook event passes us that information?

    Top Web Hosting Providers[^] Do, or do not. There is no 'try'.

    D 1 Reply Last reply
    0
    • S staticv

      Hey, I'm using Windows Hook, I installed the mouse hook, system-wide and its working perfectly. Now there is a problem, I need to the get window handle on which the mouse was clicked.. How do I do that? Does the Mouse hook event passes us that information?

      Top Web Hosting Providers[^] Do, or do not. There is no 'try'.

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Are you using WH_MOUSE?

      "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

      S 1 Reply Last reply
      0
      • D David Crow

        Are you using WH_MOUSE?

        "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        S Offline
        S Offline
        staticv
        wrote on last edited by
        #3

        Well, I was using WH_MOUSE_LL earlier. I changed my code to WH_MOUSE. Now the code is:

        HWND hWnd = NULL;
        HWND hDesktopListWnd = NULL;

        hWnd = FindWindow(_T("ProgMan"), NULL);
        hWnd = GetWindow(hWnd, GW_CHILD);
        hDesktopListWnd = GetWindow(hWnd, GW_CHILD);

        threadID = GetWindowThreadProcessId(hDesktopListWnd, NULL);

        hookMouse = SetWindowsHookEx(WH_MOUSE, (HOOKPROC)InternalMouseHookCallback, g_appInstance, threadID);

        It installs the hook successfully, but I don't get the mouse hook events now. Basically I want to get click events when any icon on the desktop is clicked.

        Top Web Hosting Providers[^] Do, or do not. There is no 'try'.

        D 1 Reply Last reply
        0
        • S staticv

          Well, I was using WH_MOUSE_LL earlier. I changed my code to WH_MOUSE. Now the code is:

          HWND hWnd = NULL;
          HWND hDesktopListWnd = NULL;

          hWnd = FindWindow(_T("ProgMan"), NULL);
          hWnd = GetWindow(hWnd, GW_CHILD);
          hDesktopListWnd = GetWindow(hWnd, GW_CHILD);

          threadID = GetWindowThreadProcessId(hDesktopListWnd, NULL);

          hookMouse = SetWindowsHookEx(WH_MOUSE, (HOOKPROC)InternalMouseHookCallback, g_appInstance, threadID);

          It installs the hook successfully, but I don't get the mouse hook events now. Basically I want to get click events when any icon on the desktop is clicked.

          Top Web Hosting Providers[^] Do, or do not. There is no 'try'.

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          Ahmed Manzoor wrote:

          Well, I was using WH_MOUSE_LL earlier.

          In the LowLevelMouseProc() function, the lParam is a MSLLHOOKSTRUCT structure.

          Ahmed Manzoor wrote:

          I changed my code to WH_MOUSE.

          In the MouseProc() function, lParam is a MOUSEHOOKSTRUCT structure. Both of these structures have a pt member.

          "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          S 1 Reply Last reply
          0
          • D David Crow

            Ahmed Manzoor wrote:

            Well, I was using WH_MOUSE_LL earlier.

            In the LowLevelMouseProc() function, the lParam is a MSLLHOOKSTRUCT structure.

            Ahmed Manzoor wrote:

            I changed my code to WH_MOUSE.

            In the MouseProc() function, lParam is a MOUSEHOOKSTRUCT structure. Both of these structures have a pt member.

            "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

            S Offline
            S Offline
            staticv
            wrote on last edited by
            #5

            Hmmm. But I ran into another problem. Since I only needed Desktop's ListView (SysListView32) mouse events. I used WH_MOUSE because it can be thread specific whereas WH_MOUSE_LL can be global hook only that's why. Now when I did this change, I'm not getting any events when I click on the desktop icons or anywhere in the desktop. hookMouse = SetWindowsHookEx(WH_MOUSE, (HOOKPROC)InternalMouseHookCallback, g_appInstance, threadID); Here g_appInstance is the address of the DLL. threadID is the ID of the thread in which there is the SysListView32 (which is the desktop). InternalMouseHookCallback is a callback of .NET function. But now its not working. Please help me out. I'm using the Global System Hooks in .NET

            Top Web Hosting Providers[^] Do, or do not. There is no 'try'.

            T 1 Reply Last reply
            0
            • S staticv

              Hmmm. But I ran into another problem. Since I only needed Desktop's ListView (SysListView32) mouse events. I used WH_MOUSE because it can be thread specific whereas WH_MOUSE_LL can be global hook only that's why. Now when I did this change, I'm not getting any events when I click on the desktop icons or anywhere in the desktop. hookMouse = SetWindowsHookEx(WH_MOUSE, (HOOKPROC)InternalMouseHookCallback, g_appInstance, threadID); Here g_appInstance is the address of the DLL. threadID is the ID of the thread in which there is the SysListView32 (which is the desktop). InternalMouseHookCallback is a callback of .NET function. But now its not working. Please help me out. I'm using the Global System Hooks in .NET

              Top Web Hosting Providers[^] Do, or do not. There is no 'try'.

              T Offline
              T Offline
              transoft
              wrote on last edited by
              #6

              The first parameter is wrong.

              hookMouse = SetWindowsHookEx(WH_MOUSE, (HOOKPROC)InternalMouseHookCallback, g_appInstance, threadID);

              You should handle "WM_MOUSE" in the "InternalMouseHookCallback".

              S D 2 Replies Last reply
              0
              • T transoft

                The first parameter is wrong.

                hookMouse = SetWindowsHookEx(WH_MOUSE, (HOOKPROC)InternalMouseHookCallback, g_appInstance, threadID);

                You should handle "WM_MOUSE" in the "InternalMouseHookCallback".

                S Offline
                S Offline
                staticv
                wrote on last edited by
                #7

                WH_MOUSE Hook[^]

                Top Web Hosting Providers[^] Do, or do not. There is no 'try'.

                1 Reply Last reply
                0
                • T transoft

                  The first parameter is wrong.

                  hookMouse = SetWindowsHookEx(WH_MOUSE, (HOOKPROC)InternalMouseHookCallback, g_appInstance, threadID);

                  You should handle "WM_MOUSE" in the "InternalMouseHookCallback".

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #8

                  transoft wrote:

                  The first parameter is wrong.

                  No, WH_MOUSE is correct.

                  transoft wrote:

                  You should handle "WM_MOUSE" in the "InternalMouseHookCallback".

                  :confused:

                  "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                  "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                  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