I need to list all open windows and get their name, but the problem is that some windows belong to the same process, but to another thread that is blocked (waiting for the mutex). Therefore, I cannot use GetWindowText for windows that belong to my own process, as this will result in a SendMessage call that will block the execution of my code (since it will wait for reinstallation for a blocked thread).
Btw here's an interesting article on how GetWindowText works internally: http://blogs.msdn.com/b/oldnewthing/archive/2003/08/21/54675.aspx
As a solution, I decided to use SendMessageTimeout in the window to get its title, but I cannot get it to work. I'm doing it:
[DllImport("User32.dll")]
public static extern int SendMessageTimeout(
IntPtr hWnd,
int uMsg,
int wParam,
int lParam,
int fuFlags,
int uTimeout,
out StringBuilder lpdwResult);
...
StringBuilder sb = new StringBuilder(256);
int result = Win32API.SendMessageTimeout(
hWnd,
0x0D ,
256,
0,
10 ,
500,
out sb);
0, , , sb null.
?
.