Esempio n. 1
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            for (int i = 0; i < Items.Count; i++)
            {
                Rectangle bounds       = this.GetItemRectangle(i);
                Rectangle deleteBounds = new Rectangle(bounds.Width - 28, (bounds.Height - 16) / 2 + bounds.Top, 16, 16);

                if (bounds.Contains(e.X, e.Y))
                {
                    HoverIndex = i;

                    if (Items[i] != mouseItem)
                    {
                        mouseItem = Items[i];
                    }

                    if (deleteBounds.Contains(e.X, e.Y))
                    {
                        mouseItem.IsFocus = true;
                        //this.Cursor = Cursors.Hand;
                    }
                    else
                    {
                        mouseItem.IsFocus = false;
                        //this.Cursor = Cursors.Arrow;
                    }

                    this.Invalidate();
                    break;
                }
            }
        }
Esempio n. 2
0
        public void SetWindowTransparency(IntPtr WindowHandle, byte Alpha, ProcessHnd p = null)
        {
            IntPtr windowInfoPtr = WinAPI.GetWindowLongPtr(WindowHandle, WinAPI.GWL_EXSTYLE);
            int    WindowLong    = windowInfoPtr.ToInt32() | WinAPI.WS_EX_LAYERED;

            WinAPI.SetWindowLongPtr(WindowHandle, WinAPI.GWL_EXSTYLE, IntPtr.Add(IntPtr.Zero, WindowLong));
            bool success = WinAPI.SetLayeredWindowAttributes(WindowHandle, 0, Alpha, WinAPI.LWA_ALPHA);

            if (!success)
            {
                MessageBox.Show("无法设置该窗口的透明度", Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (p == null)
            {
                p = thisItem;
            }

            bool canSetTransparency = true;
            byte newAlpha           = GetWindowTransparency(WindowHandle, out canSetTransparency);

            p.CanSetWindowOpacity = canSetTransparency;
            p.WindowOpacity       = newAlpha;
            if (!canSetTransparency)
            {
                MessageBox.Show("无法设置该窗口的透明度", Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 3
0
 protected override void OnMeasureItem(MeasureItemEventArgs e)
 {
     base.OnMeasureItem(e);
     if (Items.Count > 0)
     {
         ProcessHnd item = Items[e.Index];
         e.ItemHeight = 54;
     }
 }
Esempio n. 4
0
        private void lstWindow_SelectedIndexChanged(object sender, EventArgs e)
        {
            //MessageBox.Show(lstWindow.SelectedIndex.ToString());
            btnCancelTopmost.Enabled = btnTopMost.Enabled = lstWindow.SelectedIndex != -1;

            if (lstWindow.SelectedIndex != -1)
            {
                ProcessHnd H = WindowList[lstWindow.SelectedIndex];
                updateTopMostInfo(H.Handle);
            }
        }
Esempio n. 5
0
 private void lstWindow_DoubleClick(object sender, EventArgs e)
 {
     thisItem = WindowList[lstWindow.SelectedIndex];
     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);
     }
 }
Esempio n. 6
0
        private void lstWindow_MouseUp(object sender, MouseEventArgs e)
        {
            MiyukiListBox lst = (MiyukiListBox)lstWindow;

            if (lst.HoverIndex == -1)
            {
                return;
            }

            lst.SelectedIndex = lst.HoverIndex;

            if (e.Button == MouseButtons.Right)
            {
                thisItem = WindowList[lst.HoverIndex];

                menuItemProcessName.Text = "Handle: " + thisItem.Handle.ToString();
                menuItemWindowName.Text  = thisItem.ProcessFileName != "" ? "Process: " + thisItem.ProcessFileName : "No process information";

                if (this.thisItem.Handle == IntPtr.Zero)
                {
                    menuItemWindowTopMost.Enabled = menuItemCancelTopmost.Enabled = false;
                }
                else
                {
                    bool isTopMost = WinAPI.isWindowTopMost(this.thisItem.Handle);
                    menuItemWindowTopMost.Enabled = !isTopMost;
                    menuItemCancelTopmost.Enabled = isTopMost;
                }

                menuItemOpenLocation.Enabled = thisItem.ProcessFileName != "";

                // set checked state with current opacity
                byte opacity = thisItem.WindowOpacity;
                menuItemSetOpacityTo100.Checked = thisItem.CanSetWindowOpacity && (opacity == 255);
                menuItemSetOpacityTo90.Checked  = thisItem.CanSetWindowOpacity && (opacity == 229);
                menuItemSetOpacityTo75.Checked  = thisItem.CanSetWindowOpacity && (opacity == 191);
                menuItemSetOpacityTo50.Checked  = thisItem.CanSetWindowOpacity && (opacity == 127);
                menuItemSetOpacityTo25.Checked  = thisItem.CanSetWindowOpacity && (opacity == 63);
                menuItemSetOpacityTo0.Checked   = thisItem.CanSetWindowOpacity && (opacity == 0);
                //menuItemSetOpacity.Enabled = thisItem.CanSetWindowOpacity;

                contextMenu.Show(this, e.Location);
            }
        }
Esempio n. 7
0
        private void menuGetInfo_Click(object sender, EventArgs e)
        {
            MiyukiListBox lst = (MiyukiListBox)lstWindow;

            if (lst.HoverIndex == -1)
            {
                return;
            }

            thisItem = WindowList[lst.HoverIndex];

            string info = "窗口句柄: " + thisItem.Handle.ToString() + "\r\n";

            info += "窗口名称:" + thisItem.WindowName + "\r\n";
            info += thisItem.ProcessFileName != "" ? "进程名: " + thisItem.ProcessFileName : "无法获取到进程信息,请使用管理员权限运行本程序后再试。";
            info += "\r\n";
            info += "进程位置:" + thisItem.ProcessFullPath + "\r\n";
            //info += "进程物理位置:" + thisItem.ProcessFullPath + "\r\n";

            MessageBox.Show(info, !String.IsNullOrEmpty(thisItem.WindowName) ? thisItem.WindowName : thisItem.Description, MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Esempio n. 8
0
 private void btnCancelTopmost_Click(object sender, EventArgs e)
 {
     thisItem = WindowList[lstWindow.SelectedIndex];
     setTopmostState(WinAPI.HWND_NOTOPMOST);
 }
Esempio n. 9
0
 protected override void OnMouseLeave(EventArgs e)
 {
     base.OnMouseLeave(e);
     this.mouseItem = null;
     this.Invalidate();
 }