Determine which process is locking the clipboard

前端 未结 4 558
一生所求
一生所求 2020-12-29 04:58

I have a peculiar error where some process occasionally appears to be using the clipboard when my application goes to handle copy & paste operations. There are some ret

4条回答
  •  遥遥无期
    2020-12-29 05:52

    Here's a similar solution, but this gives you a string you can show the user:

    [System.Runtime.InteropServices.DllImport("user32.dll")]
    static extern IntPtr GetOpenClipboardWindow();
    
    [System.Runtime.InteropServices.DllImport("user32.dll")]
    static extern int GetWindowText(int hwnd, StringBuilder text, int count);
    
    private string getOpenClipboardWindowText()
    {
        IntPtr hwnd = GetOpenClipboardWindow();
        StringBuilder sb = new StringBuilder(501);
        GetWindowText(hwnd.ToInt32(), sb, 500);
        return sb.ToString();
    }
    

提交回复
热议问题