SendMessage ~ Window Hooks - How?

  • Thread starter Thread starter Tx
  • Start date Start date
T

Tx

I have what seems like a common problem but I cannot find how to solve
it. I have to retrieve the contents from another apps list box (from
a c# app). The external app is linked to a messaging system (like a
chat client) and continues to add messages at undetermined intervals.
If possible, I would like to "hook" into the listbox and then record
every line in my C# app (and do some processing for each line).

How would I go about this? I found some posts on using the user32.dll
and SendMessage but I wasn't too clear on how. Also, how would I
register with the control to receive the update evetns (hook?). Any
help greatly appreciated.

Thanks

P.S. I can use Spy++ to determine the window handle et al.
 
Here's as far as I got - with no luck. Please help!


[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hwnd,
[MarshalAs(UnmanagedType.U4)] int Msg, int wParam,
[MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPStr)] string
lParam);



[DllImport("user32.dll")]
public static extern IntPtr WindowFromPoint(int xPoint, int yPoint);

---------------------
private void button1_Click(object sender, System.EventArgs e)
{
hwn_Target = WindowFromPoint(MousePosition.X, MousePosition.Y);
string returnBuffer = string.Empty;
txtMssg.Clear();
txtMssg.Text = "Window " + hwn_Target;
SendMessage(hwn_Target, 180 ,0, returnBuffer);

txtMssg.Text += " - Message: " + returnBuffer;

}

I'm trying to call Send Message with LB_ADDSTRING, I don't even know
if I have the number correct. The hwn seems to be good (I have a
button I press when the mouse is over the window I want) but I cannot
seem to get any return text. What am I doing wrong. Thanks
 
Back
Top