1

I want to fetch the handle of a button whose name changes. Now I am able to fetch the handle of a button using the code given below

buttonHandle = FindWindowEx(wnd.hWnd, IntPtr.Zero, "Button", "Find Car");

But in my application the button name changes like

Find Car Changes to Find Bus

but the first word Find is static. Is there any way to dynamically get the handle of buttons when its name changes?

Thanks, Nikil

1 Answer 1

1

Change the "Find Car" to use the text property of the button

buttonHandle = FindWindowEx(wnd.hWnd, IntPtr.Zero, "Button", btnFindButton.Text);
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks but could you please elaborate. I tried using it but throwing error. Do I need to import some dlls?
Hi, You dont need to add any references if you already have the Import Statement to Use FindWindowEx. I was assuming the button you wanted to get the handle for was on a form you had developed. What is it you are trying to achieve in the long run?
Actually I am trying to get the handle of a button on a third party application!
Ah I see! In that case have you checked whether the button handle changes when the text does? I don't think it will. If the text of the button is always the same when the screen is opened you could then store the handle in your app for future use. If you installed spy++ with visual studio you can view control handles etc when the 3rd party app is running

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.