【问题标题】:capturing screen area without caret捕获没有插入符号的屏幕区域
【发布时间】:2013-04-28 19:28:02
【问题描述】:

我正在使用Graphics.CopyFromScreen() 方法来捕获控件的快照,我拥有它的 HWND。问题是我想避免捕获闪烁的插入符号。有没有办法做到这一点?如果需要的话,我愿意使用 API 调用 (BitBlt?)。

注意:我看到了一个非常相似的问题here,但问题是我的控件不是WinForms控件,甚至不是标准的EDIT类,所以我没有DrawToBitmap()这样的奢侈品。它是在单元格中按 F2 时出现的 Excel 的编辑框。

【问题讨论】:

    标签: c# .net winapi textbox


    【解决方案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);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-22
      • 2021-06-25
      • 2021-03-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多