michael447887

How do I find a control (such as a text box) from a window running in a separate process based on an X,Y screen coordinate




Re: Windows Forms General Find a window control at a point on the screen

nobugz

Use the WindowFromPoint() API function. Visit www.pinvoke.net for the necessary P/Invoke declarations.





Re: Windows Forms General Find a window control at a point on the screen

michael

Thanks, that's what I was looking for. I looked at the pinvoke.net website, and I found the function "GetDlgItemText ̄ but I can't get it to work. Does anyone know what needs to be passed into the parameters I've searched on other sites for it also, but I still can't figure it out.






Re: Windows Forms General Find a window control at a point on the screen

nobugz

The string pointer must point to a buffer that's valid in the virtual memory space of the process that owns the window. You can't pass yours. Bypassing this issue is not easy, you need to VirtualAllocEx() a buffer, then ReadProcessMemory() the buffer content.





Re: Windows Forms General Find a window control at a point on the screen

michael

Can you give me more details on how to do that I am really confused.




Re: Windows Forms General Find a window control at a point on the screen

nobugz

A Google query for these API functions can be useful. This was the second hit.





Re: Windows Forms General Find a window control at a point on the screen

michael

Thank you for your help. I have figured it out for the most part, but here is my new problem: I am only able to get text out of text boxes running in the same process. I can, however, get text from labels or other controls in other processes. How can I get text out of text boxes in other processes

It also appears that I can only get information about the programs I have written in VB.NET using VS2003. Does anyone have any ideas why that would be






Re: Windows Forms General Find a window control at a point on the screen

nobugz

Use GetWindowText().





Re: Windows Forms General Find a window control at a point on the screen

michael

That let's me get only the values of text boxes if they were filled in to start with. If I fill in the data later, or if it changes, the changes wont show when i use GetWindowText(). I looked on pinvoke.net, and I couldn't find a refresh function or anything that looked helpful.




Re: Windows Forms General Find a window control at a point on the screen

nobugz

Not sure I follow. Using GetWindowText() *after* the textbox has updated its content returns the old string





Re: Windows Forms General Find a window control at a point on the screen

michael

right. If the text box is originally empty, and I type something into it, GetWindowText() will return an empty string. If the original value is 4, and I change it to 5, it will return 4.