C, Win32: l need help getting user input[Solved]
-
TCHAR userName[100];//user input buffer hwndedit=GetDlgItem(hwnd,IDC_UNICALPTUME_SUBJECT_TBOX);//gets edit control's handle userName[100]=(TCHAR) SendMessage(hwndedit,WM_GETTEXT,(WPARAM)sizeof(userName)/sizeof(userName[0]),(LPARAM)userName);//Sent message return (INT_PTR)TRUE; case IDOK://checks if buffer is empty or not when the user clicks OK on the dialog if(userName!=NULL) EndDialog(hwnd,TRUE); return (INT_PTR)TRUE; l also tried GetWindowText(hwnd,userName,sizeof(userName)/sizeof(userName[0])) still it doesn't work. Please can someone me guide me on getting user input and checking if the buffer is empty or not. Thanks everyone.
-
TCHAR userName[100];//user input buffer hwndedit=GetDlgItem(hwnd,IDC_UNICALPTUME_SUBJECT_TBOX);//gets edit control's handle userName[100]=(TCHAR) SendMessage(hwndedit,WM_GETTEXT,(WPARAM)sizeof(userName)/sizeof(userName[0]),(LPARAM)userName);//Sent message return (INT_PTR)TRUE; case IDOK://checks if buffer is empty or not when the user clicks OK on the dialog if(userName!=NULL) EndDialog(hwnd,TRUE); return (INT_PTR)TRUE; l also tried GetWindowText(hwnd,userName,sizeof(userName)/sizeof(userName[0])) still it doesn't work. Please can someone me guide me on getting user input and checking if the buffer is empty or not. Thanks everyone.
userName[100]=(TCHAR) SendMessage(hwndedit,WM_GETTEXT,(WPARAM)sizeof(userName)/sizeof(userName[0]),(LPARAM)userName);
You are casting your return value to a single character and storing it in one character position beyond the end of your buffer. You should just use
GetWindowText
like this:int nSize = GetWindowText(hwndedit, userName, _countof(userName));
See GetWindowText function (Windows)[^] and _countof Macro[^].
-
userName[100]=(TCHAR) SendMessage(hwndedit,WM_GETTEXT,(WPARAM)sizeof(userName)/sizeof(userName[0]),(LPARAM)userName);
You are casting your return value to a single character and storing it in one character position beyond the end of your buffer. You should just use
GetWindowText
like this:int nSize = GetWindowText(hwndedit, userName, _countof(userName));
See GetWindowText function (Windows)[^] and _countof Macro[^].
Thanks.