我参考了下面的文章以使用DWM绘制自定义框架区域。使用DWM的自定义窗口框架删除标准框架之后,该框架中不存在非客户区域。
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);
}
因为整个窗口是客户区域,所以我必须调整框架的UI控件位置,但是我不知道如何处理此问题。例如,在删除非客户部分之前,应将红色矩形下方的所有UI组件移至客户区域的原始坐标。
CWnd::GetWindowRect
给您屏幕上窗口的矩形。包括字幕,边框和滚动条的尺寸(如果有)。
CWnd::GetClientRect
给您窗口的客户矩形。左侧和顶部成员将为0。右侧和底部成员将包含窗口的宽度和高度。
CWnd::ScreenToClient
并CWnd::ClientToScreen
从客户区域计算屏幕坐标和返回屏幕的点或矩形。
AdjustWindowRect
根据窗口的客户端矩形计算所需的窗口矩形。
这是计算窗口边距的函数:
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;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句