简体   繁体   English

C#-在指针下捕获窗口的屏幕截图

[英]C# - Capture screenshot of window under pointer

I am making a screen capturing application. 我正在制作一个屏幕捕获应用程序。

There's answer on how to capture an active window, but I want to be able to capture a window under mouse even if it's not active. 有关于如何捕获活动窗口的答案,但是我希望能够在鼠标下捕获一个窗口,即使该窗口不处于活动状态也是如此。

Do I understand correctly that I need to find handle of a window under mouse and then call Image.captureWindow(IntPtr handle) ? 我是否正确理解我需要在鼠标下找到窗口的句柄,然后调用Image.captureWindow(IntPtr handle)

Use following function to get the cursor position in context of screen 使用以下功能获取屏幕上下文中的光标位置

    POINT p;
if (GetCursorPos(&p))
{
    //cursor position now in p.x and p.y
}

Now you will have to use the EnumWindow function to enumerate all top level windows and then for each try this 现在,您将必须使用EnumWindow函数枚举所有顶级窗口,然后对于每个尝试此操作

    if (ScreenToClient(hwnd, &p))
{
    //p.x and p.y are now relative to hwnd's client area
}

when you get both the values positive for a window, thats the window on which your cursor is. 当您同时获得一个窗口的两个正值时,那就是光标所在的窗口。 Here is an example of how to capture a window from its handle 这是一个如何从其句柄捕获窗口的示例

http://www.codeproject.com/Articles/19192/How-to-capture-a-Window-as-an-Image-and-save-it http://www.codeproject.com/Articles/19192/How-to-capture-a-Window-as-an-Image-and-save-it

Hope this helps you 希望这对您有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM