Hi, I created a simple window with a multiline Edit Control:
Edit = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("EDIT"), NULL,
WS_CHILD | WS_VISIBLE | ES_MULTILINE,
20, 200, 200, 200,
hWnd, (HMENU)EDIT, GetModuleHandle(NULL), NULL);
If I set text using a WM_SETTEXT message, I don't get errorrs, but if I use EM_REPLACESEL I get Error 5 (ERROR_ACCESS_DENIED):
SendMessage(GetDlgItem(hWnd, EDIT), EM_REPLACESEL, 0, (LPARAM)TEXT("\r\nSome text"));
if (GetLastError()) {
/* Error 5 ERROR_ACCESS_DENIED */
}
Same problem with EM_SETSEL:
SendMessage(GetDlgItem(hWnd, EDIT), EM_SETSEL, (WPARAM)(0),(LPARAM)(-1));
SendMessage(GetDlgItem(hWnd, EDIT), EM_REPLACESEL, 0, (LPARAM)TEXT("\r\nSome text"));
if (GetLastError()) {
/* Error 5 ERROR_ACCESS_DENIED */
}
I noticed that if I send a WM_SETFOCUS message before the EM_REPLACESEL there are no error:
SendMessage(GetDlgItem(hWnd, EDIT), WM_SETFOCUS, (WPARAM)GetDlgItem(hWnd, EDIT), 0);
SendMessage(GetDlgItem(hWnd, EDIT), EM_REPLACESEL, 0, (LPARAM)TEXT("\r\nSome text"));
if (GetLastError()) {
/* NO ERRORS */
}
How can I resolve this problem? Do I have to send a WM_SETFOCUS message before the EM_REPLACESEL one every time I want to append some text to my Editbox?
Thanks for help!