4
votes

I have refereed below article to draw a custom frame area with DWM. Custom Window Frame Using DWM After removing the standard frame, non client area is not exist in the frame.

void CMainFrame::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS* lpncsp)
{
    int nTHight = 30; /*The title bar height*/
    RECT * rc;
    RECT aRect;
    RECT bRect;
    RECT bcRect;
    if(bCalcValidRects == TRUE)
    {
        CopyRect(&aRect,&lpncsp->rgrc[1]); 
        CopyRect(&bRect,&lpncsp->rgrc[0]);
        bcRect.left = bRect.left;
        bcRect.top = bRect.top - nTHight;
        bcRect.right = bRect.right;
        bcRect.bottom = bRect.bottom;
        CopyRect(&lpncsp->rgrc[0],&bcRect);
        CopyRect(&lpncsp->rgrc[1],&bRect);
        CopyRect(&lpncsp->rgrc[2],&aRect);
    }
    else
    {
        rc = (RECT *)lpncsp;
        rc->left = rc->left;
        rc->top = rc->top - nTHight;
        rc->right = rc->right;
        rc->bottom = rc->bottom;
    }

    CFrameWnd::OnNcCalcSize(bCalcValidRects, lpncsp);
}

Because the entire window is client region, I have to adjust the UI control placement for the frame, but I don't know how to handle this problem. For example, below red rectangle (all UI component) should be shifted into the original coordinate of the client area before removing the non client part.

enter image description here

1
Check Appendix C of that page. If you're just letting DWM draw the standard caption into your client area, you can use AdjustWindowRectEx() to get what the original client rect would have been.andlabs

1 Answers

3
votes

CWnd::GetWindowRect gives you the rectangle of the window on screen. The dimensions of the caption, border, and scroll bars, if present, are included.

CWnd::GetClientRect gives you the client rectangel of the window. The left and top members will be 0. The right and bottom members will contain the width and height of the window.

CWnd::ScreenToClientand CWnd::ClientToScreen calculate a point or rectangle from the client area to screen coordinates and back to screen.

AdjustWindowRect calculates the required window rectangle, based on the client rectangle of the window.

Here is afunction which calcualtes the margins of a window:

void CalculateWndMargin( const CWnd &wnd, int &leftM, int &rightM , int &topM, int &bottomM )
{
    CRect wndRect;
    wnd.GetWindowRect( wndRect );
    CRect screenRect;
    wnd.GetClientRect( screenRect );
    wnd.ClientToScreen( screenRect );
    leftM = screenRect.left - wndRect.left;
    rightM = wndRect.right - screenRect.right;
    topM = screenRect.top - wndRect.top;
    bottomM = wndRect.bottom - screenRect.bottom;
}