I tried the solution given to the question referenced by Leif, and found that the SessionSwitchReason.SessionUnlock event seemed to be fired after the computer was locked, not before. This meant that the size and location of the window was already reset, so resizing failed.
So I had to find another way to store the current size and location before the computer was locked. The only thing I could see was to subscribe to ResizeEnd for ResizeEnd applications and update the pre-lock size and location.
I have not yet managed to get it to work for WPF applications, because WPF does not have the ResizeEnd equivalent (or I have not found it yet) and the subscription to SizeChanged and LocationChanged not good enough, because they start when the computer is locked, and also overwrites the size and location.
In the end, I had to hook into the Windows ExitSizeMove event to keep the current size and position. Details on how to connect to this event can be found here :
private const int WM_EXITSIZEMOVE = 0x232; private void Window_Loaded(object sender, RoutedEventArgs e) { HwndSource source = HwndSource.FromHwnd(new WindowInteropHelper(this).Handle); source.AddHook(new HwndSourceHook(WndProc)); } private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { if (msg == WM_EXITSIZEMOVE) {
source share