How to retrieve the value of a dialog edit control?
I have a dialog resource, ID_DIALOG with an edit control, ID_TXTFORM
How do I retrieve the current text of the text field on the WM_COMMAND switch wparam message loop and assign it to a variable?
1) Get the HWND to the edit control. You can get this with the GetDlgItem() function:
|
HWND editbox = GetDlgItem( YourDlgHwnd, ID_TXTFORM );
|
2) Get the text from the edit box wtih GetWindowText:
1 2
|
char text[100];
GetWindowText( editbox, text, 100 );
|
If you want you can make sure the string is big enough by checking GetWindowTextLength():
1 2 3
|
int length = GetWindowTextLength( editbox ) + 1; // +1 for null terminator
char* text = new char[length];
GetWindowText(editbox,text,length);
|
Thanks.
Topic archived. No new replies allowed.