C language > Pocket PC and Smartphone questions
GetTextLen Problems
gromit:
Hi all
In using the following code
i was losing the global string g_catstr
it seems that GetWindowTextLength may return a longer length than is actually in the control
having tried it with
GetDlgItemText(hDlg, ADDPART_PER_COMBO,st_part.perstr,12);
12 being initialised len of st_part.perstr
it works and does not overwrite g_catstr
so what is the best way to obtain len and not have to state a hardcoded figurelike 12
Ansi version
//int clen = GetWindowTextLength(GetDlgItem(hDlg, ADDPART_PER_COMBO));
Wide version
int clen = GetWindowTextLengthW(GetDlgItem(hDlg, ADDPART_PER_COMBO));
if (clen>0)
{
wchar_t xstr[50];
swprintf(xstr, L"%d",clen); //always evaluates to 26 for ansi or wide
CheckMemoryStatus();
MessageBox(g_hwnd,xstr, L"len is", MB_OK | MB_ICONINFORMATION);
MessageBox(g_hwnd,g_catstr, L"In AddEditDlog topOK", MB_OK | MB_ICONINFORMATION);
GetDlgItemText(hDlg, ADDPART_PER_COMBO,st_part.perstr,12);
if i use clen+1 it overwrites g_catstr and shows it as empty
//GetWindowText(GetDlgItem(hDlg, ADDPART_PER_COMBO),st_part.perstr,clen+1);
MessageBox(hDlg,st_part.perstr, L"per string INFO", MB_OK | MB_ICONINFORMATION);
MessageBox(g_hwnd,g_catstr, L"In AddEditPArtsDlog botOK", MB_OK | MB_ICONINFORMATION);
}
gromit:
Hi again
Replying to my own enquiry here
Having, as i stated above, found why i was loosing a global variable.
I have reached the conclusion that it woul be far better if there was a way to simply recall from within the program the length at which the original string was initialised.
So does anyone know of a way to return the length the string was initialised at
i.e wchar_t xstring[50]
i want that 50
i can obviously get it by forming an array of lengths or enum it
but is there a way that is already avaible.
GetIniTialisedStringLen() sort o thing
an odd one i know
But any help Gratefully appreciated
Gromit
TimoVJL:
--- Quote from: gromit on April 13, 2013, 04:23:21 PM ---So does anyone know of a way to return the length the string was initialised at
i.e wchar_t xstring[50]
i want that 50
--- End quote ---
Do you mean sizeof(xstring)
EDIT: sizeof(xstring)/sizeof(xstring[0])
gromit:
Thankyou for your reply timovjl
Appreciated
struct
{
wchar_t qtystr[40];
wchar_t itemstr[200];
wchar_t sizestr[30];
wchar_t pricestr[12];
wchar_t perstr[12];
}st_part;
clen = sizeof(st_part.perstr);
swprintf(xstr, L"%d",clen);
MessageBox(g_hwnd,xstr, L"hopefully initial len of st_part.perstr is", MB_OK ,MB_ICONINFORMATION);
This returns 24 for len perstr which is is initialised in above struct at 12
???
czerny:
--- Quote from: gromit on April 13, 2013, 04:59:30 PM ---This returns 24 for len perstr which is is initialised in above struct at 12
???
--- End quote ---
12 times sizeof(wchar_t) equals 24.
Navigation
[0] Message Index
[#] Next page
Go to full version