Based on Jeff Roy's answer, but shows how to get the length of the text, so it can be> 500. It also handles the case when the window is not found.
[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); [System.Runtime.InteropServices.DllImport("user32.dll")] private static extern int GetWindowTextLength(int hwnd); private static string GetOpenClipboardWindowText() { var hwnd = GetOpenClipboardWindow(); if (hwnd == IntPtr.Zero) { return "Unknown"; } var int32Handle = hwnd.ToInt32(); var len = GetWindowTextLength(int32Handle); var sb = new StringBuilder(len); GetWindowText(int32Handle, sb, len); return sb.ToString(); }
weston Sep 25 '12 at 10:25 2012-09-25 10:25
source share