Пример #1
0
        //KILL. ME.
        public void PopulateCheckboxes(int hWnd)
        {
            User32.tagWINDOWINFO info = new User32.tagWINDOWINFO();
            User32.GetWindowInfo(hWnd, out info);

            ClearChecks();

            if ((info.dwStyle & User32.WS_BORDER) != 0)
                winOptions.SetItemChecked( 0, true );
            if ((info.dwStyle & User32.WS_CAPTION) != 0)
                winOptions.SetItemChecked( 1, true );
            if ((info.dwStyle & User32.WS_CHILD) != 0)
                winOptions.SetItemChecked( 2, true );
            if ((info.dwStyle & User32.WS_CLIPCHILDREN) != 0)
                winOptions.SetItemChecked( 3, true );
            if ((info.dwStyle & User32.WS_CLIPSIBLINGS) != 0)
                winOptions.SetItemChecked( 4, true );
            if ((info.dwStyle & User32.WS_DISABLED) != 0)
                winOptions.SetItemChecked( 5, true );
            if ((info.dwStyle & User32.WS_DLGFRAME) != 0)
                winOptions.SetItemChecked( 6, true );
            if ((info.dwStyle & User32.WS_GROUP) != 0)
                winOptions.SetItemChecked( 7, true );
            if ((info.dwStyle & User32.WS_HSCROLL) != 0)
                winOptions.SetItemChecked( 8, true );
            if ((info.dwStyle & User32.WS_MAXIMIZE) != 0)
                winOptions.SetItemChecked( 9, true );
            if ((info.dwStyle & User32.WS_MAXIMIZEBOX) != 0)
                winOptions.SetItemChecked( 10, true );
            if ((info.dwStyle & User32.WS_MINIMIZE) != 0)
                winOptions.SetItemChecked(11, true);
            if ((info.dwStyle & User32.WS_MINIMIZEBOX) != 0)
                winOptions.SetItemChecked(12, true);
            if ((info.dwStyle & User32.WS_OVERLAPPED) != 0)
                winOptions.SetItemChecked(13, true);
            if ((info.dwStyle & User32.WS_POPUP) != 0)
                winOptions.SetItemChecked(14, true);
            if ((info.dwStyle & User32.WS_SYSMENU) != 0)
                winOptions.SetItemChecked(15, true);
            if ((info.dwStyle & User32.WS_TABSTOP) != 0)
                winOptions.SetItemChecked(16, true);
            if ((info.dwStyle & User32.WS_THICKFRAME) != 0)
                winOptions.SetItemChecked(17, true);
            if ((info.dwStyle & User32.WS_VISIBLE) != 0)
                winOptions.SetItemChecked(18, true);
            if ((info.dwStyle & User32.WS_VSCROLL) != 0)
                winOptions.SetItemChecked(19, true);
        }
Пример #2
0
        //Update the checkboxes on the "advanced" window
        public void UpdateOptions(int hWnd)
        {
            User32.tagWINDOWINFO info = new User32.tagWINDOWINFO();
            User32.GetWindowInfo(hWnd, out info);

            int WinStyle = 0; //0 = normal, 1 = min, 2 = max
            int BorderStyle = 0; //0 = none, 1 = single, etc...

            #region GetWindowStyle
            if ((info.dwStyle & User32.WS_MINIMIZE) != 0)
                WinStyle = 1;
            else if ((info.dwStyle & User32.WS_MAXIMIZE) != 0)
                WinStyle = 2;

            comboWinStyle.SelectedIndex = WinStyle;
            #endregion

            #region GetBorderStyle
            if ((info.dwStyle & User32.WS_BORDER) != 0)
            {
                BorderStyle = 1;

                if ((info.dwStyle & User32.WS_POPUP) != 0)
                {
                 //   BorderStyle = 2;

                    if ((info.dwStyle & User32.WS_THICKFRAME) != 0)
                    {
                    //    BorderStyle = 3;
                    }
                }

            }

            comboBorderStyle.SelectedIndex = BorderStyle;
            #endregion

            adv.PopulateCheckboxes(hWnd);
        }
Пример #3
0
        private void ModifyProperties(ProgramSettings settings, IntPtr Handle)
        {
            //System.Threading.Thread.Sleep(3000);
            User32.tagWINDOWINFO info = new User32.tagWINDOWINFO();
            User32.GetWindowInfo((int)Handle, out info);
            uint lStyle = (uint)info.dwStyle;
            //Console.WriteLine(lStyle);

            switch (settings.Borderstyle)
            {
                case BorderStyle.NONE: //None
                    lStyle &= ~(User32.WS_CAPTION | User32.WS_BORDER);
                    break;

                case BorderStyle.SIZABLE: //Sizable
                    lStyle = lStyle | User32.WS_CAPTION;
                    lStyle = lStyle | User32.WS_BORDER;
                    break;

                case BorderStyle.CUSTOM: //Custom
                    lStyle = settings.Style;
                    break;

                default:
                    break;
            }

            User32.SetWindowLong(Handle, (int)User32.WindowLongFlags.GWL_STYLE, (int)lStyle);
            User32.SetWindowPos(Handle, IntPtr.Zero, info.rcWindow.Left, info.rcWindow.Top, info.rcWindow.Right - info.rcWindow.Left, info.rcWindow.Bottom - info.rcWindow.Top, User32.SetWindowPosFlags.FrameChanged);

            switch (settings.WindowState)
            {
                case WinState.NORMAL: //Normal
                    User32.ShowWindowAsync(Handle, 1);
                    break;

                case WinState.MINIMIZED: //Minimized
                    User32.ShowWindowAsync(Handle, 2);
                    break;

                case WinState.MAXIMIZED: //Maximised
                    User32.ShowWindowAsync(Handle, 3);
                    break;

                default:
                    break;
            }
        }
Пример #4
0
        //Callback for winAPI. enumerates through all the current windows
        private bool EnumWindows( int hWnd, int lParam )
        {
            User32.tagWINDOWINFO info = new User32.tagWINDOWINFO();
            User32.GetWindowInfo(hWnd, out info);

            if (hWnd != 0 && ((info.dwStyle & User32.WS_VISIBLE) != 0)/*&& ((info.dwStyle & User32.WS_GROUP) != 0)*/) //Window is valid, visible, and
            {
                //The next three lines are all just getting the window title of the handle
                int capacity = User32.GetWindowTextLength(new HandleRef(null, (IntPtr)hWnd)) * 2;
                StringBuilder stringBuilder = new StringBuilder(capacity);
                User32.GetWindowText(new HandleRef(null, (IntPtr)hWnd), stringBuilder, stringBuilder.Capacity);

                //Program manager/Start aren't technically windows, and we don't want anything to do with them.
                //Start is the desktop, and Program Manager is something that manages programs. (Who knew!)
                if (stringBuilder.Length > 0 && stringBuilder.ToString() != "Program Manager" && stringBuilder.ToString() != "Start")
                {
                    //Get the process ID
                    int id = 0;
                    User32.GetWindowThreadProcessId((IntPtr)hWnd, out id);
                    //We're going to use the process so we can get some useful info out of it
                    System.Diagnostics.Process p = System.Diagnostics.Process.GetProcessById(id);

                    //Create a new window class (A class that just holds some important info about the current windows)
                    Window win = new Window();
                    win.Title = stringBuilder.ToString();
                    win.Handle = hWnd;
                    //win.Icon = User32.GetSmallIcon(p.MainModule.FileName); //I wanted to get the little 16x16 icon like the task manager, but it seemed like a huge task
                    windows.Add(win); //Add it to our list of windows

                    //Replacing the little icon I have a little sign of whether the window is responding or not.
                    //Doesn't look half bad if I say so myself
                    int index = 1;
                    if (p.Responding) index = 0;

                    //Finally, add the window to the listview
                    listWindows.Items.Add(win.Title);
                    listWindows.Items[listWindows.Items.Count -1].ImageIndex = index;
                }

            }
            //We must return true so we keep enumerating to the next window
            return true;
        }
Пример #5
0
        private void buttonAccept_Click(object sender, EventArgs e)
        {
            if (windows.Count <= 0 || listWindows.SelectedIndices.Count <= 0) return; //If there are zero windows or nothing is selected, do nothing

            Window w = windows[listWindows.SelectedItems[0].Index];

            //Get some information for the selected window, to be used in settings its style
            User32.tagWINDOWINFO info = new User32.tagWINDOWINFO();
            User32.GetWindowInfo(w.Handle, out info);

            //Get the current windows style
            uint lStyle = (uint)info.dwStyle;
            Console.WriteLine(lStyle); //DEBUG

            switch (comboBorderStyle.SelectedIndex)
            {
                case 0: //None
                    lStyle &= ~(User32.WS_CAPTION | User32.WS_BORDER ); //Bit shit that shift
                    break;

                case 1: //Sizable
                    lStyle = lStyle | User32.WS_CAPTION; //These two enumerations make the border exist
                    lStyle = lStyle | User32.WS_BORDER;
                    break;

                case 2: //Custom
                    lStyle = GetCustomStyle(); //Get the custom style selected in the advanced menu
                    break;

                default:
                    break;
            }

            //Set the window properties
            User32.SetWindowLong((IntPtr)w.Handle, (int)User32.WindowLongFlags.GWL_STYLE, (int)lStyle);

            //Window settings are cached, so we must set the position to update them
            User32.SetWindowPos((IntPtr)w.Handle, IntPtr.Zero, info.rcWindow.Left, info.rcWindow.Top, info.rcWindow.Right - info.rcWindow.Left, info.rcWindow.Bottom - info.rcWindow.Top, User32.SetWindowPosFlags.FrameChanged);

            //Now for the Window State
            switch (comboWinStyle.SelectedIndex)
            {
                case 0: //Normal
                    User32.ShowWindowAsync((IntPtr)w.Handle, 1);
                    break;

                case 1: //Minimized
                    User32.ShowWindowAsync((IntPtr)w.Handle, 2);
                    break;

                case 2: //Maximised
                    User32.ShowWindowAsync((IntPtr)w.Handle, 3);
                    break;

                default:
                    break;
            }
        }