Catch Windows Messages from RadWindow : WPF

1 Answer 45 Views
General Discussions
Nick
Top achievements
Rank 1
Nick asked on 06 Nov 2021, 07:18 PM | edited on 06 Nov 2021, 07:20 PM

 

I have a requirement to override the Minimize function of the radWindow (clicking the Minimize Button on the Title Bar). Instead of the Window Minimizing to the bottom left of the screen I intend to simply reduce the Height of the Window leaving just the Title Bar showing (in its original position). Restoring the Window will again simply set the Height back to its original value to expand the Window….

So, I need to set Handle = true when the SC_MINIMIZE Message is received, this will prevent the Window from minimizing, then i can implement my own code to change the Height of the Window… This is the code so far…

        private void RadWindow_HostCreated(object sender, HostWindowCreatedEventArgs e)

        {

            e.HostWindow.SourceInitialized += HostWindow_SourceInitialized;

        }

 

        private void HostWindow_SourceInitialized(object sender, EventArgs e)

        {

            var source = PresentationSource.FromVisual((Window)sender) as HwndSource;

            if (source != null) source.AddHook(new HwndSourceHook(HandleMessages));

        }

 

        private IntPtr HandleMessages(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)

        {

            if (msg == 0x0112 && ((int)wParam & 0xFFF0) == 0xF020)

            {

                handled = true;

            }

 

            return IntPtr.Zero;

        }

 

However, while I seem to be catching Windows Messages in the HandleMessages function, it is not setting handled = true; when i click the Windows Minimize Button

Any help would be appreciated…

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 10 Nov 2021, 03:33 PM

Hello Nick,

This solution doesn't work because the minimize button of RadWindow is a custom one (RadButton) that executes its own command, instead of the native command used with the WPF Window control. This means that the default minimize messages are not trigger, thus the "msg" and "wParam" are not the expected ones.

The code in the HandleMessages() method will work with RadWindow only if you click its icon in the taskbar. Note that the RadWindow is not displayed in the taskbar by default. To enable this, you can set the RadWindowInteropHelper.ShowInTaskbar attached property to True. 

In order to achieve your requirement, you can extend the code by getting the minimize RadButton and handle its PreviewMouseLeftButtonDown event. You can find this approach in the attached project. I hope that helps.

Regards,
Martin Ivanov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Nick
Top achievements
Rank 1
commented on 12 Nov 2021, 09:43 AM

Hi Martin

                Thanks for that solution….

Thanks.

Tags
General Discussions
Asked by
Nick
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or