Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting values from EditBox

Status
Not open for further replies.

bells

MIS
Oct 5, 2001
51
CA

I am worikng on Windows programming
and wants to get the value of an editBox or text box defined as.

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 let window decide
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

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.

 
To get a number from an editbox you can use:

int number = GetDlgItemInt(hwnd, IDC_EDITCONTROL, NULL, FALSE);

In your CreateWindow call your have to add:

,(HMENU)IDC_EDITCONTROL ,

in the HMENU field (and then #define IDC_EDITCONTROL 800 at the top of your program).

Hope that helps.
 


i do not think i understand u about
the second part the IDC_EDITCONTROL

u see my EditBox is defined this way and its handle is hwndPrincipal

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 let window decide
90,//y co
155,//width
45,//height
hwnd, //NO parent
NULL, //NO MENU
hThisInst, //instance handle
NULL //NO additional arguments
);
at what point do i introduce the edit box ID
You mentioned above. i can not use hwndPrinicpal
because what the funcion want is an integer value
not a window handle. thank u in advance again.

 
My login handle handle won't work for some reason.

You can assign a control ID to the edit box by using the menu field. For example:


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 let window decide
90,//y co
155,//width
45,//height
hwnd, //NO parent
(HMENU)800, // control ID
hThisInst, //instance handle
NULL //NO additional arguments
);


and then when you want the integer:

int number = GetDlgItemInt(hwnd, 800, NULL, FALSE);

Rather than using the number 800 in your code it would be better to define the number at the top of your code like so:

#define IDC_EDIT_ID 800

Now rather than use 800 you can use IDC_EDIT_ID.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top