Solved

Getting all buttons of a window and identifying a particular one

Posted on 2004-04-30
12
675 Views
Last Modified: 2013-12-03
Hi!

I want to simulate a button click for a particular application by sending a click message.
I already have its main window (via EnumWindows/GetWindowThreadProcessId/GetModuleBaseName) and its first level child windows.

How do I get all buttons in a window? What is the best method to identify a single button?
0
Comment
Question by:stefan73
  • 5
  • 2
  • 2
  • +2
12 Comments
 
LVL 13

Assisted Solution

by:SteH
SteH earned 60 total points
ID: 10959202
Would Spy++ be a solution for you. It will do what you want but not from within your program. Depending on how often you have to look for it, it might be the fastest option.
0
 
LVL 48

Expert Comment

by:Mikal613
ID: 10959289
from a vb form?
0
 
LVL 17

Expert Comment

by:mokule
ID: 10959352
You should use EnumChildWindows recursivele
Getting Text You can have Button caption.
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 125 total points
ID: 10959534
Try GetClassName function. For button it should give "Button".
0
 
LVL 12

Author Comment

by:stefan73
ID: 10959723
SteH,
> Would Spy++ be a solution for you
Maybe, depending on its capabilities.

Stefan
0
 
LVL 12

Author Comment

by:stefan73
ID: 10959726
Mikal613,
> from a vb form?
Nope, pure Win32 API and C.

Stefan
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 12

Author Comment

by:stefan73
ID: 10959965
SteH,
Spy++ is part of MSVC, right?
No, I only have Cygwin here.

Stefan
0
 
LVL 12

Author Comment

by:stefan73
ID: 10960069
mokule, AlexFM,

I tried this:

static BOOL CALLBACK ChildIterator (HWND childwin, LPARAM lParam)
{
    char titlebuf[MAX_PATH];
    int ind=(int)lParam;

    if(ind>3) return TRUE; /* Limit recursion */

    if(!GetClassName(childwin,titlebuf,sizeof(titlebuf)))
          return TRUE;
          
    /* Lazy indent */
    printf("%*s",ind*2,"");
    if(!strcmp(titlebuf,"Button")){
          printf("%s -> ",titlebuf);              
      if (!GetWindowText (childwin, titlebuf, sizeof (titlebuf))) {
            strcpy (titlebuf, "(no title)");
          }
    }
    puts(titlebuf);    


    EnumChildWindows (csm_window, ChildIterator, (LPARAM)ind+1);

    return TRUE;
}

...but apparently there is a cycle in the parent->child relationship (unlikely), or EnumChildWindows doesn't support recursion:

FNFIXEDBAR60
  FNFIXEDBAR60
    FNFIXEDBAR60
      FNFIXEDBAR60
      FNFIXEDBAR60
      FNHELP60
      MDIClient
      FNWND360
      PBTabControl32_60
      FNUDO360
      pbdw60
      Edit
 [...]
      Edit
      PBEDIT60
      Button -> Click window to refresh.
      Button -> Network Interface
      Button -> (no title)
      Button -> Services:
      Button -> Buffers:
      pbdw60
      Edit
      Edit
      pbdwst60
      Button -> Views:
      Button -> (no title)
      Button -> General:
    FNFIXEDBAR60
      FNFIXEDBAR60
      FNFIXEDBAR60
      FNHELP60
      MDIClient
      FNWND360
      PBTabControl32_60
      FNUDO360
      pbdw60
      Edit
 [...]
      Edit
      PBEDIT60
      Button -> Click window to refresh.
      Button -> Network Interface
      Button -> (no title)
      Button -> Services:
      Button -> Buffers:
      pbdw60
      Edit
      Edit
      pbdwst60
      Button -> Views:
      Button -> (no title)
      Button -> General:
    FNHELP60
0
 
LVL 17

Assisted Solution

by:mokule
mokule earned 65 total points
ID: 10960691

>    EnumChildWindows (csm_window, ChildIterator, (LPARAM)ind+1);
What is csm_window?
Shouldn't be childwin?

0
 
LVL 13

Expert Comment

by:SteH
ID: 10960734
Spy++ is MS software but there are similar tools:
http://www.windows-spy.com/
http://www.codeproject.com/tools/minispy.asp

HTH
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 10961651
According to MSDN, EnumChildWindows is recursive, you don't need to do recursion:

If a child window has created child windows of its own, EnumChildWindows enumerates those windows as well.

0
 
LVL 12

Author Comment

by:stefan73
ID: 10975310
mokule,
> Shouldn't be childwin?
Ooops, yes. But as AlexFM said, it's recursive by itself, anyway. I'll try that out.

Stefan
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now