Ejemplo n.º 1
0
 public void Dispose()
 {
     if (wndProcRetHook != null)
     {
         wndProcRetHook.Uninstall();
         wndProcRetHook = null;
     }
     if (cbtHook != null)
     {
         cbtHook.Uninstall();
         cbtHook = null;
     }
 }
Ejemplo n.º 2
0
        public void WndProcRet(object sender, WndProcRetEventArgs e)
        {
            if (e.cw.message == Win32.Const.WM_INITDIALOG ||
                e.cw.message == Win32.Const.WM_CHANGEUISTATE)
            {
                Win32.Function.MoveWindow(e.cw.hWnd, rect.Left, rect.Top, rect.Width, rect.Height, 1);

                // uninstall this hook
                WindowsHook wndHook = (WindowsHook)sender;
                Debug.Assert(wndProcRetHook == wndHook);
                wndProcRetHook.Uninstall();
                wndProcRetHook = null;
            }
        }
Ejemplo n.º 3
0
        public void WndActivate(object sender, CbtEventArgs e)
        {
            IntPtr hMsgBox = e.wParam;

            // try to find a howner for this message box
            if (hOwner == IntPtr.Zero)
            {
                hOwner = Win32.Function.GetActiveWindow();
            }

            // get the MessageBox window rect
            Win32.RECT rectDlg = new Win32.RECT();
            Win32.Function.GetWindowRect(hMsgBox, ref rectDlg);

            // get the owner window rect
            Win32.RECT rectForm = new Win32.RECT();
            Win32.Function.GetWindowRect(hOwner, ref rectForm);

            // get the biggest screen area
            Rectangle rectScreen = TrueScreenRect;

            // if no parent window, center on the primary screen
            if (rectForm.right == rectForm.left)
            {
                rectForm.right = rectForm.left = Screen.PrimaryScreen.WorkingArea.Width / 2;
            }
            if (rectForm.bottom == rectForm.top)
            {
                rectForm.bottom = rectForm.top = Screen.PrimaryScreen.WorkingArea.Height / 2;
            }

            // center on parent
            int dx = ((rectDlg.left + rectDlg.right) - (rectForm.left + rectForm.right)) / 2;
            int dy = ((rectDlg.top + rectDlg.bottom) - (rectForm.top + rectForm.bottom)) / 2;

            rect = new Rectangle(
                rectDlg.left - dx,
                rectDlg.top - dy,
                rectDlg.right - rectDlg.left,
                rectDlg.bottom - rectDlg.top);

            // place in the screen
            if (rect.Right > rectScreen.Right)
            {
                rect.Offset(rectScreen.Right - rect.Right, 0);
            }
            if (rect.Bottom > rectScreen.Bottom)
            {
                rect.Offset(0, rectScreen.Bottom - rect.Bottom);
            }
            if (rect.Left < rectScreen.Left)
            {
                rect.Offset(rectScreen.Left - rect.Left, 0);
            }
            if (rect.Top < rectScreen.Top)
            {
                rect.Offset(0, rectScreen.Top - rect.Top);
            }

            if (e.IsDialog)
            {
                // do the job when the WM_INITDIALOG message returns
                wndProcRetHook             = new WndProcRetHook(hMsgBox);
                wndProcRetHook.WndProcRet += new WndProcRetHook.WndProcEventHandler(WndProcRet);
                wndProcRetHook.Install();
            }
            else
            {
                Win32.Function.MoveWindow(hMsgBox, rect.Left, rect.Top, rect.Width, rect.Height, 1);
            }

            // uninstall this hook
            WindowsHook wndHook = (WindowsHook)sender;

            Debug.Assert(cbtHook == wndHook);
            cbtHook.Uninstall();
            cbtHook = null;
        }