Click to See Complete Forum and Search --> : how do i get the number of the characters in a edit box?


SunCore
June 14th, 2005, 05:24 AM
thanks in advance.

Vaderman
June 14th, 2005, 06:01 AM
The following code does what you require.


CString strText;
m_yourEditBox.GetWindowText(strText)
int nLength = strText.GetLength()


Hope that helps

Regards

John
edit: Don't you think this question is appropriate for the Visual C++ Forum?

SunCore
June 14th, 2005, 06:31 AM
i was talking about API, not MFC.

Boris K K
June 14th, 2005, 06:42 AM
Send WM_GETTEXTLENGTH (http://msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowmessages/wm_gettextlength.asp) message to the edit box.

+J_o_S_H
June 14th, 2005, 11:16 AM
Well if it is in a Dialog you could use


char the_text[256];
int length=0;

case YOUR_CASE_HERE:

GetDlgItemText(hwnd,IDC_YOURTEXTBOX,the_text,256);//get text
length=strlen(the_text);//set var==length of the text

return TRUE;
break;



or if you have just a plain window you could do:

char the_text[256];
int length=0;

case YOUR_CASE_HERE:

GetWindowText(hwnd_of_text_box,the_text,256);
length=strlen(the_text);//set var==length of the text

return TRUE;
break;


That should help :)

ovidiucucu
June 14th, 2005, 11:34 AM
You can get the text length by a single call of GetWindowTextLength or sending WM_GETTEXTLENGTH message as Boris already stated.

kkez
June 15th, 2005, 05:40 AM
Well if it is in a Dialog you could use


char the_text[256];
int length=0;

case YOUR_CASE_HERE:

GetDlgItemText(hwnd,IDC_YOURTEXTBOX,the_text,256);//get text
length=strlen(the_text);//set var==length of the text

return TRUE;
break;



or if you have just a plain window you could do:

char the_text[256];
int length=0;

case YOUR_CASE_HERE:

GetWindowText(hwnd_of_text_box,the_text,256);
length=strlen(the_text);//set var==length of the text

return TRUE;
break;


That should help :)What if the text is more than 256 chars?