如何得到一个窗口的图像时,我们只知道它的窗口句柄 [英] How to get the image of a window when we only know its window handle

查看:268
本文介绍了如何得到一个窗口的图像时,我们只知道它的窗口句柄的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在开发C#应用程序,并想知道如何得到任何窗口的截屏图像时,我们只知道它的窗口句柄。我想实现的功能是能够把刚才复制的任何窗口的截屏(也可以是整个应用程序或应用程序中的控制)时,我只知道它的窗口句柄。

I am developing an application in C# and want to know how to get the screen shot image of any window when we only know its window handle. The functionality I am trying to achieve is to be able to just copy the screen shot of any window (it can be a whole application or a control inside an application) when I only know its window handle.

例子:我正在运行计算器应用程序,和Spy ++。当我使用找到间谍++的窗口功能和悬停我的鼠标在计算器的不同的按钮,它表现出不同的窗口句柄。可以说,我悬停鼠标放在9按钮,在计算器。现在,当我知道它的窗口句柄,我想只有9键的形象。如果我有完整的应用程序的窗口句柄然后,我希望能得到只有该应用程序的屏幕截图。 。类似ALT + PrintScr

Example: I am running a calculator application, and Spy++. When I use find window functionality of the Spy++ and hover my mouse over different buttons of the calculator, it show different window handles. Lets say I hover mouse over "9" button in the calculator. Now as I know its window handle, I want to get image of the "9" button only. If I have window handle of the complete application then I want to be able to get the screen shot of that application only. Similar to Alt+PrintScr.

推荐答案

您需要使用的 GetWindowRect

就像在所示的这个例子

然后你可以使用的 Graphics.CopyFromScreen 如本SO发布的 C#采取特定区域的截图。

Then you can use Graphics.CopyFromScreen as shown in this SO post c# Take a screenshot of specific area.

全部放在一起,你叫GetWindowRect,它接受HWND得到你想要的窗口的正确。然后你使用这些矩形值与CopyFromScreen捕捉你的形象。

Putting it all together, you call GetWindowRect, which accepts an HWnd to get the rect of the window you want. Then you use those rect values with CopyFromScreen to capture your image.

这篇关于如何得到一个窗口的图像时,我们只知道它的窗口句柄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆