Installs an application-defined hook procedure with SetWindowsHookEx Often not effective

Add-in Express™ Support Service
That's what is more important than anything else

Installs an application-defined hook procedure with SetWindowsHookEx Often not effective
 
chris chen


Guest


Hi,
I need to capture the mouse click event to determine where the click is on the shape, so as to make the response action, I set the SetWindowsHookEx, the hook code from https://github.com/rvknth043/Global-Low-Level-Key-Board-And-Mouse-Hook/blob/master/GlobalLowLevelHooks/MouseHook.cs

        
        private IntPtr SetHook(MouseHookHandler proc)
        {
            using (ProcessModule module = Process.GetCurrentProcess().MainModule)
                return SetWindowsHookEx(WH_MOUSE_LL, proc, GetModuleHandle(module.ModuleName), 0);
        }
     


i setup the hook in AddinModule's InitializeComponent()

        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            ....
            mouseHook = new MouseHook();
            mouseHook.LeftButtonDown += new MouseHook.MouseHookCallback(mouseHook_MouseDown);
            mouseHook.Install();
            ....
         }
     


I found a strange phenomenon, not every time I open PowerPoint the hook program will take effect, sometimes it will not capture any mouse events, I don't know where the problem is.

I saw one of your articles about the hooking process https://www.add-in-express.com/creating-addins-blog/2021/07/27/addin-express-windows-hooks/ I don't know if it is related to this
Posted 07 Feb, 2023 17:58:09 Top
Andrei Smolin


Add-in Express team


Posts: 19122
Joined: 2006-05-11
Hello Chris,

Hooks are outside of the scope of our support services. In a COM add-in, you can use the Selection object to find the control selected.

Regards from Poland (GMT+1),

Andrei Smolin
Add-in Express Team Leader
Posted 08 Feb, 2023 08:36:44 Top