Solved

Getting all buttons of a window and identifying a particular one

Posted on 2004-04-30
12
682 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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
 
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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

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…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

832 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