Thread: Reading a list of window buttons

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    11

    Reading a list of window buttons

    Hi,

    Is there a way to obtain a list of all the buttons on a window given that windows handle ?

    Thanks,
    Marc

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    EnumChildWindows will enumerate all the child windows of a specified window. You can then use GetClassName to get the window class for each of these windows. This can be compared against the string "BUTTON" to check if each window is a button.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    11
    Ok, I've tried using the following code but it's just not reporting any buttons for the window, even though I can see they exist. Unless they're implementing buttons in some way that makes them undetectable I dunno what's going on.

    What I'm doing is searching for the window belonging to a specific app and once I've found that (which it does) I use a recursive EnumChildWindows callback to scan all its child windows looking for buttons.

    Here's the relevant functions I'm using.

    Code:
    BOOL CALLBACK FindChildWindowProc ( HWND hwnd, LPARAM lParam )
    { 
    	int			style;
    	TCHAR		class_name[256];
    
    	GetClassName ( hwnd, class_name, 100 );
    
    	if ( strcmp ( class_name, "Button" ) == 0 ) { 
    		button_count++;
    	}
    	EnumChildWindows ( hwnd, FindChildWindowProc, (LPARAM) NULL );
    
    	return TRUE;
    } 
    
    BOOL CALLBACK FindWindowProc ( HWND hwnd, LPARAM lParam )
    { 
    	int			str_length;
    	TCHAR		window_name[256];
    		
    	str_length = GetWindowTextLength ( hwnd );
    
    	GetWindowText ( hwnd, (TCHAR *) window_name, str_length + 1 );
    
    	if ( strstr ( window_name, (TCHAR *) lParam ) != NULL ) {
    		EnumChildWindows ( hwnd, FindChildWindowProc, (LPARAM) NULL );
    	}
    
    	return TRUE;
    }
    I should mention that the buttons in question aren't displayed as standard windows buttons. I assumed they just had bitmaps set for them but using the Spy++ window finder, it doesn't highlight any of the buttons or check boxes when I run the cursor over them. Is there a way to make buttons undetectable or could they be implemented as just a bitmap with the app performing collision checking by looking for mouse clicks within given rectangles ?

    I'm stumped and grateful for any suggestions...

    Marc
    Last edited by marc74; 01-08-2005 at 04:35 PM.

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    finding a button on another application could violate privacy protection rules. but yes, buttons can be implemented in a number of user/system defined ways. the vendor is the best source for that type of information though.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  5. #5
    Registered User
    Join Date
    Jun 2004
    Posts
    84
    You shold not call EnumChildWindows in it's callback function, it is done automatically. Also use stricmp to find buttons as they are case insensetive(at least I thik so). Try this corrected code, might work.
    Code:
    BOOL CALLBACK FindChildWindowProc (HWND hwnd, LPARAM lParam )
    { 
        int   style;
        TCHAR class_name[256];
    
        GetClassName(hwnd, class_name, sizeof(class_name)/sizeof(class_name[0]));
    
        if (_tcsicmp(class_name, "button" ) == 0)
        {
            button_count++;
        }
    
        return TRUE;
    } 
    
    BOOL CALLBACK FindWindowProc (HWND hwnd, LPARAM lParam )
    { 
        TCHAR window_name[256];
    		
        GetWindowText(hwnd, window_name, sizeof(window_name)/sizeof(window_name[0]));
    
        if (_tcsstr(window_name, (TCHAR*)lParam) != NULL )
        {
            if (!EnumChildWindows(hwnd, FindChildWindowProc, 0))
                MessageBox(NULL, "EnumChildWindows() failed! ", "Error", MB_OK | MB_ICONERROR);
            return FALSE;
        }
    
        return TRUE;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help! Placement of nodes in a Linked List
    By lostmyshadow in forum C Programming
    Replies: 6
    Last Post: 12-17-2007, 01:21 PM
  2. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 08:23 AM
  3. Problem with linked list ADT and incomplete structure
    By prawntoast in forum C Programming
    Replies: 1
    Last Post: 04-30-2005, 01:29 AM
  4. instantiated from here: errors...
    By advocation in forum C++ Programming
    Replies: 5
    Last Post: 03-27-2005, 09:01 AM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM