C# 无插入符号捕获屏幕区域
我正在使用C# 无插入符号捕获屏幕区域,c#,.net,winapi,textbox,C#,.net,Winapi,Textbox,我正在使用Graphics.CopyFromScreen()方法捕获一个控件的快照,我已经有了它的HWND。问题是我想避免捕捉闪烁的插入符号。有没有办法做到这一点?如果需要的话,我愿意使用API调用(BitBlt?) 注意:我看到了一个非常类似的问题,但问题是我的控件不是WinForms控件,甚至不是标准的编辑类,所以我没有像DrawToBitmap()这样的奢侈品。在单元格中按F2键时,将显示Excel的编辑框 看来,HideCaret和ShowCaret功能会有所帮助 获取包含插入符号的
Graphics.CopyFromScreen()
方法捕获一个控件的快照,我已经有了它的HWND。问题是我想避免捕捉闪烁的插入符号。有没有办法做到这一点?如果需要的话,我愿意使用API调用(BitBlt
?)
注意:我看到了一个非常类似的问题,但问题是我的控件不是WinForms控件,甚至不是标准的编辑类,所以我没有像
DrawToBitmap()
这样的奢侈品。在单元格中按F2键时,将显示Excel的编辑框 看来,HideCaret和ShowCaret功能会有所帮助
获取包含插入符号的控件(编辑、ComobBox等)的句柄
您可以使用函数
GetWindowThreadProcessId以获取ThreadId
获取插入符号保持器句柄的GetGuitThreadInfo
[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);
}