[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2010-01-04
16
Medium Priority
?
288 Views
Last Modified: 2013-12-03
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.
0
Comment
Question by:MMonk
  • 6
  • 5
  • 3
  • +1
16 Comments
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 26170326
0
 

Author Comment

by:MMonk
ID: 26170399
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
 
LVL 7

Expert Comment

by:js-profi
ID: 26170480
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 33

Expert Comment

by:pgnatyuk
ID: 26170540
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
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1000 total points
ID: 26171662
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
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 26171811
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
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 26171830
I'm guessing the "button" didn't have a handle so the API suggestions didn't apply to his situation...  =\
0
 
LVL 7

Expert Comment

by:js-profi
ID: 26171861
you mean word 2007 would use self-drawn fake buttons?
0
 

Author Comment

by:MMonk
ID: 26172104
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
 
LVL 7

Expert Comment

by:js-profi
ID: 26172452
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
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 26172497
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
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 26172861
"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
 
LVL 7

Expert Comment

by:js-profi
ID: 26173151
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
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 26173360
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
 
LVL 7

Expert Comment

by:js-profi
ID: 26173699
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
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 26174345
OK. OK. Let's stop now. It's already not a technical discussion.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question