Getting string from edit text using VC++ Win32 application

Use the following code for getting the value from edit text in VC++ using Win32 application.


case WM_COMMAND:

if(LOWORD(wParam)==IDC_btnStrCmp)
{
int length = GetWindowTextLength(GetDlgItem(hDlg, IDC_EDIT1));
if(length > 0)
{
char* tempChar;
tempChar= (char*)GlobalAlloc(GPTR, length + 1);
GetDlgItemText(hDlg, IDC_EDIT1, LPWSTR(tempChar), length + 1);
MessageBox(NULL,LPWSTR(tempChar),L"test",MB_OK);
}
}

No comments: