Add a variable to edit box in win32 program(visual c++)

Started by
6 comments, last by pepeland 18 years, 7 months ago
Hi, I have a problem. I created a dialog box by resource script and adding a edit box on. I want add a variable to this edit box in a win32 program(without MFC and wizard). how i can?
Hamid.R Gharahzadehwww.pepeland.net
Advertisement
I believe you make a char* to the value of the edit box...
We should do this the Microsoft way: "WAHOOOO!!! IT COMPILES! SHIP IT!"
I mean is how i can attach this variable to this edit box.
with ID or other?
for example i have an edit box with id: IDC_EDIT1 and define a varible :
char * Name;
Now how can attach it to edit box?
Hamid.R Gharahzadehwww.pepeland.net
I think it is something like:

SetDlgItemText(hwnd,IDC_EDIT1,"text");

Unfortunately, you can't make it so that when text is entered into an edit box, the char* pointer automatically will "contain" the updated text. You have to set and receive the text manually.

Use WM_SETTEXT with the char* variable in the lParam to set the text
and WM_GETTEXT to retrieve the text with the maximum length in wParam and receiving variable in lParam

Consult MSDN on these two messages and SendDlgItemMessage
You could process the WM_INITDIALOG message in you dialog function and set the text of the control through SetDlgItemText(hDlg,IDC_EDIT1,name);
If you're only dealing with numbers, here's how to do it:
////////// In C://////// // To get the valuechar text[32];GetDlgItemText(hwnd, IDC_EDIT1, text, 32); int value;sscanf(text, "%d", &value); // To set the valueint value = 17;char text[32];sprintf(text, "%d", value);SetDlgItemText(hwnd, IDC_EDIT1, text);  //////////// In C++:////////// // To get the valuechar text[32];GetDlgItemText(hwnd, IDC_EDIT1, text, 32);std::istringstream in(std::string(text)); int value;in >> value; // To set the valueint value = 18;std::ostringstream out;out << value;SetDlgItemText(hwnd, IDC_EDIT1, out.str().c_str());
Thank you very much
Hamid.R Gharahzadehwww.pepeland.net

This topic is closed to new replies.

Advertisement