2013-04-28 51 views
0

我使用Graphics.CopyFromScreen()方法來捕獲一個控件的快照,其HWND我有。問題是我想避免捕捉閃爍的插入符號。有沒有辦法做到這一點?如果需要,我願意使用API​​調用(BitBlt?)。捕獲屏幕區域沒有脫字號

注意:我看到一個非常類似的問題here,但問題是我的控件不是WinForms控件,甚至沒有標準的EDIT類,所以我沒有像DrawToBitmap()那樣的奢侈品。當您按下單元格中的F2時,將出現Excel的編輯框。

回答

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

要獲得控制手柄(編輯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); 
} 
+0

非常感謝。 – dotNET 2013-04-28 13:32:40