Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 691
  • Last Modified:

Getting all buttons of a window and identifying a particular one

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
stefan73
Asked:
stefan73
  • 5
  • 2
  • 2
  • +2
3 Solutions
 
SteHCommented:
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
 
Mikal613Commented:
from a vb form?
0
 
mokuleCommented:
You should use EnumChildWindows recursivele
Getting Text You can have Button caption.
0
Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

 
AlexFMCommented:
Try GetClassName function. For button it should give "Button".
0
 
stefan73Author Commented:
SteH,
> Would Spy++ be a solution for you
Maybe, depending on its capabilities.

Stefan
0
 
stefan73Author Commented:
Mikal613,
> from a vb form?
Nope, pure Win32 API and C.

Stefan
0
 
stefan73Author Commented:
SteH,
Spy++ is part of MSVC, right?
No, I only have Cygwin here.

Stefan
0
 
stefan73Author Commented:
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
 
mokuleCommented:

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

0
 
SteHCommented:
Spy++ is MS software but there are similar tools:
http://www.windows-spy.com/
http://www.codeproject.com/tools/minispy.asp

HTH
0
 
AlexFMCommented:
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
 
stefan73Author Commented:
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

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 5
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now