/// <summary>
        /// Removes all of the sunken 3D borders from the client MDI Children
        /// of an MDI Parent form.
        /// </summary>
        /// <param name="winForm">The form whose MDI Children are to have their sunken borders removed.</param>
        /// <param name="showBorders">Set to true if the sunken 3D borders are to be shown, else false.</param>
        public static void SetBevel(this Form winForm, bool showBorders)
        {
            // For each control within the form (MDI Children are also regarded as controls)
            foreach (Control control in winForm.Controls)
            {
                // If it succeeds, remove the bezel.
                if (control is MdiClient mdiCLientForm)
                {
                    // Get the window properties.
                    long windowLong = (long)WindowStyles.GetWindowLongPtr(control.Handle, Constants.GWL_EXSTYLE);

                    // Remove (or append) the border flags.
                    if (showBorders)
                    {
                        windowLong |= Constants.WS_EX_CLIENTEDGE;
                    }
                    else
                    {
                        windowLong &= ~Constants.WS_EX_CLIENTEDGE;
                    }

                    // Set the new extended window flags.
                    WindowStyles.SetWindowLongPtr(new HandleRef(control, control.Handle), Constants.GWL_EXSTYLE, (IntPtr)windowLong);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Applies compositing to a Windows Forms window by enabling the WS_EX_COMPOSITED
        /// extended window style.
        /// </summary>
        /// <param name="windowsForm">The Windows form whose compositing is to be applied.</param>
        public static void ApplyCompositing(Form windowsForm)
        {
            // Retrieves the extended window style.
            long extendedWindowStyle = (long)WindowStyles.GetWindowLongPtr(windowsForm.Handle, Constants.GWL_EXSTYLE);

            // Append WS_EX_COMPOSITED window style.
            extendedWindowStyle |= Constants.WS_EX_COMPOSITED;

            // Set window style.
            WindowStyles.SetWindowLongPtr(new HandleRef(windowsForm, windowsForm.Handle), Constants.GWL_EXSTYLE, (IntPtr)extendedWindowStyle);
        }
        /// <summary>
        /// Constructor for the overlay form, is executed upon creation of the overlay.
        /// </summary>
        public TransparentWinform(IntPtr gameWindowHandle)
        {
            // Initialize Windows Form
            InitializeComponent();

            // Set handle to game window.
            GameWindowHandle = gameWindowHandle;

            // Set owner window
            WindowStyles.SetWindowLongPtr(Handle, -8, gameWindowHandle);

            // Set up the glass window to overlay over target window.
            SetupWindow();
        }
Beispiel #4
0
        /// <summary>
        /// Overrides the WndProc function that handles messages sent to the ListView
        /// control in question. It removes the scrollbars from the listview when the listview
        /// in the case that the control may want to place them.
        /// We accomodate scrolling ourselves by using the arrow keys and scroll wheel.
        /// </summary>
        protected override void WndProc(ref Message message)
        {
            switch (message.Msg)
            {
            // WM_NCCALCSIZE | Message that calculates the size of the window.
            case 0x83:
                // Obtain Initial Style
                long windowStyle = (long)WindowStyles.GetWindowLongPtr(Handle, Constants.GWL_STYLE);

                // If the initial style for the Window contains the vertical scrollbar, remove it from the window style.
                if ((windowStyle & Constants.WS_HSCROLL) == Constants.WS_HSCROLL)
                {
                    windowStyle = windowStyle & ~Constants.WS_HSCROLL;
                }

                // Repeat for horizontal scrollbar if it is contained in the window style.
                if ((windowStyle & Constants.WS_VSCROLL) == Constants.WS_VSCROLL)
                {
                    windowStyle = windowStyle & ~Constants.WS_VSCROLL;
                }

                // Write the initial window style.
                WindowStyles.SetWindowLongPtr(new HandleRef(this, Handle), Constants.GWL_STYLE, (IntPtr)windowStyle);

                // Send the message to the base function, for potential painting purposes.
                base.WndProc(ref message);
                break;

            // Ignore WM_STYLECHANGED (No Permission to write, this is a Win32 wrapped control)
            case 0x7D:
                break;

            // Ignore WM_REFLECT | WM_NOTIFY
            case 0x204e:
                break;

            // No modification.
            default:
                base.WndProc(ref message);
                break;
            }
        }
        /// <summary>
        /// Sets the appropriate extended and non-extended window styles and attributes.
        /// The window is made topmost, transparent and layered and the layered window alpha
        /// is set to the maximum posible value.
        /// </summary>
        private void SetWindowStyles()
        {
            // Retrieve the original window style.
            long initialStyle = (long)WindowStyles.GetWindowLongPtr(Handle, Constants.GWL_EXSTYLE);

            // Set window as visible
            Visible = true;

            // Set the new window style
            WindowStyles.SetWindowLongPtr
            (
                Handle,                // Handle reference for the window.
                Constants.GWL_EXSTYLE, // nIndex which writes to the currently set window style.

                // Set window as layered window, transparent (removes hit testing when layered) and keep it topmost.
                (IntPtr)(initialStyle | Constants.WS_EX_LAYERED | Constants.WS_EX_TRANSPARENT)
            );

            // Set the Alpha on the Layered Window to 255 (solid)
            WindowStyles.SetLayeredWindowAttributes(Handle, 0, 255, Constants.LWA_ALPHA);

            // Set window as topmost.
            TopMost = false;
        }