Simplify bit flags checking code Please help make this code more cleaner. It's a part of window procedure that notifies my renderer before client area of window resized.

I need to check two combinations of bit blags: some of them must be set, and some must be not. How to do it without bunch of temp variables? (and probably calculate only 2 possible states and only once, not every call)

Thanks!

LRESULT CALLBACK MSWindow::Impl::WndProc( HWND hWnd, uint msg, WPARAM wParam, LPARAM lParam )
{
switch( msg )
{

// ...

// WM_WINDOWPOSCHANGING is sent just about window position, size or order changed.
case WM_WINDOWPOSCHANGING:
    {
        const WINDOWPOS* wp = ((WINDOWPOS*)lParam);
        const auto&amp; flags = wp-&gt;flags;

        const bool NOCOPYBITS       = (flags &amp; SWP_NOCOPYBITS)      &gt; 0;
        const bool NOSIZE           = (flags &amp; SWP_NOSIZE)          &gt; 0;
        const bool FRAMECHANGED     = (flags &amp; SWP_FRAMECHANGED)    &gt; 0;
        const bool NOOWNERZORDER    = (flags &amp; SWP_NOOWNERZORDER)   &gt; 0; 
        const bool NOZORDER         = (flags &amp; SWP_NOZORDER)        &gt; 0;
        const bool NOACTIVATE       = (flags &amp; SWP_NOACTIVATE)      &gt; 0;
        const bool SHOWWINDOW       = (flags &amp; SWP_SHOWWINDOW)      &gt; 0;

        const bool IsResizingAboutToEnd  = !(NOSIZE) &amp;&amp; NOOWNERZORDER &amp;&amp; NOZORDER &amp;&amp; (!NOACTIVATE);
        const bool IsGoingToMaximizeOrRestore = FRAMECHANGED &amp;&amp; (!NOACTIVATE) &amp;&amp; (!NOCOPYBITS) &amp;&amp; (!SHOWWINDOW);

        if ( IsGoingToMaximizeOrRestore || IsResizingAboutToEnd )
        {
            Resize(Point(wp-&gt;cx, wp-&gt;cy));
        }

        break;
    }
// .....
}
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)