I need to add text to win32 edit control I have a working function for this, but the text printed in the edit control is gibrish why? sample code taken from microsoft example from here
void settext(HWND hDlg,std::string s) { //std::wstring ws; //ws.assign( s.begin(), s.end() ); //LPWSTR pwst = &ws[0]; //// get temporary LPCWSTR (pretty safe) //LPCWSTR pcwstr = ws.c_str(); //SetDlgItemText(hWndEdit, IDC_EDIT1,pcwstr); HWND hWndEdit = GetDlgItem (hDlg, IDC_EDIT1); LPSTR pst = &s[0]; int ndx = GetWindowTextLength (hWndEdit); SetFocus (hWndEdit); #ifdef WIN32 SendMessage (hWndEdit, EM_SETSEL, (WPARAM)ndx, (LPARAM)ndx); #else SendMessage (hWndEdit, EM_SETSEL, 0, MAKELONG (ndx, ndx)); #endif SendMessage (hWndEdit, EM_REPLACESEL,0,(LPARAM)pst); }
and from the call to DlgProc im:
std::string ss("wwwwww"); settext(hwnd,ss);
Update
even if I do as suggested here:
SendMessage (hWndEdit, EM_REPLACESEL,0,(LPARAM)s.c_str());
which transmit compilation but still typed characters are gibrish
and if I do this:
LPSTR pst = s.c_str()
it does not pass error compilation:
error C2440: 'initializing': cannot convert from 'const char *' to 'LPSTR'
source share