// WindowProc handles dispatching of messages and routing back to the base class or to Windows
LRESULT cef_dark_aero_window::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
    bool callDefWindowProc = true;

    switch (message) 
    {
    case WM_MEASUREITEM:
        if (HandleMeasureItem((LPMEASUREITEMSTRUCT)lParam))
            return 0L;
        break;
    case WM_DRAWITEM:
        if (HandleDrawItem((LPDRAWITEMSTRUCT)lParam))
            return 0L;
        break;
    case WM_SETICON:
        mWindowIcon = 0;
        {
            RECT rectIcon;
            ComputeWindowIconRect(rectIcon);
            InvalidateRect(&rectIcon);
        }
        break;
    }

    // First let the DesktopWindowManager handle the message and tell us if 
    //  we should pass the message to the default window proc
    LRESULT lr = DwpCustomFrameProc(message, wParam, lParam, &callDefWindowProc);

    switch(message) {
    case WM_SETTINGCHANGE:
        HandleSettingChange((UINT)wParam, (LPCWSTR)lParam);
        break;

    case WM_NCACTIVATE:
    case WM_ACTIVATE:
        if (mReady) {
            UpdateNonClientArea();
        }
        break;
    case WM_NCMOUSELEAVE:
        // NOTE: We want anyone else interested in this message
        //          to be notified. Otherwise the default implementation 
        //          may be in the wrong state
        HandleNcMouseLeave();
        break;
    case WM_NCMOUSEMOVE:
        {
            POINT pt;
            POINTSTOPOINT(pt, lParam);

            if (HandleNcMouseMove((UINT)wParam, &pt))
                return 0L;
        }
        break;
    case WM_NCLBUTTONDOWN:
        {
            POINT pt;
            POINTSTOPOINT(pt, lParam);
            if (HandleNcLeftButtonDown((UINT)wParam, &pt))
                return 0L;
        }
        break;
    case WM_NCLBUTTONUP:
        {
            POINT pt;
            POINTSTOPOINT(pt, lParam);
            if (HandleNcLeftButtonUp((UINT)wParam, &pt))
                return 0L;
        }
        break;
    }

    // call DefWindowProc?
    if (!callDefWindowProc) {
        return lr;
    }


    lr = cef_window::WindowProc(message, wParam, lParam);

    if (!mReady)
        return lr;

    switch (message)
    {
    case WM_GETMINMAXINFO:
        HandleGetMinMaxInfo((LPMINMAXINFO) lParam);
        break;
    case WM_SETTEXT:
    case WM_WINDOWPOSCHANGING:
    case WM_WINDOWPOSCHANGED:
    case WM_MOVE:
    case WM_SIZE:
    case WM_SIZING:
    case WM_EXITSIZEMOVE:
        UpdateNonClientArea();
        if (message == WM_WINDOWPOSCHANGED) 
        {
            RECT rect;
            ComputeMenuBarRect(rect);
            InvalidateRect(&rect, TRUE);
        }
        break;
    case WM_EXITMENULOOP:
        mMenuActiveIndex = -1;
        break;   
    case WM_ACTIVATEAPP:
        mIsActive = (BOOL)wParam;
        UpdateNonClientArea();
        break;
    }

    return lr;
}
// WindowProc handles dispatching of messages and routing back to the base class or to Windows
LRESULT cef_dark_window::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message) 
    {
    case WM_SETTINGCHANGE:
        // NOTE: We want anyone else interested in this message
        //          to be notified of a setting change even if we handle 
        //          the message.  Otherwise the default implementation 
        //          may be in the wrong state
        HandleSettingChange((UINT)wParam, (LPCWSTR)lParam);
        break;
    case WM_NCMOUSELEAVE:
        // NOTE: We want anyone else interested in this message
        //          to be notified. Otherwise the default implementation 
        //          may be in the wrong state
        HandleNcMouseLeave();
        break;
    case WM_NCMOUSEMOVE:
        if (HandleNcMouseMove((UINT)wParam))
            return 0L;
        break;

    case WM_NCLBUTTONDOWN:
        if (HandleNcLeftButtonDown((UINT)wParam))
            return 0L;
        break;
    case WM_NCLBUTTONUP:
        {
            POINT pt;
            POINTSTOPOINT(pt, lParam);
            if (HandleNcLeftButtonUp((UINT)wParam, &pt))
                return 0L;
        }
        break;
    case WM_NCCREATE:
        if (HandleNcCreate())
            return 0L;
        break;  
    case WM_NCPAINT:
        if (HandleNcPaint((HRGN)wParam)) 
            return 0L;
        break;
    case WM_NCDESTROY:
        if (HandleNcDestroy())
            return 0L;
        break;
    case WM_NCHITTEST:
        {
            POINT pt;
            POINTSTOPOINT(pt, lParam);
            return HandleNcHitTest(&pt);
        }            
        break;
    case WM_MEASUREITEM:
        if (HandleMeasureItem((LPMEASUREITEMSTRUCT)lParam))
            return TRUE;
        break;
    case WM_DRAWITEM:
        if (HandleDrawItem((LPDRAWITEMSTRUCT)lParam))
            return TRUE;
        break;
    case WM_SETICON:
        mWindowIcon = 0;
        break;
    case WM_SETTEXT:
    case WM_ACTIVATE:
    case WM_NCACTIVATE:
        // Turn off redraw because the 
        //  DefaultWindowProc will paint over top of 
        //  our frame and cause the title bar to flicker 
        if (!IsIconic()){
            SetRedraw(FALSE); 
        }
        break;
    }
    LRESULT lr = cef_window::WindowProc(message, wParam, lParam);
    // post default message processing
    switch (message)
    {
    case WM_WINDOWPOSCHANGING:
    case WM_WINDOWPOSCHANGED:
    case WM_MOVE:
    case WM_SIZE:
    case WM_SIZING:
    case WM_EXITSIZEMOVE:
        UpdateNonClientArea();
        break;
    }

    // special case -- since we turned off redraw for these 
    //  messages to reduce flicker, we need to turn redraw 
    //  on now and force updating the non-client area
    switch (message) 
    {
    case WM_SETTEXT:
    case WM_ACTIVATE:
    case WM_NCACTIVATE:
        if (!IsIconic()){
            SetRedraw(TRUE);
            UpdateNonClientArea();
            if (message != WM_SETTEXT) {
                DoRepaintClientArea();
            }
        }
        break;
    }
    return lr;
}