我使用Graphics.CopyFromScreen()
方法来捕获一个控件的快照,其HWND我有。问题是我想避免捕捉闪烁的插入符号。有没有办法做到这一点?如果需要,我愿意使用API调用(BitBlt
?)。捕获屏幕区域没有脱字号
注意:我看到一个非常类似的问题here,但问题是我的控件不是WinForms控件,甚至没有标准的EDIT类,所以我没有像DrawToBitmap()
那样的奢侈品。当您按下单元格中的F2时,将出现Excel的编辑框。
我使用Graphics.CopyFromScreen()
方法来捕获一个控件的快照,其HWND我有。问题是我想避免捕捉闪烁的插入符号。有没有办法做到这一点?如果需要,我愿意使用API调用(BitBlt
?)。捕获屏幕区域没有脱字号
注意:我看到一个非常类似的问题here,但问题是我的控件不是WinForms控件,甚至没有标准的EDIT类,所以我没有像DrawToBitmap()
那样的奢侈品。当您按下单元格中的F2时,将出现Excel的编辑框。
看来,这HideCaret和ShowCaret功能将帮助
http://msdn.microsoft.com/en-us/library/windows/desktop/ms648406(v=vs.85).aspx http://msdn.microsoft.com/en-us/library/windows/desktop/ms648403(v=vs.85).aspx
要获得控制手柄(编辑ComobBox等),它保存插入符 你可以使用函数 GetWindowThreadProcessId获得的ThreadId GetGUIThreadInfo获得插入符持有者
http://msdn.microsoft.com/en-us/library/windows/desktop/ms633522(v=vs.85).aspx
的手柄210[DllImport("User32",
CallingConvention = CallingConvention.Winapi,
ExactSpelling = true,
EntryPoint = "HideCaret",
SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern Boolean HideCaret(IntPtr hWnd);
[DllImport("User32",
CallingConvention = CallingConvention.Winapi,
ExactSpelling = true,
EntryPoint = "ShowCaret",
SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern Boolean ShowCaret(IntPtr hWnd);
// If the window you have to copy is in your process then
// handle = IntPtr.Zero
// Otherwise your have to find it out via GetWindowThreadProcessId and GetGUIThreadInfo
HideCaret(handle);
try {
// Your code to capture the image
}
finally {
ShowCaret(handle);
}
非常感谢。 – dotNET 2013-04-28 13:32:40