CalcWindowRect

CalcWindowRect是一個計算機函式。

基本介紹

  • 中文名:函式原型
  • 外文名:CalcWindowRect
  • 屬性:計算機編程
  • 行業:IT
簡介,發展,

簡介

CWnd::CalcWindowRect (函式原型)
virtual void CalcWindowRect( LPRECT lpClientRect, UINT nAdjustType = ustBorder );
Parameters(參數)
lpClientRect
Points to a RECT structure or CRect object that contains the resultant value of the window rectangle.(指向RECT結構或CRect對象(包含window矩形的值)的指針
nAdjustType
An enumerated type used for in-place editing. It can have the following values:
一種枚舉類型,可以有如下的值:
CWnd::adjustBorder = 0, which means that scroll-bar sizes are ignored in calculation;
當adjustBorder=0時,表示在計算時忽略滾動條大小
and CWnd::adjustOutside = 1, which means that they are added into the final measurements of the rectangle.
當adjustOutside=1時,表示把滾動條大小考慮進去
Remarks(備註)
Call this member function to compute the required size of the window rectangle based on the desired client-rectangle size. The resulting window rectangle (contained in lpClientRect) can then be passed to the Create member function to create a window whose client area is the desired size.
調用這個成員函式以根據所需的客戶矩形大小計算視窗矩形的大小。隨後算出的視窗矩形(保存在lpClientRect)中可以被傳遞到Create成員函式以創建一個視窗,其客戶區大小就是要求的大小
Called by the framework to size windows prior to creation.
它被框架調用以確定產生視窗的大小
A client rectangle is the smallest rectangle that completely encloses a client area. A window rectangle is the smallest rectangle that completely encloses the window.、
客戶矩形是緊繞客戶區的最小矩形,視窗矩形是緊繞視窗的最小矩形
Example(舉例)
// Uses CalcWindowRect to determine size for new CFrameWnd
// based on the size of the current view. The end result is a
// top level frame window of the same size as CMyView's frame.
用該函式計算基於當前視圖尺寸的新框架視窗的大小,最後得到一個和CMyView框架尺寸相等的最上層框架視窗
void CMyView::OnMyCreateframe()
{
CFrameWnd* pFrameWnd = new CFrameWnd;
CRect myRect;
GetClientRect(myRect);

發展

pFrameWnd->Create(NULL, "My Frame");
pFrameWnd->CalcWindowRect(&myRect, CWnd::adjustBorder);
pFrameWnd->MoveWindow(0, 0, myRect.Width(), myRect.Height());
pFrameWnd->ShowWindow(SW_SHOW);
}
總的來說,該函式的功能就是使你能夠精確地限定客戶區矩形的大小。
比如你的客戶區是200*200的,因為調用Create函式(或者CreateEx)的時候指定的視窗大小是視窗矩形的大小(視窗矩形包含客戶區矩形和標題欄選單欄等),並且標題欄選單欄這些元素的尺寸隨著視頻驅動程式和顯示器圖形解析度的不同而不同,所以創建視窗時,無法準確限定客戶區矩形的大小。
使用過程:
CreateEx(0,
strClassName,
strTitleName,
WS_CAPTION | WS_MINIMIZEBOX | WS_OVERLAPPED | WS_SYSMENU,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT, // 指定要創建的視窗矩形的Width
CW_USEDEFAULT, // 指定要創建的視窗矩形的Height
NULL,
NULL)
但是我們用到的客戶區矩形可能只有200*200,(假設200<CW_USEDEFAULT- x , x 為非客戶區所占的寬或高),為了低碳節約,我們再對視窗進行調整.假設調整後的視窗矩形為210*210,(其中包含200*200的客戶區矩形,剩下的是選單,標題欄等等)
CRect rect (0, 0, 200, 200);
// 上面語句執行後 rect.width = 200, rect.height = 200.
CalcWindowRect (&rect);
// 上面語句執行後 rect.width = 210, rect.height = 210.
SetWindowPos(0, 0, 0,
rect.Width(),
rect.Heigth(),
SWP_NOZORDER | SWP_NOMOVE | SWP_NOREDRAW )
由此得到一個合適大小的視窗。
CalcWindowRect 需要在視窗創建之後進行調用,以能夠使視窗的非客戶區被考慮和生效。

相關詞條

熱門詞條

聯絡我們