Solved

Getting all buttons of a window and identifying a particular one

Posted on 2004-04-30
12
678 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C#: need to import an entire CSV file 4 51
Windows Process running 3 47
Poor Man's .NET Framework Certification 2 47
Need an intro to -- .Net SQL Authorization Manager 7 75
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…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

930 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

13 Experts available now in Live!

Get 1:1 Help Now