I need an activeX which handles global hotkey: Shift+b

The code below is supposed to do this when I call this ActiveX from IE.

I see the result of RegisterHotKey is true which means that the hotkey has been registered Ok.

But I don't see that any messages come to the ThreadPreprocessMessage method.... why????

Please help.

Thank you

namespace Kosmala.Michal.ActiveXTest{
    public class ActiveXObject : NativeWindow, IDisposable {
        public const int WM_HOTKEY = 0x0312;
        private IntPtr pFoundWindow ;

        public ActiveXObject(){
            System.Windows.MessageBox.Show("constructor<<");
            Process[] processes = Process.GetProcessesByName("iexplore");
            foreach (Process p in processes){
                pFoundWindow = p.MainWindowHandle;
            }
            System.Windows.MessageBox.Show("pFoundWindow:" + pFoundWindow);
            SetupHotKey(pFoundWindow);
            ComponentDispatcher.ThreadPreprocessMessage += ComponentDispatcher_ThreadPreprocessMessage;
            System.Windows.MessageBox.Show("constructor>>");
        }

        void ComponentDispatcher_ThreadPreprocessMessage(ref MSG msg, ref bool handled){
            System.Windows.MessageBox.Show("inside handler");
            if (msg.message == WM_HOTKEY){
                System.Windows.MessageBox.Show("inside handler");
            }
        }

        private void SetupHotKey(IntPtr handle){
            bool res = RegisterHotKey(handle, GetType().GetHashCode(), 0x0004, 0x42); //Shift + b
            System.Windows.MessageBox.Show("SetupHotKey res:"+res);
        }

        public void Dispose(){
            UnregisterHotKey(_host.Handle, GetType().GetHashCode());
        }

        [DllImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vlc);

        [DllImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool UnregisterHotKey(IntPtr hWnd, int id);
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.