Hi,
Is there a way to obtain a list of all the buttons on a window given that windows handle ?
Thanks,
Marc
Hi,
Is there a way to obtain a list of all the buttons on a window given that windows handle ?
Thanks,
Marc
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.
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.
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 ?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'm stumped and grateful for any suggestions...
Marc
Last edited by marc74; 01-08-2005 at 04:35 PM.
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; }
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; }