Check if currently minimized window was in maximized or normal state at the time of minimization
WinForms does not expose any WindowStateChanged
event then you have to track it by yourself. Windows will send a WM_SYSCOMMAND
when form state changes:
partial class MyForm : Form
{
public MyForm()
{
InitializeComponent();
_isMaximized = WindowState == FormWindowState.Maximized;
}
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_SYSCOMMAND)
{
int wparam = m.WParam.ToInt32() & 0xfff0;
if (wparam == SC_MAXIMIZE)
_isMaximized = true;
else if (wparam == SC_RESTORE)
_isMaximized = false;
}
base.WndProc(ref m);
}
private const int WM_SYSCOMMAND = 0x0112;
private const int SC_MAXIMIZE = 0xf030;
private const int SC_RESTORE = 0xf120;
private bool _isMaximized;
}
You can use GetWindowPlacement
(a native Win32 API function) on a minimized window, and read back the Flags member from the WindowPlacement struct. If bit 0x02 is set, then the window was maximized before it became minimized.