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的值就是高度了

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM