示例#1
0
        private void button3_Click_1(object sender, EventArgs e)
        {
            List <WindowInfo> list = GetApplication.GetRunApplicationInfo(this);
            string            pId  = "0";

            list.ForEach(process =>
            {
                //  if (process.szWindowName == "微信")
                {
                    listBox1.Items.Add(process.hWnd + "=====cls:" + process.cls + "=====szWindowName:"
                                       + process.szWindowName + "=====PID:" + process.PID
                                       + "=====AppPath:" + process.AppPath
                                       + "=====Marks:" + process.marks
                                       );
                    TITLEBARINFO pti = new TITLEBARINFO();
                    pti.cbSize       = (uint)System.Runtime.InteropServices.Marshal.SizeOf(pti);
                    bool result      = GetTitleBarInfo((IntPtr)process.hWnd, ref pti);//标题栏的按钮,最大化最小化,关闭

                    TreeNode node = new TreeNode();
                    node.Text     = process.szWindowName + "--" + process.cls + "--" + pti.rgstate[0].ToString();
                    node.Tag      = process.hWnd;// process.cls;
                    pId           = process.PID;
                    RefreshChildNode(treeView1, node, "0");

                    GetHandleNode(process.szWindowName, node);
                }
            });
            treeView1.ExpandAll();
        }
示例#2
0
        /*
         * private void Exit1(int step)
         * {
         *  if (step == 0)
         *  {
         *      pictureBox1.Image = imageList1.Images[12];
         *      this.Top += 5;
         *  }
         *  else if (step < 20)
         *  {
         *      if (step < 10) this.Top += 3;
         *      pictureBox1.Image = imageList1.Images[131 + (step % 2)];
         *  }
         *  else if (step < 50)
         *  {
         *      pictureBox1.Image = imageList1.Images[133];
         *      this.Top += 5;
         *  }
         *  else
         *  {
         *      this.Top = -40;
         *      this.Left = ((Screen.PrimaryScreen.WorkingArea.Width / 120) * GetRandomNumber()) + 100;
         *      this.TopMost = true;
         *
         *      if (GetRandomNumber() < 2)
         *      {
         *          SetNewAnimation(AnimationType.Water);
         *      }
         *      else
         *      {
         *          SetNewAnimation(AnimationType.FallWinDown);
         *      }
         *  }
         * }
         *
         * private void Water(int step)
         * {
         *  if (step == 0)
         *  {
         *      this.TopMost = true;
         *      formX = new Form2();
         *      formX.addImage(imageList1.Images[146]);
         *      formX.addImage(imageList1.Images[147]);
         *      formX.addImage(imageList1.Images[148]);
         *      formX.Enabled = false;
         *      formX.Show();
         *      if (bMoveLeft)
         *      {
         *          formX.Top = Screen.PrimaryScreen.WorkingArea.Height - 40;
         *          formX.Left = (Screen.PrimaryScreen.WorkingArea.Width / 150) * GetRandomNumber() + 200;
         *          this.Left = Screen.PrimaryScreen.WorkingArea.Width + 60;
         *          this.Top = Screen.PrimaryScreen.WorkingArea.Height - (this.Left + 40 - formX.Left);
         *      }
         *      else
         *      {
         *          formX.Top = Screen.PrimaryScreen.WorkingArea.Height - 40;
         *          formX.Left = Screen.PrimaryScreen.WorkingArea.Width - (Screen.PrimaryScreen.WorkingArea.Width / 150) * GetRandomNumber() - 200;
         *          this.Left = -60;
         *          this.Top = Screen.PrimaryScreen.WorkingArea.Height - (-this.Left + 40 + formX.Left);
         *      }
         *
         *      timer1.Interval = 40;
         *
         *      formX.PlayWater((Screen.PrimaryScreen.WorkingArea.Height - this.Top) / 5 - 3);
         *      formX.SetTopLevel(true);
         *      formX.TopMost = true;
         *      this.SetTopLevel(true);
         *  }
         *  else if(step < 20)
         *  {
         *      pictureBox1.Image = imageList1.Images[134];
         *      if (bMoveLeft)
         *          this.Left -= 5;
         *      else
         *          this.Left += 5;
         *      this.Top += 5;
         *  }
         *  else if (134 + (step - 20) / 10 < 145)
         *  {
         *      pictureBox1.Image = imageList1.Images[134 + (step - 20) / 10];
         *      if (bMoveLeft)
         *          this.Left -= 5;
         *      else
         *          this.Left += 5;
         *      this.Top += 5;
         *  }
         *  else
         *  {
         *      if (this.Top >= Screen.PrimaryScreen.WorkingArea.Height - 45)
         *          pictureBox1.Image = imageList1.Images[173];
         *      else
         *          pictureBox1.Image = imageList1.Images[144 + ((step / 7) % 2)];
         *
         *      if (bMoveLeft)
         *          this.Left -= 5;
         *      else
         *          this.Left += 5;
         *      this.Top += 5;
         *
         *      if (this.Top >= Screen.PrimaryScreen.WorkingArea.Height)
         *      {
         *          this.Top  = Screen.PrimaryScreen.WorkingArea.Height - 40;
         *          if (bMoveLeft)
         *              this.Left += 45;
         *          else
         *              this.Left -= 45;
         *          SetNewAnimation(AnimationType.Walk);
         *      }
         *  }
         *
         * }
         *
         * private void WaterX(int step)
         * {
         *  if (step < iWaterSteps - 2)
         *  {
         *      pictureBox1.Image = imageList1.Images[0];
         *  }
         *  else if (step == iWaterSteps - 2)
         *  {
         *      timer1.Interval = 150;
         *      pictureBox1.Image = imageList1.Images[1];
         *  }
         *  else if (step == iWaterSteps - 1)
         *  {
         *      pictureBox1.Image = imageList1.Images[2];
         *  }
         *  else if (step == iWaterSteps)
         *  {
         *      pictureBox1.Image = imageList1.Images[1];
         *  }
         *  else
         *  {
         *      this.Close();
         *  }
         * }
         *
         */

        private bool CheckTopWindow(bool bCheck)
        {
            if ((int)hwndWindow != 0)
            {
                RECT rctO;
                RECT rct;
                GetWindowRect(new HandleRef(this, hwndWindow), out rctO);

                if (bCheck)
                {
                    if (rctO.Top > Top + Height + 2)
                    {
                        return(true);
                    }
                    else if (rctO.Top < Top + Height - 2)
                    {
                        return(true);
                    }
                    else if (rctO.Left > Left + Width - 5)
                    {
                        return(true);
                    }
                    else if (rctO.Right < Left + 5)
                    {
                        return(true);
                    }
                }

                TITLEBARINFO titleBarInfo = new TITLEBARINFO();
                titleBarInfo.cbSize = Marshal.SizeOf(titleBarInfo);

                IntPtr hwnd2 = GetWindow(hwndWindow, 3);
                while (hwnd2 != (IntPtr)0)
                {
                    StringBuilder sTitle = new StringBuilder(128);
                    GetWindowText(hwnd2, sTitle, 128);

                    if (GetTitleBarInfo(hwnd2, ref titleBarInfo))
                    {
                        if (sTitle.Length > 0 && GetWindowRect(new HandleRef(this, hwnd2), out rct) && (titleBarInfo.rcTitleBar.Bottom > 0 || sTitle.ToString() == "sheep"))
                        {
                            if (rct.Top < rctO.Top && rct.Bottom > rctO.Top)
                            {
                                if (rct.Left < Left && rct.Right > Left + 40 && iAnimationStep > 4)
                                {
                                    return(true);
                                }
                            }
                        }
                    }
                    hwnd2 = GetWindow(hwnd2, 3);
                }
            }
            return(false);
        }
示例#3
0
        public static bool IsAltTabWindow(IntPtr hWnd)
        {
            if (!IsWindowVisible(hWnd))
            {
                return(false);
            }

            var hwndWalk = IntPtr.Zero;
            var hwndTry  = GetAncestor(hWnd, GetAncestorFlags.GetRootOwner);

            while (hwndTry != hwndWalk)
            {
                hwndWalk = hwndTry;
                hwndTry  = GetLastActivePopup(hwndWalk);
                if (IsWindowVisible(hwndTry))
                {
                    break;
                }
            }

            if (hwndWalk != hWnd)
            {
                return(false);
            }

            var ti = new TITLEBARINFO();

            ti.cbSize = (uint)Marshal.SizeOf(ti);
            GetTitleBarInfo(hWnd, ref ti);
            if ((ti.rgstate[0] & STATE_SYSTEM_INVISIBLE) != 0)
            {
                return(false);
            }

            if (IsExToolWindow(hWnd))
            {
                return(false);
            }

            return(true);
        }
示例#4
0
 public static extern bool GetTitleBarInfo(HWND hWnd, ref TITLEBARINFO pti);
示例#5
0
 internal static extern bool GetTitleBarInfo(IntPtr hWnd, ref TITLEBARINFO pti);
示例#6
0
 public static extern bool GetTitleBarInfo(
     IntPtr hwnd,
     ref TITLEBARINFO pti
     );
示例#7
0
        public void resetList()
        {
            List<IntPtr> temp = new List<IntPtr>();
            EnumWindows(delegate(IntPtr hWnd, IntPtr lParam)
            {
                temp.Add(hWnd);
                return true;
            }, IntPtr.Zero);

            foreach (IntPtr hWnd in temp)
            {
                TITLEBARINFO ti = new TITLEBARINFO();
                GetTitleBarInfo(hWnd, ref ti);
                if ((ti.rgstate[0] & STATE_SYSTEM_INVISIBLE) == STATE_SYSTEM_INVISIBLE)
                {
                    continue;
                }

                if ((GetWindowLong(hWnd, GWL_EXSTYLE) & WS_EX_TOOLWINDOW) == WS_EX_TOOLWINDOW)
                {
                    continue;
                }

                int length = GetWindowTextLength(hWnd);
                if (length++ > 0 && IsWindowVisible(hWnd))
                {
                    StringBuilder b = new StringBuilder(length);
                    GetWindowText(hWnd, b, b.Capacity);
                    if (IsHandleCreated)
                    {
                        this.Invoke((MethodInvoker)delegate
                        {
                            if(!windowNameList.Items.Contains(b.ToString()))
                            {
                                if(!windows.Contains(hWnd))
                                    windows.Add(hWnd);
                                windowNameList.Items.Add(b.ToString());
                            }
                        });
                    }
                }
            }
        }
示例#8
0
 private static extern bool GetTitleBarInfo(IntPtr hWnd, ref TITLEBARINFO tbi);
示例#9
0
 public static extern bool GetTitleBarInfo(IntPtr hwnd, ref TITLEBARINFO pti);
        /// <summary>
        /// The hook procedure for window messages generated by the FileOpenDialog
        /// </summary>
        /// <param name="hWnd">the handle of the window at which this message is targeted</param>
        /// <param name="msg">the message identifier</param>
        /// <param name="wParam">message-specific parameter data</param>
        /// <param name="lParam">mess-specific parameter data</param>
        /// <returns></returns>
        public IntPtr MyHookProc(IntPtr hWnd, UInt32 msg, Int32 wParam, Int32 lParam)
        {
            try
            {
                if (hWnd == IntPtr.Zero)
                {
                    return(IntPtr.Zero);
                }

                switch (msg)
                {
                // We're not interested in every possible message; just return a NULL for those we don't care about
                default:
                {
                    return(IntPtr.Zero);
                }

                // WM_INITDIALOG - at this point the OpenFileDialog exists, so we pull the user-supplied control
                // into the FileOpenDialog now, using the SetParent API.
                case WM.INITDIALOG:
                {
                    _hWndParent = User32.GetParent(hWnd);

                    //setting a bool for whether the OS is RTL (not the installed language of WLW)
                    IsRTL = (User32.GetWindowLong(_hWndParent, User32.GWL_EXSTYLE) & User32.WS_EX_LAYOUTRTL) > 0;

                    //account for large title bar, borders for adjusting control locations
                    TITLEBARINFO titleBarInfo = new TITLEBARINFO();
                    titleBarInfo.cbSize = (uint)Marshal.SizeOf(titleBarInfo);
                    if (!User32.GetTitleBarInfo(_hWndParent, ref titleBarInfo))
                    {
                        throw new Win32Exception(Marshal.GetLastWin32Error());
                    }

                    WINDOWINFO info = new WINDOWINFO();
                    info.cbSize = (uint)Marshal.SizeOf(info);
                    if (!User32.GetWindowInfo(_hWndParent, ref info))
                    {
                        throw new Win32Exception(Marshal.GetLastWin32Error());
                    }

                    _extraWindowHeight = (titleBarInfo.rcTitleBar.bottom - titleBarInfo.rcTitleBar.top) + 2 * (int)info.cyWindowBorders;
                    _extraWindowWidth  = 2 * (int)info.cxWindowBorders;

                    Rectangle rcClient = new Rectangle(0, 0, 0, 0);
                    // Get client rectangle of dialog
                    RECT rcTemp = new RECT();
                    User32.GetWindowRect(_hWndParent, ref rcTemp);
                    rcClient.X      = rcTemp.left;
                    rcClient.Y      = rcTemp.top;
                    rcClient.Width  = rcTemp.Width;
                    rcClient.Height = rcTemp.Height + TABS_HEIGHT + BUTTONS_HEIGHT;
                    //make the dialog box bigger
                    User32.MoveWindow(_hWndParent, rcClient.Left, rcClient.Top, rcClient.Width, rcClient.Height, true);
                    //move all the controls down
                    AdjustControlLocations();
                    //top tab control
                    mainTabControl = new LightweightControlContainerControl();
                    User32.SetParent(mainTabControl.Handle, _hWndParent);
                    mainTabControl.Location = new Point(0, 0);
                    mainTabControl.Anchor   = AnchorStyles.Left | AnchorStyles.Right;
                    mainTabControl.Size     = new Size(rcClient.Width, TABS_HEIGHT);

                    tabs = new TabLightweightControl();
                    tabs.ColorizeBorder = false;
                    tabs.VirtualBounds  = new Rectangle(0, 0, rcClient.Width, TABS_HEIGHT);
                    tabs.LightweightControlContainerControl = mainTabControl;
                    tabs.DrawSideAndBottomTabPageBorders    = false;

                    InsertImageTabControl tabFromFile = new InsertImageTabControl();
                    tabFromFile.TabText   = Res.Get(StringId.InsertImageInsertFromFile);
                    tabFromFile.TabBitmap = ResourceHelper.LoadAssemblyResourceBitmap("ImageInsertion.Images.TabInsertFromFile.png");
                    tabFromFile.BackColor = SystemColors.Control;
                    User32.SetParent(tabFromFile.Handle, _hWndParent);
                    tabs.SetTab(0, tabFromFile);

                    mainTabControl.BackColor = tabFromFile.ApplicationStyle.InactiveTabTopColor;

                    //now, add tabs for the other controls
                    int i = 1;
                    foreach (InsertImageSource imageSource in imageSources)
                    {
                        InsertImageTabControl tab = new InsertImageTabControl();
                        tab.TabText   = imageSource.TabName;
                        tab.TabBitmap = imageSource.TabBitmap;
                        tab.BackColor = SystemColors.Control;
                        tabs.SetTab(i++, tab);
                    }

                    tabs.SelectedTabNumberChanged += new EventHandler(tabs_SelectedTabNumberChanged);

                    //set the keyboard hook for tab switching
                    tabKeyboardHook = new TabbingHookProc(tabs);
                    tabKeyboardHook.Install(_hWndParent);

                    //add other image source panels
                    _panelImage             = new Panel();
                    _panelImage.Location    = new Point(0, mainTabControl.Size.Height);
                    _panelImage.BorderStyle = BorderStyle.None;
                    _panelImage.Anchor      = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom;
                    _panelImage.Size        = new Size(rcClient.Width, rcClient.Height - TABS_HEIGHT - BUTTONS_HEIGHT - _extraWindowHeight);
                    _panelImage.Visible     = false;

                    User32.SetParent(_panelImage.Handle, _hWndParent);

                    //initalize the other sources
                    foreach (InsertImageSource source in imageSources)
                    {
                        source.Init(_panelImage.Width, _panelImage.Height);
                        Control c = source.ImageSelectionControls;
                        DisplayHelper.Scale(c);
                        foreach (Control childControl in c.Controls)
                        {
                            DisplayHelper.Scale(childControl);
                        }
                    }
                    DisplayHelper.Scale(_panelImage);

                    //special cancel button
                    _buttonPanel             = new Panel();
                    _buttonPanel.Location    = new Point(rcClient.Width - (int)(0.5 * _extraWindowWidth) - _buttonPanel.Width, _panelImage.Bounds.Bottom);
                    _buttonPanel.Size        = new Size(75, 23);
                    _buttonPanel.BorderStyle = BorderStyle.None;

                    _cancelButton           = new Button();
                    _cancelButton.TextAlign = ContentAlignment.MiddleCenter;
                    if (BidiHelper.IsRightToLeft)
                    {
                        _cancelButton.RightToLeft = RightToLeft.Yes;
                    }
                    _cancelButton.Text      = Res.Get(StringId.CancelButton);
                    _cancelButton.FlatStyle = FlatStyle.System;
                    _cancelButton.Location  = new Point(0, 0);
                    _cancelButton.Size      = new Size(75, 23);
                    _cancelButton.Click    += new EventHandler(_cancelButton_Click);

                    _buttonPanel.Controls.Add(_cancelButton);

                    User32.SetParent(_buttonPanel.Handle, _hWndParent);

                    int    origWidth = _cancelButton.Width;
                    string tmp       = _cancelButton.Text;
                    _cancelButton.Text = Res.Get(StringId.InsertImageButton);
                    int newWidth = Math.Max(origWidth, DisplayHelper.MeasureButton(_cancelButton));
                    _cancelButton.Text = tmp;
                    newWidth           = Math.Max(newWidth, DisplayHelper.MeasureButton(_cancelButton));

                    _buttonPanel.Width = _cancelButton.Width = newWidth;
                    int deltaX = newWidth - origWidth;
                    _buttonPanel.Left -= deltaX;

                    //fixing up button text and tab order
                    IntPtr hWndOpenButton = User32.GetDlgItem(_hWndParent, _OPEN_BUTTON_ID);
                    User32.SetWindowText(hWndOpenButton, Res.Get(StringId.InsertImageButton));

                    mainTabControl.InitFocusManager();
                    mainTabControl.AddFocusableControls(tabs.GetAccessibleControls());
                    foreach (InsertImageSource tabPage in imageSources)
                    {
                        mainTabControl.AddFocusableControl(tabPage.ImageSelectionControls);
                    }

                    state = STATE.FILE;

                    return(IntPtr.Zero);
                }

                case WM.SIZE:
                {
                    ManipulatePanels();
                    return(IntPtr.Zero);
                }

                // WM_NOTIFY - we're only interested in the CDN_SELCHANGE notification message:
                // we grab the currently-selected filename and copy it into the buffer
                case WM.NOTIFY:
                {
                    IntPtr   ipNotify = new IntPtr(lParam);
                    OfNotify ofNot    = (OfNotify)Marshal.PtrToStructure(ipNotify, typeof(OfNotify));
                    Int16    code     = (short)ofNot.hdr.code;
                    if (code == CommonDlgNotification.SelChange)
                    {
                        UpdateChosenImage(false);
                        //CheckOptions(false);
                    }
                    else if (code == CommonDlgNotification.InitDone)
                    {
                        listener = new CommandListener(_hWndParent, this, (int)User32.GetDlgCtrlID(_cancelButton.Handle));
                    }
                    else if (code == CommonDlgNotification.FileOk)
                    {
                        // update the image path (need to do this if the user selected
                        // a file by simpliy typing in the filepath text box)
                        UpdateChosenImage(true);

                        // ok to insert
                        _insertFile = true;
                    }
                    else if ((code == CommonDlgNotification.FolderChange) && (state == STATE.WEB))
                    {
                        // If the user hits the OK button while there is no valid selection
                        // within the File panel, the file dialog sends a CommonDlgNotification.FolderChange
                        // We use this combined with other relevant state to trigger the closing
                        // of the Image dialog
                        HitOpen();
                    }
                    return(IntPtr.Zero);
                }
                }
            }
            catch (Exception ex)
            {
                UnexpectedErrorMessage.Show(ex);
                return(new IntPtr(1));
            }
            finally
            {
                GC.KeepAlive(this);
            }
        }
示例#11
0
 public extern static bool GetTitleBarInfo(IntPtr hwnd, out TITLEBARINFO pti);
示例#12
0
        protected override IntPtr HookProc(IntPtr nColorDialogHandle, int msg, IntPtr wparam, IntPtr lparam)
        {
            IntPtr returnValue = base.HookProc(nColorDialogHandle, msg, wparam, lparam);

            if (msg == WM_INITDIALOG)
            {
                IntPtr[] oStaticHandleArray = new IntPtr[9];
                // Change the window title
                SetWindowText(nColorDialogHandle, sColorPickerText);
                // Get titlebar info for calculations later
                TITLEBARINFO oTITLEBARINFO = new TITLEBARINFO();
                oTITLEBARINFO.cbSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(oTITLEBARINFO);
                GetTitleBarInfo(nColorDialogHandle, ref oTITLEBARINFO);
                // Change the text of the "Basic colors:" label
                oStaticHandleArray[0] = GetDlgItem(nColorDialogHandle, 0xFFFF);
                SetWindowText(oStaticHandleArray[0], sBasicColorsText);

                // Change the text of the "Define Custom Colors >>" button
                SetWindowText(GetDlgItem(nColorDialogHandle, 0x2CF), sDefineCustomColorsButtonText);
                // Save the "OK" button size and new width
                Rectangle oOKButtonRect  = new Rectangle();
                int       nOKButtonWidth = (int)oGraphics.MeasureString(sOKButtonText, new Font("Microsoft Sans Serif", 8, FontStyle.Regular)).Width + 20;                    // +20 accounts for extra +10 padding on either side
                // Find the "OK" Button
                IntPtr nChildHandle = GetDlgItem(nColorDialogHandle, 0x1);
                if (nChildHandle.ToInt32() > 0)
                {
                    // The "OK" button was found
                    // Now save the current size and position
                    GetWindowRect(nChildHandle.ToInt32(), ref oOKButtonRect);
                    // We have to subtract oOKButtonRect.X value from oOKButtonRect.Width to obtain the "real" button width (same thing with subtracting Y value from Height)
                    oOKButtonRect.Width  = oOKButtonRect.Width - oOKButtonRect.X;
                    oOKButtonRect.Height = oOKButtonRect.Height - oOKButtonRect.Y;
                    // Resize the "OK" button so that the new text fits properly
                    // NOTE: I cannot be sure 100% if it is correct to use the titlebar to find the position of the button or not but the math works out in all of my tests
                    MoveWindow(nChildHandle, oOKButtonRect.X - oTITLEBARINFO.rcTitleBar.X, oOKButtonRect.Y - oTITLEBARINFO.rcTitleBar.Y - oTITLEBARINFO.rcTitleBar.Height, nOKButtonWidth, oOKButtonRect.Height, true);
                    // Finally, change the button text
                    SetWindowText(nChildHandle, sOKButtonText);
                }
                // Find the "Cancel" Button
                nChildHandle = GetDlgItem(nColorDialogHandle, 0x2);
                if (nChildHandle.ToInt32() > 0)
                {
                    // The "Cancel" button was found
                    // Now get the current size and position
                    Rectangle oCancelButtonRect = new Rectangle();
                    GetWindowRect(nChildHandle.ToInt32(), ref oCancelButtonRect);
                    // We have to subtract oCancelButtonRect.X value from oCancelButtonRect.Width to obtain the "real" button width (same thing with subtracting Y value from Height)
                    oCancelButtonRect.Width  = oCancelButtonRect.Width - oCancelButtonRect.X;
                    oCancelButtonRect.Height = oCancelButtonRect.Height - oCancelButtonRect.Y;
                    // Resize the "Cancel" button so that the new text fits properly
                    // NOTE: I cannot be sure 100% if it correct to use the titlebar to find the position of the button or not but the math works out in all of my tests
                    MoveWindow(nChildHandle, oOKButtonRect.X + nOKButtonWidth - oTITLEBARINFO.rcTitleBar.X + 6, oCancelButtonRect.Y - oTITLEBARINFO.rcTitleBar.Y - oTITLEBARINFO.rcTitleBar.Height, (int)oGraphics.MeasureString(sCancelButtonText, new Font("Microsoft Sans Serif", 8, FontStyle.Regular)).Width + 20, oCancelButtonRect.Height, true);
                    // Finally, change the button text
                    SetWindowText(nChildHandle, sCancelButtonText);
                }
                // Change the text of the "Add to Custom Colors" button
                SetWindowText(GetDlgItem(nColorDialogHandle, 0x2C8), sAddToCustomColorsButtonText);
                // Change the text of the "Color" label text
                oStaticHandleArray[1] = GetDlgItem(nColorDialogHandle, 0x2DA);
                SetWindowText(oStaticHandleArray[1], sColorText);
                // Change the text of the "Solid" label text
                oStaticHandleArray[2] = GetDlgItem(nColorDialogHandle, 0x2DB);
                SetWindowText(oStaticHandleArray[2], sSolidText);
                // Change the text of the "Hue:" label
                oStaticHandleArray[3] = GetDlgItem(nColorDialogHandle, 0x2D3);
                SetWindowText(oStaticHandleArray[3], sHueText);
                // Change the text of the "Sat:" label
                oStaticHandleArray[4] = GetDlgItem(nColorDialogHandle, 0x2D4);
                SetWindowText(oStaticHandleArray[4], sSatText);
                // Change the text of the "Lum:" label
                oStaticHandleArray[5] = GetDlgItem(nColorDialogHandle, 0x2D5);
                SetWindowText(oStaticHandleArray[5], sLumText);
                // Change the text of the "Red:" label
                oStaticHandleArray[6] = GetDlgItem(nColorDialogHandle, 0x2D6);
                SetWindowText(oStaticHandleArray[6], sRedText);
                // Change the text of the "Green:" label
                oStaticHandleArray[7] = GetDlgItem(nColorDialogHandle, 0x2D7);
                SetWindowText(oStaticHandleArray[7], sGreenText);
                // Change the text of the "Blue:" label
                oStaticHandleArray[8] = GetDlgItem(nColorDialogHandle, 0x2D8);
                SetWindowText(oStaticHandleArray[8], sBlueText);
                // Change the text of the "Custom Colors:" label
                SetCustomColorsText(nColorDialogHandle, oStaticHandleArray);
            }
            return(returnValue);
        }
示例#13
0
        private int FallDetect(int y)
        {
            RECT rct;
            Dictionary <IntPtr, string> windows = new Dictionary <IntPtr, string>();
            TITLEBARINFO titleBarInfo           = new TITLEBARINFO();

            titleBarInfo.cbSize = Marshal.SizeOf(titleBarInfo);

            EnumWindows(delegate(IntPtr hWnd, int lParam)
            {
                if (hWnd == Handle)
                {
                    return(true);
                }

                if (IsWindowVisible(hWnd))
                {
                    StringBuilder sTitle = new StringBuilder(128);
                    GetWindowText(hWnd, sTitle, 128);

                    if (sTitle.ToString() == "Sheep")
                    {
                        ;
                    }
                    else if (!GetTitleBarInfo(hWnd, ref titleBarInfo))
                    {
                        return(true);
                    }
                    else if ((titleBarInfo.rgstate[0] & 0x00008000) > 0)
                    {
                        return(true);                                                    // invisible
                    }
                    if (sTitle.Length > 0)
                    {
                        windows[hWnd] = sTitle.ToString();
                    }
                }
                return(true);
            }, 0);

            foreach (KeyValuePair <IntPtr, string> window in windows)
            {
                if (GetWindowRect(new HandleRef(this, window.Key), out rct))
                {
                    //Console.WriteLine("Window title: {0}", window.Value);

                    if (Top + Height < rct.Top && Top + Height + y >= rct.Top &&
                        Left >= rct.Left - Width / 2 && Left + Width <= rct.Right + Width / 2 &&
                        Top > 30)
                    {
                        hwndWindow = window.Key;
                        if (!CheckTopWindow(false))
                        {
                            ShowWindow(window.Key, 0);
                            ShowWindow(window.Key, 5);
                            return(rct.Top);
                        }
                        else
                        {
                            hwndWindow = (IntPtr)0;
                        }
                    }
                }
            }
            return(-1);
        }
示例#14
0
 public static extern bool GetTitleBarInfo(HWND hWnd, ref TITLEBARINFO pti);
示例#15
0
        public static List <WindowInfo> GetRunApplicationInfo(Form form)
        {
            List <WindowInfo> appList = new List <WindowInfo>();

            myPropeNumProca = new PROPENUMPROCA(myPropeNumProcaReport);
            try
            {
                int handle = (int)form.Handle;
                //   int handle = (int)GetDesktopWindow();
                int    hwCurr;
                IntPtr hwChild;
                hwCurr = GetWindow(handle, GW_HWNDFIRST);
                // hwCurr = GetWindow(handle, 5);
                while (hwCurr > 0)
                {
                    //| WS_BORDER
                    int  isTask     = (WS_VISIBLE);
                    int  lngStyle   = GetWindowLongA(hwCurr, GWL_STYLE);
                    bool taskWindow = ((lngStyle & isTask) == isTask);
                    if (taskWindow)
                    {
                        int           length = GetWindowTextLength(new IntPtr(hwCurr));
                        StringBuilder sb     = new StringBuilder(256);
                        GetWindowText(hwCurr, sb, sb.Capacity);
                        string strTitle = sb.ToString();
                        if (!string.IsNullOrEmpty(strTitle))
                        {
                            WindowInfo wnd = new WindowInfo();
                            wnd.hWnd         = new IntPtr(hwCurr);
                            wnd.szWindowName = strTitle;                        //窗口title名称
                            sb.Clear();
                            GetClassNameW(new IntPtr(hwCurr), sb, sb.Capacity); //类名
                            wnd.cls = sb.ToString();
                            sb.Clear();
                            GetWindowTextW(new IntPtr(hwCurr), sb, sb.Capacity);
                            wnd.app = sb.ToString();
                            int PID;
                            GetWindowThreadProcessId(new IntPtr(hwCurr), out PID);
                            wnd.PID = PID.ToString();
                            sb.Clear();
                            GetWindowModuleFileNameA(new IntPtr(hwCurr), sb, sb.Capacity);
                            wnd.AppPath = sb.ToString();
                            sb.Clear();
                            // GetClassInfoExW(new IntPtr(hwCurr), sb, sb.Capacity);获取不到值
                            // wnd.marks = sb.ToString();
                            // GetPropA(new IntPtr(hwCurr), sb);
                            // wnd.marks = sb.ToString();
                            //枚举属性
                            // EnumPropsA(new IntPtr(hwCurr), myPropeNumProca);

                            TITLEBARINFO pti = new TITLEBARINFO();
                            pti.cbSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(pti);
                            bool result = GetTitleBarInfo(new IntPtr(hwCurr), ref pti);
                            // wnd.marks = pti.rgstate.FirstOrDefault()..ToString();
                            appList.Add(wnd);
                        }
                    }
                    hwCurr = GetWindow(hwCurr, GW_HWNDNEXT);
                }
                return(appList);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        //this sometimes returns false positives for tray icons and similar
        //it's never caused any real problems, so I'm not super-interested in fixing it,
        //but I am interested in knowing if there's a better method for doing this in case
        //I need to do it again in the future
        private bool isAltTabWindow(IntPtr hWnd)
        {
            if (!IsWindowVisible(hWnd)) { return false; }

            IntPtr hWndWalk = IntPtr.Zero;
            IntPtr hWndTry = GetAncestor(hWnd, GetAncestor_Flags.GetRootOwner);
            while (hWndTry != hWndWalk)
            {
                hWndWalk = hWndTry;
                hWndTry = GetLastActivePopup(hWndWalk);
                if (IsWindowVisible(hWndTry)) { break; }
            }
            if (hWndWalk != hWnd) { return false; }

            TITLEBARINFO ti = new TITLEBARINFO();
            ti.cbSize = (uint)Marshal.SizeOf(ti);
            GetTitleBarInfo(hWnd, ref ti);
            if (ti.rgstate[0] == 0x8000) { return false; }

            if (GetWindowLong(hWnd, -20) == 0x80) { return false; }

            return true;
        }