函數功能:該函數獲取窗口客戶區的坐標。客戶區坐標指定客戶區的左上角和右下角。由於客戶區坐標是相對子窗口客戶區的左上角而言的,因此左上角坐標為(0,0)
函數原型:BOOL GetClientRect(HWND hWnd,LPRECT lpRect);
參數:
GetLastError 函數。
備注:Windows CE:命令條包含在客戶區中。
速查:Windows NT: 3.1以上版本:Windows:95以上版本: Windows CE:1.0以上版本:頭文件:winuser.h;庫文件:user32.lib
函數原型:BOOL GetClientRect(HWND hWnd,LPRECT lpRect);
參數:
GetLastError 函數。
備注:Windows CE:命令條包含在客戶區中。
速查:Windows NT: 3.1以上版本:Windows:95以上版本: Windows CE:1.0以上版本:頭文件:winuser.h;庫文件:user32.lib
第一步,聲明結構
public struct RECT
{
public uint Left;
public uint Top;
public uint Right;
public uint Bottom;
}
第二步,導入user32.dll
[DllImport(
"
user32
")]
public static extern bool GetClientRect(
IntPtr hwnd,
out RECT lpRect
);
public static extern bool GetClientRect(
IntPtr hwnd,
out RECT lpRect
);
第三步,設定一個RECT
RECT rect =
new RECT();
第四步,應用
bool result = GetClientRect(
this.Handle,
out RECT rect);
注:GetClientRect 函數所取得的 Left 及 Top 值是 0; Right 及 Bottom 值是 width 和 height。也就是說,Right的就是寬度,Bottom的值就是高度了