欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C# GetWindowRect簡介及使用說明

 更新時間:2012年12月20日 11:57:18   作者:  
GetWindowRect返回指定窗口的邊框矩形的尺寸。該尺寸以相對于屏幕坐標左上角的屏幕坐標給出,需要的朋友可以了解下
函數(shù)功能:該函數(shù)返回指定窗口的邊框矩形的尺寸。該尺寸以相對于屏幕坐標左上角的屏幕坐標給出。
函數(shù)原型:BOOL GetWindowRect(HWND hWnd,LPRECTlpRect);
參數(shù):
hWnd:窗口句柄。
lpRect:指向一個RECT結構的指針,該結構接收窗口的左上角和右下角的屏幕坐標。
返回值:如果函數(shù)成功,返回值為非零:如果函數(shù)失敗,返回值為零。若想獲得更多錯誤信息,請調用GetLastError函數(shù)。
C#中使用該函數(shù)首先導入命名空間:
復制代碼 代碼如下:

using System.Runtime.InteropServices;

然后寫API引用部分的代碼,放入 class 內部
復制代碼 代碼如下:

[DllImport("user32.dll")]
private static extern int GetWindowRect(IntPtr hwnd,out Rect lpRect);

這個函數(shù)有兩個個參數(shù),第一個參數(shù)是指定窗口句柄;第二個參數(shù)接收窗口的左上角和右下角的屏幕坐標,它是Rect結構。Rect結構定義如下:
復制代碼 代碼如下:

public struct Rect
{
public int Left;
public int Top;
public int Right;
public int Bottom;
}
演示代碼:
IntPtr hwnd = FindWindow("", "計算器");
Rect rect = new Rect();
GetWindowRect(hwnd, out lpRect);

相關文章

最新評論