Solved

Getting all buttons of a window and identifying a particular one

Posted on 2004-04-30
12
687 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

690 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