C#调用WindowsAPI之GetClientRect用法

    函数功能:该函数获取窗口客户区的坐标。客户区坐标指定客户区的左上角和右下角。由于客户区坐标是相对子窗口客户区的左上角而言的,因此左上角坐标为(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

第一步,声明结构


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

 

第三步,设定一个RECT

RECT rect = new RECT();

 

第四步,应用

 

bool result = GetClientRect(this.Handle,out RECT rect);

 

注:GetClientRect 函数所取得的 LeftTop 值是 0RightBottom 值是 widthheight。也就是说,Right的就是宽度,Bottom的值就是高度了

 

posted @ 2012-07-17 15:35  ゞ追忆o0ゞ  阅读(6236)  评论(0编辑  收藏  举报