5

[Question]

1. How to detect the window (WPF) was resized by Aero Snap? then i can ignore the new size and position.

Thanks for your answer and comments in advance.

whunmr
  • 2,435
  • 2
  • 22
  • 35
  • It might help to know what you are trying to achieve here because I suspect the answer will be: you cannot tell. But there might be another way to solve your problem. – Richard Jan 04 '10 at 11:52
  • Do you want to know when the window is resized at all? Or specifically by Aero Snap? If specifically Aero Snap, why? As Richard says, there might be another way to help if we know the real problem. – Roger Lipscombe Jan 04 '10 at 11:55
  • Thank you for your suggestions, I need to save the position and size before Aero snaped. – whunmr Jan 04 '10 at 12:18
  • why before? what if i expect the window to re-open where i left it: snapped to one side? otherwise, you're opening it in some random place that i had it at some other time in the past, which i obviously didn't want, or i woudln't have snapped it to where it was when i closed it... – John Gardner Jan 04 '10 at 19:16
  • 1
    Hi John, thank you for your comments. I tried the "Microsoft Office Word" and "Notepad", these applications do not remember the "Aero Snap"ed position and size. so this why i want to get the size and position before "Aero snap"ed. – whunmr Jan 04 '10 at 19:34

1 Answers1

4

On exit, Call GetWindowPlacement. This will return the current window size and position, and whether you are minimized, maximized or restord, it will also give you the latest 'restored' window size and position.

So you don't have to track changes to your window position, just ask when you need it.

typedef struct _WINDOWPLACEMENT {
    UINT length;
    UINT flags;
    UINT showCmd;
    POINT ptMinPosition;
    POINT ptMaxPosition;
    RECT rcNormalPosition;
} WINDOWPLACEMENT;
John Knoeller
  • 33,512
  • 4
  • 61
  • 92
  • Why do you use an Win API call with P/Invoke? I think it is better to avoid these and look for a pure .NET class library solution. – Oliver Hanappi Jan 24 '10 at 11:49
  • 2
    @Oliver: Nothing wrong with P/Invoking. That functionality is provided by the .NET Framework for a reason: so that you can do things it doesn't already provide a managed implementation for. The short answer here is that there *isn't* a managed implementation that can do this, so P/Invoking is your only option. – Cody Gray - on strike Feb 05 '11 at 07:30