Hide Close Button on FloatingWindow

Dec 1, 2009 at 1:31 PM

When you set IsCloseable to false in a DockablePane the close button is disabled in a floatingwindow, but still visible.

In other windowtypes the close button is hidden. I prefer that this button is hidden in a floating window as well. This will do the trick in FloatingWindow.cs:

        [DllImport("user32.dll")]
        static extern int GetWindowLong(IntPtr hWnd, int nIndex);

        [DllImport("user32.dll")]
        static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

        const int GWL_STYLE = -16;
        const int WS_SYSMENU = 0x00080000;

        protected override void OnSourceInitialized(EventArgs e)
        {
            base.OnSourceInitialized(e);
            if (HostedPane.Items.Count > 0)
            {
                ManagedContent cntHosted = HostedPane.Items[0] as ManagedContent;
                if (!cntHosted.IsCloseable)
                {
                    IntPtr handle = (new WindowInteropHelper(this)).Handle;
                    var style = GetWindowLong(handle, GWL_STYLE);
                    style &= (~WS_SYSMENU);
                    SetWindowLong(handle, GWL_STYLE, style);
                }
            }
        }

Is it possible to add this code to the base class?

Frank

Dec 14, 2009 at 2:08 AM

Seconded

Steve

Sep 30, 2010 at 3:21 PM

@Frank. Where do you place this code in? Do you have an example?

Sep 30, 2010 at 8:31 PM

I don't use it anymore. Just copy all code into FloatingWindow.cs and rebuild the library. That should do the job.