Example #1
0
        private void ModifyProperties(ProgramSettings settings, IntPtr Handle)
        {
            //System.Threading.Thread.Sleep(3000);
            Win32Api.tagWINDOWINFO info = new Win32Api.tagWINDOWINFO();
            Win32Api.GetWindowInfo((int)Handle, out info);
            uint lStyle = (uint)info.dwStyle;

            //Console.WriteLine(lStyle);

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

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

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

            default:
                break;
            }

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

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

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

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

            default:
                break;
            }
        }
Example #2
0
        //Callback for winAPI. enumerates through all the current windows
        private bool EnumWindows(int hWnd, int lParam)
        {
            Win32Api.tagWINDOWINFO info = new Win32Api.tagWINDOWINFO();
            Win32Api.GetWindowInfo(hWnd, out info);

            if (hWnd != 0 && ((info.dwStyle & Win32Api.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      = Win32Api.GetWindowTextLength(new HandleRef(null, (IntPtr)hWnd)) * 2;
                StringBuilder stringBuilder = new StringBuilder(capacity);
                Win32Api.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;
                    Win32Api.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);
        }
Example #3
0
        //Update the checkboxes on the "advanced" window
        public void UpdateOptions(int hWnd)
        {
            Win32Api.tagWINDOWINFO info = new Win32Api.tagWINDOWINFO();
            Win32Api.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 & Win32Api.WS_MINIMIZE) != 0)
            {
                WinStyle = 1;
            }
            else if ((info.dwStyle & Win32Api.WS_MAXIMIZE) != 0)
            {
                WinStyle = 2;
            }

            comboWinStyle.SelectedIndex = WinStyle;
            #endregion

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

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

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

            comboBorderStyle.SelectedIndex = BorderStyle;
            #endregion

            adv.PopulateCheckboxes(hWnd);
        }
Example #4
0
        //KILL. ME.
        public void PopulateCheckboxes(int hWnd)
        {
            Win32Api.tagWINDOWINFO info = new Win32Api.tagWINDOWINFO();
            Win32Api.GetWindowInfo(hWnd, out info);

            ClearChecks();

            if ((info.dwStyle & Win32Api.WS_BORDER) != 0)
            {
                winOptions.SetItemChecked(0, true);
            }
            if ((info.dwStyle & Win32Api.WS_CAPTION) != 0)
            {
                winOptions.SetItemChecked(1, true);
            }
            if ((info.dwStyle & Win32Api.WS_CHILD) != 0)
            {
                winOptions.SetItemChecked(2, true);
            }
            if ((info.dwStyle & Win32Api.WS_CLIPCHILDREN) != 0)
            {
                winOptions.SetItemChecked(3, true);
            }
            if ((info.dwStyle & Win32Api.WS_CLIPSIBLINGS) != 0)
            {
                winOptions.SetItemChecked(4, true);
            }
            if ((info.dwStyle & Win32Api.WS_DISABLED) != 0)
            {
                winOptions.SetItemChecked(5, true);
            }
            if ((info.dwStyle & Win32Api.WS_DLGFRAME) != 0)
            {
                winOptions.SetItemChecked(6, true);
            }
            if ((info.dwStyle & Win32Api.WS_GROUP) != 0)
            {
                winOptions.SetItemChecked(7, true);
            }
            if ((info.dwStyle & Win32Api.WS_HSCROLL) != 0)
            {
                winOptions.SetItemChecked(8, true);
            }
            if ((info.dwStyle & Win32Api.WS_MAXIMIZE) != 0)
            {
                winOptions.SetItemChecked(9, true);
            }
            if ((info.dwStyle & Win32Api.WS_MAXIMIZEBOX) != 0)
            {
                winOptions.SetItemChecked(10, true);
            }
            if ((info.dwStyle & Win32Api.WS_MINIMIZE) != 0)
            {
                winOptions.SetItemChecked(11, true);
            }
            if ((info.dwStyle & Win32Api.WS_MINIMIZEBOX) != 0)
            {
                winOptions.SetItemChecked(12, true);
            }
            if ((info.dwStyle & Win32Api.WS_OVERLAPPED) != 0)
            {
                winOptions.SetItemChecked(13, true);
            }
            if ((info.dwStyle & Win32Api.WS_POPUP) != 0)
            {
                winOptions.SetItemChecked(14, true);
            }
            if ((info.dwStyle & Win32Api.WS_SYSMENU) != 0)
            {
                winOptions.SetItemChecked(15, true);
            }
            if ((info.dwStyle & Win32Api.WS_TABSTOP) != 0)
            {
                winOptions.SetItemChecked(16, true);
            }
            if ((info.dwStyle & Win32Api.WS_THICKFRAME) != 0)
            {
                winOptions.SetItemChecked(17, true);
            }
            if ((info.dwStyle & Win32Api.WS_VISIBLE) != 0)
            {
                winOptions.SetItemChecked(18, true);
            }
            if ((info.dwStyle & Win32Api.WS_VSCROLL) != 0)
            {
                winOptions.SetItemChecked(19, true);
            }
        }
Example #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
            Win32Api.tagWINDOWINFO info = new Win32Api.tagWINDOWINFO();
            Win32Api.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 &= ~(Win32Api.WS_CAPTION | Win32Api.WS_BORDER); //Bit shit that shift
                break;

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

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

            default:
                break;
            }

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

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

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

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

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

            default:
                break;
            }
        }