首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C# 怎么获取系统活动窗口相对屏幕的位置以及大小

2013-01-11 
C# 如何获取系统活动窗口相对屏幕的位置以及大小本人正用 C# 开发屏幕录制程序,允许用户指定任意窗口区域

C# 如何获取系统活动窗口相对屏幕的位置以及大小
本人正用 C# 开发屏幕录制程序,允许用户指定任意窗口区域为录制范围,这就必须获得当前用户指定的窗口对象及其相对屏幕的位置和大小,固有此问。
[解决办法]
算了。估计你也看不明白如何实现,写个例子给你好了。


[System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "GetForegroundWindow")]
public static extern IntPtr GetForegroundWindow();
[System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "GetWindowRect")]
public static extern int GetWindowRect(IntPtr hwnd, ref System.Drawing.Rectangle lpRect);
private static void TestGetForegroundWindowRectangle()
{
    IntPtr hForeground = GetForegroundWindow();
    System.Drawing.Rectangle rect = new System.Drawing.Rectangle();
    GetWindowRect(hForeground, ref rect);
    //这里的rect就是你你要的
}

热点排行