问题描述
我有这行代码在我的主要方法:
I have this line of code in my main method:
IntPtr hhook = SetWinEventHook(EVENT_SYSTEM_FOREGROUND, EVENT_SYSTEM_FOREGROUND, IntPtr.Zero, procDelegate, 0, 0, WINEVENT_OUTOFCONTEXT);
然后,我有这个在我的课:
Then I have this in my class:
delegate void WinEventDelegate(IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime);
static void WinEventProc(IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime)
{
// filter out non-HWND namechanges... (eg. items within a listbox)
if (idObject != 0 || idChild != 0)
{
return;
}
SaveImage(Capture(hwnd), hwnd);
Console.WriteLine("Handle: {0:x8}", hwnd.ToInt32());
}
我有一个小问题,此代码,它是很难表达这样包涵。这段代码背后的基本想法是,我想在前台当前应用程序的截图并将其保存到C盘上的位置。到目前为止,我的代码可以让我做到这一点,但它并不总是精确地工作,我怎么想它。问题是,有时,当我点击一个应用程序(因此带来到前台),它会拍摄照片的窗口有时间完全最大化了。这导致我的截图文件夹填充与那些应用程序背后的桌面截图。
I have a small problem with this code and it is very hard to articulate so bear with me. The basic idea behind this code is that I want to take a screenshot of the current application in the foreground and save it to a location on the C drive. So far my code allows me to do this, however it doesn't always work exactly how I want it to. The problem is that sometimes when I click an application (therefore bringing it to the foreground) it will take the picture before the window has had time to completely maximize. This leads to my screenshots folder being filled with screenshots that are of the desktop behind the application.
有没有办法等到窗口,我打电话之前完全最大化我的截图功能?
Is there a way to wait until the window is completely maximized before I call my screenshot function?
推荐答案
您可以使用和SetWindowsHookEx
与 WH_CALLWNDPROCRET
来知道什么时候 WM_PAINT
已通过窗口处理。或者,您可以通过延迟一点把你的截图,从实用的角度来看可能是你真正需要之前攻击它。
You can use SetWindowsHookEx
with WH_CALLWNDPROCRET
to know when WM_PAINT
has been processed by the window. Or you can hack it by delaying a bit before taking your screenshot, which from a practical standpoint might be all you really need.
这篇关于我的代码需要一个程序的截图,当它成为前台窗口。跑进一个小问题用截图的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!