use*_*346 5 c++ winapi mfc aero dwm
我参考了下面的文章,用 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);
}
Run Code Online (Sandbox Code Playgroud)
因为整个窗口都是客户端区域,所以我必须调整框架的 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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1645 次 |
| 最近记录: |