PDA

Click to See Complete Forum and Search --> : editBox and Windows Programming


bell
May 10th, 2002, 05:00 PM
I am worikng on Windows programming
and wants to get the value of an editBox or text box defined as.

//EditBox is defined this way

hwndPrincipal = CreateWindow(
"EDIT", //name of windwo class
NULL,//title
WS_VISIBLE|WS_CHILD|WS_BORDER |ES_RIGHT|WS_TABSTOP,// WINDOW STYLE NORMAL
260,//x coordinate
90,//y co
155,//width
45,//height
hwnd,
NULL,
hThisInst, //instance handle
NULL //NO additional arguments
);

I am typing a number and want that number
to use it in a calulaton i tried the following but
did not work

//get the values from text boxes
//principal is decalred above as char principal[20]

GetWindowText(hwndPrincipal,principal,NULL);

//then calculate
computeNumber(principal);

I am not getting any error message but the result
i am getting is alway 0

any suggestion is appreciated

Megatron
May 10th, 2002, 05:32 PM
Make sure to pass the length of the string in lParam.

int len = GetWindowTextLength(hwndPrincipal);
if( len )
{
principle = new char[len];
GetWindowText(hwndPrincipal,principal,len);
}

bell
May 12th, 2002, 08:05 PM
thanks megtron

it almost worked except the line

principle = new char[len];

is giving me an error. when i comment out
the above line (keeping all the other ..no if statement ). it works fin except it is always one value less
than what i typed in the edit box.
example if I typed 123 it shows me only 12
when i check the len variable value it is ok it shows me 3.

but

if i do

len+=1

then it shows all values typed in the editbox.

can u explain pls the use of this line

principle = new char[len];


any reason why it is short of one character ??
thank u again.