<p>Background: I have a little video playing app with a UI inspired by the venerable Sasami2k, just updated to use VMR9 (i.e. Direct3D9 with DirectShow) and be less unstable.  Currently, it's a C++ app using raw Win32, through necessity: none of the various toolkits are worth a damn.  WPF, in particular, was not possible, due to its airspace restrictions.</p>

<p>OK, so, now that D3DImage exists it might be viable to mix and match D3D/VMR9/DirectShow and WPF. Given past frustrations with Win32's inextensibility, this seems like a good thing.</p>

<p>But y'know, I'm falling at the first hurdle here.</p>

<p>With Win32 I have created (very easily) a borderless window that's resizable, resizes proportionately, snaps to the screen edges, and takes up the whole screen (including taskbar area) when maximized. It's a video app, so these are all pretty desirable properties.</p>

<p>OK, so, how to do the same with WPF?</p>

<p>In Win32, I use:
WM_GETMINMAXINFO to control the maximize behaviour
WM_NCHITTEST to control the resize borders
WM_MOVING to control the snap-to-screen-edges
WM_SIZING to control the resize aspect ratio</p>

<p>However, looking at WPF it seems that the various events arrive too late, unless I'm misunderstanding the documentation?</p>

<p>For example, I don't know when I'm mid-move, as LocationChanged says it fires only once the window has moved (which is too late).
Similarly, it appears that StateChanged only fires once the window has been restored/maximized (when I need the information prior to the maximize, to tell the system the correct maximize size).</p>

<p>And I seem to be completely overlooking where the system tells me about resizes. Likewise the hit testing.</p>

<p>So, uh, am I missing something here, or do I have no choice but to drop back to hooking the wndproc of this thing anyway?  Can I do what I want without hooking the WndProc?</p>

<p>If I have to use the WndProc I might as well stick with my existing codebase; I want to have simpler, cleaner UI code, and moving away from the WndProc is fundamental to this.</p>

<p>If I do have to hook the WndProc, I have to wonder--<em>why</em>?  Win32 has got the sizing/sized, moving/moved, poschanging/poschanged window messages, and they're all useful.  Why wouldn't WPF replicate the same set of events?  It seems like an unnecessary gap in functionality.</p>

<p>Plus, it means that WPF is tied to a specific USER32-dependent implementation.  This means that MS can't (in Windows 7 or 8, say) invert the display layer to make WPF "native" and emulate HWNDs and WndProcs for legacy apps--even though this is precisely what MS should be doing.</p>

[{'answer_id': 27819, 'author': 'elgrego', 'author_id': 403, 'author_profile': 'https://Stackoverflow.com/users/403', 'pm_score': 1, 'selected': False, 'text': '<p>In code you can set the WindowStyle property to "None" and WindowsState to "Maximized"</p>\n\n<p>Im not sure what the Xaml would look like.</p>\n'}, {'answer_id': 27854, 'author': 'Huppie', 'author_id': 1830, 'author_profile': 'https://Stackoverflow.com/users/1830', 'pm_score': 2, 'selected': True, 'text': '<blockquote>\n<p>And I seem to be completely overlooking where the system tells me about resizes. Likewise the hit testing.</p>\n</blockquote>\n<p>For the resizing you\'re indeed missing the <a href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.sizechanged.aspx" rel="nofollow noreferrer">SizeChanged</a> event.\nAFAIK there is sadly no OnSizeChanging, OnLocationChanging and OnStateChanging event on a <a href="http://msdn.microsoft.com/en-us/library/system.windows.window_events.aspx" rel="nofollow noreferrer">Window</a> in .NET</p>\n<hr>\n<blockquote>\n<p>I saw that one, but as far as I can tell it only fires after the size has changed, whereas I need the event to fire during the resize. Unless I\'m misreading the docs and it\nactually fires continuously?</p>\n</blockquote>\n<p>It does not fire continuously but you can probably use the <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.form.resizebegin.aspx" rel="nofollow noreferrer">ResizeBegin</a> and <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.form.resizeend.aspx" rel="nofollow noreferrer">ResizeEnd</a> events and be able to do that.</p>\n<hr>\n<blockquote>\n<p>Aren\'t they WinForms events?</p>\n</blockquote>\n<p>Hmm, you\'re right.</p>\n'}, {'answer_id': 33764, 'author': 'DrPizza', 'author_id': 2131, 'author_profile': 'https://Stackoverflow.com/users/2131', 'pm_score': 2, 'selected': False, 'text': "<p>OK, to answer my own question, I was missing Adorners (never came back in any of the searches I did, so it doesn't seem that they're as widely known as they perhaps should be).</p>\n\n<p>They seem rather more complex than the WndProc overrides, unfortunately, but I think it should be possible to manhandle them into doing what I want.</p>\n"}, {'answer_id': 357293, 'author': 'devios1', 'author_id': 238948, 'author_profile': 'https://Stackoverflow.com/users/238948', 'pm_score': 0, 'selected': False, 'text': "<p>Can you perhaps override the ArrangeOverride and/or MeasureOverride to make up for those missing resize events? Measure is the first pass, and occurs when a layout needs to adjust for a new size, so it's kind of like a size changing event.</p>\n"}]
['https://Stackoverflow.com/questions/27733', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2131/']