|
-
August 3rd, 2010, 07:33 AM
#1
Problem to append text to an editbox
Hi, I created a simple window with a multiline Edit Control:
Code:
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):
Code:
SendMessage(GetDlgItem(hWnd, EDIT), EM_REPLACESEL, 0, (LPARAM)TEXT("\r\nSome text"));
if (GetLastError()) {
/* Error 5 ERROR_ACCESS_DENIED */
}
Same problem with EM_SETSEL:
Code:
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:
Code:
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!
-
August 3rd, 2010, 10:15 AM
#2
Re: Problem to append text to an editbox
 Originally Posted by mariop
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!
No, you should not send WM_SETFOCUS message at all!
EM_REPLACESEL is a notification message sent by WIndows after focus has been already set...
You should call SetFocus API instead. See this KB
Victor Nijegorodov
-
August 3rd, 2010, 10:34 AM
#3
Re: Problem to append text to an editbox
Not all Windows API functions set the last error (value returned by GetLastError).
Although SendMessage can set last error (5, access denied) for some messages under Vista (see User Interface Privilege Isolation (UIPI)), it seems it's not the case of your program.
Just call SetLastError(0) before SendMessage to be sure that last error is set.
-
August 12th, 2010, 01:18 AM
#4
Re: Problem to append text to an editbox
hi,
I have to send a WM_SETFOCUS message before the EM_REPLACESEL one every time I want to append some text to my Editbox? pl. explained for me
regards,
phe9oxis,
http://www.guidebuddha.com
-
August 12th, 2010, 01:32 AM
#5
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|