Donald Ramsey

Donald Ramsey

  • NA
  • 7
  • 4.3k

Unable to get window text

Jul 19 2010 4:51 PM
I'm not real sure why this doesn't work because I'm getting the correct window. Here is the code. Maybe someone can point out something that I'm missing. Any ideas?

 private void bStatus_Click(object sender, EventArgs e)
{
//Find the console edit box aswell as send the status command - works fine.
string message = "status";
StringBuilder sb = new StringBuilder(message);
IntPtr MW4CONSOLE = FindWindow("IW4 WinConsole", null);
IntPtr MW4EDIT = FindWindowEx(MW4CONSOLE, IntPtr.Zero, "Edit", IntPtr.Zero);
SendMessage(MW4EDIT, WM_SETTEXT, IntPtr.Zero, sb);
PostMessage(MW4EDIT, WM_KEYDOWN, VK_RETURN, IntPtr.Zero);
PostMessage(MW4EDIT, WM_KEYUP, VK_RETURN, IntPtr.Zero);

//Get the console text - works and finds the correct window - cross checked with api spy
IntPtr MW4TEXT = FindWindowEx(MW4CONSOLE, MW4EDIT, "Edit", IntPtr.Zero);

//does not work
int length = GetWindowTextLength(MW4TEXT);
StringBuilder sbtext = new StringBuilder(length + 1);

GetWindowText(MW4TEXT, sbtext, sbtext.Capacity);
lbUserNames.Items.Add(sbtext.ToString());

}

Edit: Here is a screen shot of the windows showing what is going on.

http://i29.tinypic.com/1z72dxi.jpg


Answers (14)