VC++ DialogBox()
I created the proper resource.rc file with an about box which contains: one edit box called IDC_EDIT1, one OK and one CANCEL button.
I''d like to get the value entered in the edit box after pressing on ''OK''.
I open the edit box with the following instruction:
nret=DialogBox(hInstance, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
in your About callback function - intercept the WM_COMMAND message and put this...
case WM_COMMAND :
if ( LOWORD( wParam ) == IDOK )
{
char text[ 1024 ];
GetDlgItemText ( hwnd, IDC_EDIT1, text, sizeof(text) );
}
return FALSE;
with that code, the text entered will be in the variable "text". If you need to get the number of characters so you can dynamically allocate the array - do this..
int bytes = SendDlgItemMessage ( hwnd, IDC_EDIT1, WM_GETTEXTLENGTH, 0, 0 );
char * text = new char [ bytes + 1 ];
hope that helped!
White space is free - so use it!!!
[edited by - TrapZZ on August 9, 2003 11:28:36 AM]
case WM_COMMAND :
if ( LOWORD( wParam ) == IDOK )
{
char text[ 1024 ];
GetDlgItemText ( hwnd, IDC_EDIT1, text, sizeof(text) );
}
return FALSE;
with that code, the text entered will be in the variable "text". If you need to get the number of characters so you can dynamically allocate the array - do this..
int bytes = SendDlgItemMessage ( hwnd, IDC_EDIT1, WM_GETTEXTLENGTH, 0, 0 );
char * text = new char [ bytes + 1 ];
hope that helped!
White space is free - so use it!!!
[edited by - TrapZZ on August 9, 2003 11:28:36 AM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement