コード例 #1
0
        private bool WndProcForFocus(ref Message m)
        {
            const int SC_MAXIMIZE = 0xF030;
            const int SC_RESTORE  = 0xF120;

            switch ((uint)m.Msg)
            {
            case WinAPI.WM.NCLBUTTONDOWN:
                // This is in conjunction with the WM_NCMOUSEMOVE. We cannot detect
                // WM_NCLBUTTONUP because it gets swallowed up on many occasions. As a result
                // we detect the button down and check the NCMOUSEMOVE to see if it has
                // changed location. If the mouse location is different, then we let
                // the resize handler deal with the focus. If not, then we assume that it
                // is a mouseup action.
                this.m_lastMouseDownOnTitleBar = DateTime.Now;
                m_mouseDownLocation            = new Point(GET_X_LPARAM((int)m.LParam), GET_Y_LPARAM((int)m.LParam));
                break;

            case WinAPI.WM.NCMOUSEMOVE:
                Point currentLocation = new Point(GET_X_LPARAM((int)m.LParam), GET_Y_LPARAM((int)m.LParam));
                if ((this.m_lastMouseDownOnTitleBar - DateTime.Now < this.m_delayUntilMouseMove) &&
                    currentLocation == m_mouseDownLocation)
                {
                    FocusCurrentTab();
                }
                break;

            case WinAPI.WM.NCACTIVATE:
                // Never allow this window to display itself as inactive
                WinAPI.DefWindowProc(this.Handle, m.Msg, (IntPtr)1, m.LParam);
                m.Result = (IntPtr)1;
                return(false);

            case WinAPI.WM.SYSCOMMAND:
                // Check for maximizing and restoring from maxed.
                // Removing the last 4 bits. This is necessary because
                // maximizing by double click gives you 0xF032, not 0xF030.
                switch ((int)m.WParam & 0xFFF0)
                {
                case SC_MAXIMIZE:
                case SC_RESTORE:
                    FocusCurrentTab();
                    break;
                }
                break;

            default:
                if (m.Msg == m_shellHookNotify)
                {
                    switch (m.WParam.ToInt32())
                    {
                    case 4:
                        IntPtr current = WinAPI.GetForegroundWindow();
                        if (current != this.Handle && !ContainsChild(current))
                        {
                            m_externalWindow = true;
                        }
                        else if (m_externalWindow)
                        {
                            m_externalWindow = false;
                            WinAPI.BringWindowToTop(this.Handle);
                            FocusCurrentTab();
                        }
                        break;

                    default:
                        break;
                    }
                }
                break;
            }

            return(true);
        }
コード例 #2
0
 public void ResetTopmost()
 {
     WinAPI.BringWindowToTop(this.Handle);
 }