Reputation: 1
If I'm pressing Win + D, the StateChanged event is not firing, but if the ResizeMode is CanResize,the StateChanged event is firing.
<Window x:Class="WpfApplication3.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" WindowStyle="None" ResizeMode="NoResize" WindowState="Maximized">
<Grid>
</Grid>
If I hook a messages loop and debug it, I am never in on Win + D with "NoResize"
IntPtr mainWindowPtr = new WindowInteropHelper(sender as Window).Handle;
HwndSource mainWindowSrc = HwndSource.FromHwnd(mainWindowPtr);
mainWindowSrc.AddHook(Hook);
But if I spy with Microsoft Spy++, there is a WM_WINDOWPOSCHANGED message on Win + D
What is wrong? And how can I catch this message/event?
Upvotes: 0
Views: 1875
Reputation: 315
Got the same case.
Window.ResizeMode
is NoResize
and i am trying to Show()
and then Hide()
Minimized
window programaticaly.
Even if i change the WindowState
property in code, event has not fired on Hide()
(but has fired on Show()
btw).
In my case i fired it by myself and it works for me.
public new void Hide()
{
Dispatcher.Invoke(() =>
{
base.Hide();
WindowState = WindowState.Minimized;
base.OnStateChanged(new EventArgs());
});
}
public new void Show()
{
Dispatcher.Invoke(() =>
{
base.Show();
base.Topmost = true;
WindowState = WindowState.Normal;
});
}
Upvotes: 0
Reputation: 69959
Your Application Window
is not being resized when you press Windows + D, so there is no reason for the StateChanged
event to be fired. You can verify this by running your Application and pressing ALT + Space to see the Window
state options. You will notice that the options to Maximise, Minimise and Restore are greyed out, which means that they cannot be selected.
That is because you have set the ResizeMode
property to NoResize
and would explain why you get different results when it is set to CanResize
. So, whatever the operating system does to hide Window
s when Windows + D is pressed does not involve resizing them.
Upvotes: 1