// JP opened flex table

Click to See Complete Forum and Search --> : if on the button is text "cat" ........


abab
April 20th, 2007, 12:06 AM
How can I do that:

if ( on the button with ID=250 is text "cat" ) ........

Krishnaa
April 20th, 2007, 03:07 AM
What ?? Are you trying to find which button has the text/caption "cat" ?? Do you alredy have all the IDs of button and want to test if certain button has that perticular text ??

You can use use FindWindow (http://msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/findwindow.asp?frame=true) and/or FindWindowEx (http://msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/findwindowex.asp) API to get the HWND of button who has caption text you are looking for, then you can get the HWND of the button by it's ID using GetDlgItem (http://msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/windowing/dialogboxes/dialogboxreference/dialogboxfunctions/getdlgitem.asp?frame=true) API. Then test if those 2 are same.



DWORD dwButtonID = 250 ;

HWND hWnd_from_caption = FindWindow(NULL, "cat");

HWND hWnd_from_ID = GetDlgItem(hWnd_Host_Dialog_Box, dwButtonID );

if(hWnd_from_caption == hWnd_from_ID)
{
// you got it...go nuts..
}
else
{
// whatever..
}



BTW, posting such an one liner query and leaving others guessing what the heck you want is one of the bad forum manners.

abab
April 20th, 2007, 10:19 AM
it isn't good, mayby text "X" - for example - I have 36 buttons and when somebody click right mouse on some button he will see "X", and I want do that when are 6 "X" then something will happen - so I need know how many "X" are on the buttons - I don't know how can I do that ?

golanshahar
April 20th, 2007, 11:58 AM
it isn't good, mayby text "X" - for example - I have 36 buttons and when somebody click right mouse on some button he will see "X", and I want do that when are 6 "X" then something will happen - so I need know how many "X" are on the buttons - I don't know how can I do that ?

Loop throughout the 36 buttons and use ::GetWindowText() to get the caption if the caption is equal to "X" increase a counter when you reach to 6 do whatever you want.

Cheers

abab
April 20th, 2007, 12:27 PM
So what is wrong with this:


char buff[10]="";
................................



case WM_COMMAND:
{

if(GetWindowText(GetDlgItem(MainWindow, 201), buff, 1)=='X') MessageBox(MainWindow,"On button with ID=201 is X","Information",MB_OK);
}
break;


??

MrViggy
April 20th, 2007, 12:52 PM
Check out GetWindowText (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/getwindowtext.asp) The function returns the number of characters found, not a character.

Viggy

abab
April 20th, 2007, 01:28 PM
so how can I check is it "X" or not ?

Notsosuperhero
April 20th, 2007, 01:39 PM
when you loop through you can use strcmp (http://msdn2.microsoft.com/en-us/library/e0z9k731(VS.71).aspx)(strButtonText, "X").

If strcmp returns 0 then you have a match.


for (...loop through windows...)
{
// Get the text
if (strcmp(The text that holds what GetWindowText returned, "X") == 0)
{
// Do what you want
}
}

abab
April 20th, 2007, 01:52 PM
It doesn't work and I understand 30% what you write - - I AM NOT FROM ENGLAND - my english isn't good:



#include<string.h>

char buff[10]="";
................................



case WM_COMMAND:
{

if(strcmp( GetWindowText(GetDlgItem(MainWindow, 201), buff, 1 ), "X")==0) MessageBox(MainWindow,"On button with ID=201 is X","Information",MB_OK);
}
break;

MrViggy
April 20th, 2007, 04:16 PM
I'm not from England either.

if (GetWindowText(GetDlgItem(MainWindow, 201), buff, 1 ) > 0)
{
if (strcmp(buff, "X") == 0)
{
// This window is called "X"
}
}
Viggy

abab
April 21st, 2007, 02:09 AM
thanks but in GetWindowText(GetDlgItem(MainWindow, 201), buff, 1) should be not "1" but "2"- mayby that it is big "X" ?

//JP added flex table