我正在使用Graphics.CopyFromScreen()
方法捕获控件的快照,我的HWND。问题是我想避免捕获闪烁的插入符号。有没有办法实现这个目标?我愿意使用API调用(BitBlt
?),如果需要的话。
注意:我看到了一个非常相似的问题here,但问题是我的控件不是WinForms控件,甚至不是标准的EDIT类,所以我没有{{1}这样的奢侈品}}。当您在单元格中按F2时,将显示Excel的编辑框。
答案 0 :(得分:1)
看来,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
获取包含插入符号的控件(Edit,ComobBox等)的句柄 你可以使用功能 GetWindowThreadProcessId获取ThreadId GetGUIThreadInfo用于处理插入符号
http://msdn.microsoft.com/en-us/library/windows/desktop/ms633522(v=vs.85).aspx
[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);
}