Find control of specific class in another application
c#, user32, winapi
Solution
Thanks for the answer above. It's very detailed. I ended up using a more simple approach:
private IntPtr FindHandle()
{
while (true)
{
IntPtr handle = FindWindowEx(this.ApplicationHandle,IntPtr.Zero,"TRichEdit", null);
if (handle == null)
{
throw new Exception("No handle found");
}
if (handle != this.Handle_01)
{
return handle;
}
}
}
Problem
I am scrapping content from another Windows application. The application has a Listbox and two TRichEdit controls (and other controls without interest). When using SendKeys.SendWait("{DOWN}") to the Listbox, the content in the two TRichEdit boxes changes. Thats where I want to scrap the content. That works. RichEdit1 : No problem - I get the content using SendMessageW() RichEdit2: Big problem. It changes Windows Handle each time I use SendKeys.SendWait on the LIstBox, so I can't access it. The solution is to find the new Windows Handle for RichEdit2. I think that I can get a list of Handles for RichEdit control and select the one with Handle different from RichEdit1. Question: How can I get a list of Handles of a specific class (RichEdit) from a different windows forms application? Or Does anyone has a better solution? A code snippet in C# will be appreciated. Thanks in advance.