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
 
Subscribe
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 Global Low Level Key Board and Mouse Hook

        
        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 Add-In Express and Windows Hook 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: 18614
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