Exemple #1
0
        private IntPtr ModalListener(int code, IntPtr wParam, IntPtr lParam)
        {
            if (code == HCBT_ACTIVATE)
            {
                Form form = Form.FromHandle(wParam) as Form;

                string name = null;

                if (form != null && form.Modal)
                {
                    name = form.Name;
                }
                else if (IsDialog(wParam))
                {
                    System.Diagnostics.Debug.Assert(false);
                    //name = MessageBoxTester.GetCaption(wParam);
                    if (name == null)
                    {
                        name = string.Empty;
                    }
                }

                Invoke(name, wParam);
            }

            return(Win32.CallNextHookEx(handleToHook, code, wParam, lParam));
        }
Exemple #2
0
        /// <summary>
        /// CBT callback called when a form is activated.
        /// If the newly activated form is modal, invoke the registered handler.
        /// </summary>
        private IntPtr Callback_ModalListener(int code, IntPtr wParam, IntPtr lParam)
        {
            if (code == HCBT_ACTIVATE)
            {
                // Some controls sends an HCBT_ACTIVATE when changed for example tabPages. We do not
                // want our handler to be called when a tabPage is changed. This is a problem in Modal
                // modal windows.
                bool b = true;
                if (hwndList.Contains(wParam))
                {
                    b = false;
                }

                if (b)
                {
                    hwndList.Add(wParam);
                    FindWindowNameAndInvokeHandler(wParam);
                }
            }
            if (code == HCBT_DESTROYWND)
            {
                // Need to remove the handle when the window is destroyed.

                if (hwndList.Contains(wParam))
                {
                    hwndList.Remove(wParam);
                }
            }

            return(Win32.CallNextHookEx(handleToHook, code, wParam, lParam));
        }