Beispiel #1
0
        void setTopmostState(int hnd)
        {
            int S = lstWindow.SelectedIndex;

            if (S == -1)
            {
                return;
            }
            WinAPI.RECT            R = new WinAPI.RECT();
            WinAPI.WINDOWPLACEMENT P = new WinAPI.WINDOWPLACEMENT();
            bool success             = WinAPI.GetWindowRect(thisItem.Handle, out R) &&
                                       WinAPI.GetWindowPlacement(thisItem.Handle, ref P);

            if (!success)
            {
                MessageBox.Show("无法获取窗口信息。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (!WinAPI.SetWindowPos(thisItem.Handle, (IntPtr)hnd, R.Left, R.Top, R.Right - R.Left, R.Bottom - R.Top, P.flags))
            {
                MessageBox.Show("设置窗口位置时发生错误。\r\n如果该程序是以管理员权限运行的,那么你需要以管理员权限运行本程序。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            updateTopMostInfo(thisItem.Handle);
            thisItem.IsTopMost = lstWindow.Items[S].IsTopMost = WinAPI.isWindowTopMost(thisItem.Handle);
        }
Beispiel #2
0
 private void menuSwitchTo_Click(object sender, EventArgs e)
 {
     if (thisItem.Handle != IntPtr.Zero)
     {
         WinAPI.WINDOWPLACEMENT P = new WinAPI.WINDOWPLACEMENT();
         WinAPI.RECT            R = new WinAPI.RECT();
         bool success             = WinAPI.GetWindowRect(thisItem.Handle, out R) &&
                                    WinAPI.GetWindowPlacement(thisItem.Handle, ref P);
         if (!success)
         {
             MessageBox.Show("无法获取窗口信息。\r\n\r\n可能是该窗口已经关闭。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
         WinAPI.SwitchToThisWindow(thisItem.Handle, true);
     }
 }