Get the position and dimension of a button in a window of another application

What I'm trying to do is when the user clicks a button of another application, for example Word 2007 , to get the position and dimension of that button, so later I can draw a rectangle in a screenshot.
Is this possible?

I tried to use EnumChildWindows but it doesn't return the buttons.
MMonkAsked:
Who is Participating?
 
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
It actually depends on the "button" in question...some controls are drawn by the parent container and don't actually have their own handle!

To determine this, use Spy++ or the free WinSpector Spy to see if the button you are trying to target is a "light" or "heavy" control...
0
 
pgnatyukCommented:
0
 
MMonkAuthor Commented:
I already have a mouse hook, and I'm able to get the handle when the window is clicked.
What I want to know is if it's possible to get information about a specific button within a window (Word 2007), since I'm not able to get the handle of the buttons with GetChildWindows (are buttons windows? do they have a HWND?).
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
js-profiCommented:
yes, buttons have a hwnd. if you already have a mouse hook and the hwnd of the application you probably would need a deep search, i. e. if you get a child hwnd you recursively have to search the grand childs as well.
0
 
pgnatyukCommented:
There is also ChildWindowFromPoint:
http://msdn.microsoft.com/en-us/library/ms632676(VS.85).aspx

You can try that also.

There is also RealChildWindowFromPoint,...

But you need to be sure that you use right coordinates (ScreenToClient).
0
 
pgnatyukCommented:
I do not understand the relation between the question and the comment selected as the accepted solution. It does answer on one of the questions raised in this thread so it can be an assisted solution - to use Spy is a perfect advice here. But ...
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
I'm guessing the "button" didn't have a handle so the API suggestions didn't apply to his situation...  =\
0
 
js-profiCommented:
you mean word 2007 would use self-drawn fake buttons?
0
 
MMonkAuthor Commented:
pgnatyuk all your suggestions I already knew and have tried, so weren't of great help.
What I wanted to know is if was possible to get the hwnd of buttons of any application, Word 2007 was just an example. Idle_Mind comment provided the answer, that not all buttons have hwnd, so I'm giving up this approach.

I'm new around here, I'm sory if I created any confusion.
0
 
js-profiCommented:
mmonk, there are applications which don't use button control (windows) but only use self-drawn rectangles or images for buttons. but for your purpose those buttons are out of interest as you can't determine their dimensions (with reasonable efforts). A dialog-based application with buttons always will use real buttons which have a hwnd. pgnatyuk tried to help you and his suggestions are valid.
0
 
pgnatyukCommented:
For sure - if it is a window, it has a handle. The standard button is a window. If you are talking about a desktop application, you can be sure for 95% that your buttons have handles. You can check it with Spy as Idle_Mind mentioned.
If we will go back to your original question:

What I'm trying to do is when the user clicks a button of another application, for example Word 2007 , to get the position and dimension of that button, so later I can draw a rectangle in a screenshot.
Is this possible?

You see the difference and the correct answer.

Anyway.. You are welcome. Thank you and Good evening. :)
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
"The standard button is a window."

True...but the new Ribbon Bar interface in Office 2007 (and above) is an entirely different beast.

It doesn't have any ~standard~ controls within it...  =\
RibbonBarChildControls.JPG
0
 
js-profiCommented:
the mfc toolbar buttons is a bitmap, i. e. you could not spot a button window. The ribbon may not be a standard control (who defines?) but it has hwnds. by evaluating window class the ribbon probably could be handled.
0
 
pgnatyukCommented:
Guys, :) why you took just one sentence from a paragraph?
I said "95%". Right?
Or you want to show what? Something new about toolbars? :)
 
Please read the original question again and you will agree with me. I do not want to take any points from you. I'm OK.
It was just my private opinion that the selected comment cannot be the accepted solution.
0
 
js-profiCommented:
better read comments thoroughly yourself.  didn't  tell a contrary position to your's before. but don't think that ribbon buttons can be caught with your answers. and neither mfc toolbar buttons which are no windows. and word 2007 was example of initial q. what helps 95% if the given sample doesn't work?
0
 
pgnatyukCommented:
OK. OK. Let's stop now. It's already not a technical discussion.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.