Jump to content
  • Advertisement
Sign in to follow this  
pepeland

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

This topic is 4772 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
You could process the WM_INITDIALOG message in you dialog function and set the text of the control through SetDlgItemText(hDlg,IDC_EDIT1,name);

Share this post


Link to post
Share on other sites
If you're only dealing with numbers, here's how to do it:
////////
// In C:
////////

// To get the value
char text[32];
GetDlgItemText(hwnd, IDC_EDIT1, text, 32);

int value;
sscanf(text, "%d", &value);

// To set the value
int value = 17;
char text[32];
sprintf(text, "%d", value);
SetDlgItemText(hwnd, IDC_EDIT1, text);


//////////
// In C++:
//////////

// To get the value
char text[32];
GetDlgItemText(hwnd, IDC_EDIT1, text, 32);
std::istringstream in(std::string(text));

int value;
in >> value;

// To set the value
int value = 18;
std::ostringstream out;
out << value;
SetDlgItemText(hwnd, IDC_EDIT1, out.str().c_str());

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!