Note that there are some explanatory texts on larger screens.

plurals
  1. POGet tooltips text from C# with PInvoke
    primarykey
    data
    text
    <p>I'm using PInvoke in C#, trying to read tooltips visible in a window with a known handler, but the apps who's windows I try to inspect in this manner crash with memory access violation errors, or simply don't reveal the tooltip text in the lpszText TOOLINFO member.</p> <p>I'm calling <a href="http://pinvoke.net/default.aspx/user32/EnumWindows.html" rel="nofollow">EnumWindows</a> with a callback and then sending a message to the tooltip window in that function:</p> <pre><code>public delegate bool CallBackPtr(IntPtr hwnd, IntPtr lParam); static void Main(string[] args) { callBackPtr = new CallBackPtr(Report); IntPtr hWnd = WindowFromPoint(&lt;mouse coordinates point&gt;); if (hWnd != IntPtr.Zero) { Console.Out.WriteLine("Window with handle " + hWnd + " and class name " + getWindowClassName(hWnd)); EnumWindows(callBackPtr, hWnd); Console.Out.WriteLine(); } public static bool Report(IntPtr hWnd, IntPtr lParam) { String windowClassName = getWindowClassName(hWnd); if (windowClassName.Contains("tool") &amp;&amp; GetParent(hWnd) == lParam) { string szToolText = new string(' ', 250); TOOLINFO ti = new TOOLINFO(); ti.cbSize = Marshal.SizeOf(typeof(TOOLINFO)); ti.hwnd = GetParent(hWnd); ti.uId = hWnd; ti.lpszText = szToolText; SendMessage(hWnd, TTM_GETTEXT, (IntPtr)250, ref ti); Console.WriteLine("Child window handle is " + hWnd + " and class name " + getWindowClassName(hWnd) + " and value " + ti.lpszText); } return true; } </code></pre> <p>Here's how I defined the TOOLINFO structure:</p> <pre><code>[StructLayout(LayoutKind.Sequential)] public struct RECT { private int _Left; private int _Top; private int _Right; private int _Bottom; } struct TOOLINFO { public int cbSize; public int uFlags; public IntPtr hwnd; public IntPtr uId; public RECT rect; public IntPtr hinst; [MarshalAs(UnmanagedType.LPTStr)] public string lpszText; public IntPtr lParam; } </code></pre> <p>the TTM_GETTEXT value</p> <pre><code>private static UInt32 WM_USER = 0x0400; private static UInt32 TTM_GETTEXT = (WM_USER + 56); </code></pre> <p>and the <a href="http://pinvoke.net/default.aspx/user32/SendMessage.html" rel="nofollow">SendMessage</a> overload</p> <pre><code>[DllImport("user32.dll", CharSet = CharSet.Auto)] static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, ref TOOLINFO lParam); </code></pre> <p>So, is there any obvious error that I'm missing in my code, what should I change so that this situation is resolved?</p> <p>Edit: <a href="http://codeupload.com/4297" rel="nofollow">Here</a> is the whole code, so you could test.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload