user2365346
user2365346

Reputation: 515

How to shift the start coordinates of the client area on the window?

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

Upvotes: 5

Views: 1713

Answers (1)

Rabbid76
Rabbid76

Reputation: 211166

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;
}

Upvotes: 3

Related Questions