Simplify bit flags checking code
You first need to select the bits in the flag you want to test by ANDing them with a mask containing all the bits. 

This will zero all the bits that aren't being tested.

You then just need to check the value of the bits you want so the masks and values are:

const UINT EndMask = NOSIZE | NOOWNERZORDER | NOZORDER | NOACTIVATE;
const UINT MaxRestoreMask = FRAMECHANGED | NOACTIVATE | NOCOPYBITS | SHOWWINDOW;
const UINT EndValue = NOOWNERZORDER | NOZORDER;
const UINT MaxRestoreValue = FRAMECHANGED;


The test then becomes:

if ((flags &amp; EndMask) == EndValue || (flags &amp; MaxRestoreMask) == MaxRestoreValue)