Edit Control Problem
-
programmingalholic wrote:
I've tried to omit the suffix letter and it still produced the same effect.
That's because the A or W is nothing to do with your problem. That is just a suggestion for better code writing, and you should fix it in all your programs. As to the actual problem, what are the values of
selPos
andselEnd
when the code runs?The selPos is the value denotes the first character's position of the selected text and the selEnd is the value denotes the end character's position of the selected text. Did any VS.Community users have the same experience like me?
-
The selPos is the value denotes the first character's position of the selected text and the selEnd is the value denotes the end character's position of the selected text. Did any VS.Community users have the same experience like me?
programmingalholic wrote:
The selPos is the value denotes the first character's position of the selected text and the selEnd is the value denotes the end character's position of the selected text.
Seriously? :rolleyes: Richard asked what their values were, not what purpose they served.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
I want to select text in the Edit control and make it has visual effect that represents the highlight of selected text. But how does WM_SETSEL come? It was undefined in the edition of my Visual Studio. Any suggestion please??
programmingalholic wrote:
But how does WM_SETSEL come?
Do you mean how is it used?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
The selPos is the value denotes the first character's position of the selected text and the selEnd is the value denotes the end character's position of the selected text. Did any VS.Community users have the same experience like me?
-
I want to select text in the Edit control and make it has visual effect that represents the highlight of selected text. But how does WM_SETSEL come? It was undefined in the edition of my Visual Studio. Any suggestion please??
-
I've used SendMessageW API to direct an EM_SETSEL message to a designated Edit control to make it locates the searched text entered from the another Edit control. Why it doesn't provide visual feedback to reflect its current state? I used Spy++ to detect the EM_SETSEL message and the message was correctly listed in the message window. Can anyone give suggestion? My current development tool is MSVS Community 2015, project type is Win32 that merely uses A.P.I.
The default behaviour of edit controls is showing the selection only when the control has the focus. From your description I assume that another control (the search input field or a button) has the focus when you try to set the selection. But there is an option to show the selection even when the edit control does not have the focus: ES_NOHIDESEL[^]. Unfortunately the style can't be changed once the control exists. You have to set it when creating the edit control. If it is defined as static resource, set the option there (e.g. using the resource editor). For dynamically created edit controls pass the flag in the style parameter when calling
CreateWindow
orCreateWindowEx
. -
I've tried to omit the suffix letter and it still produced the same effect. Below is code that sends the EM_SETSEL message to the Edit control.
int selPos = (int)(pInitialFound - lpWStr1) + 1;
int selEnd = selPos + (lstrlenW(lpWStr0));
SendMessage(hwndEdit, EM_SETSEL, selPos, selEnd);Are there any suggestions to better correct that problem?
As per Richard said debug the dam thing because there is something wrong with a value and you are asking us to guess what. However something obvious to me which you have not explained you have two different string pointers in the above lpWStr1 and lpWstr0 and since there is something wrong with selPos or selEnd which you haven't debugged is this related as no explaination of these???
In vino veritas
-
I've tried to omit the suffix letter and it still produced the same effect. Below is code that sends the EM_SETSEL message to the Edit control.
int selPos = (int)(pInitialFound - lpWStr1) + 1;
int selEnd = selPos + (lstrlenW(lpWStr0));
SendMessage(hwndEdit, EM_SETSEL, selPos, selEnd);Are there any suggestions to better correct that problem?
programmingalholic wrote:
Below is code that sends the EM_SETSEL message to the Edit control.
int selPos = (int)(pInitialFound - lpWStr1) + 1;
int selEnd = selPos + (lstrlenW(lpWStr0));
SendMessage(hwndEdit, EM_SETSEL, selPos, selEnd);And what are the actual values of selPos, selEnd, and the length of the text in hwndEdit edit control?
-
programmingalholic wrote:
Below is code that sends the EM_SETSEL message to the Edit control.
int selPos = (int)(pInitialFound - lpWStr1) + 1;
int selEnd = selPos + (lstrlenW(lpWStr0));
SendMessage(hwndEdit, EM_SETSEL, selPos, selEnd);And what are the actual values of selPos, selEnd, and the length of the text in hwndEdit edit control?
-
The default behaviour of edit controls is showing the selection only when the control has the focus. From your description I assume that another control (the search input field or a button) has the focus when you try to set the selection. But there is an option to show the selection even when the edit control does not have the focus: ES_NOHIDESEL[^]. Unfortunately the style can't be changed once the control exists. You have to set it when creating the edit control. If it is defined as static resource, set the option there (e.g. using the resource editor). For dynamically created edit controls pass the flag in the style parameter when calling
CreateWindow
orCreateWindowEx
.That's 100% right !! It had to do with ES_NOHIDESEL style, I had succeeded tap into it. However, thanks to all members of this community that had posed attention to my problem. :-D
-
programmingalholic wrote:
Below is code that sends the EM_SETSEL message to the Edit control.
int selPos = (int)(pInitialFound - lpWStr1) + 1;
int selEnd = selPos + (lstrlenW(lpWStr0));
SendMessage(hwndEdit, EM_SETSEL, selPos, selEnd);And what are the actual values of selPos, selEnd, and the length of the text in hwndEdit edit control?
the actual value of selPos and selEnd just represent as what they are, both contained int value that denoted character index. To hwndEdit, the return value of GetWindowTextLengthW just not false ( other values than 0 ).
-
I know that. But have you actually used your debugger to check that they are both valid at the time of your
SendMessage
call? Is selPos >= 0, and selEnd > selPos && < editTextLen()?The selPos and selEnd had actually referred to the precise character index of the selected text. Thanks.