I have just tried this (with VS 2010 Express) and it selects and highlights the text correctly. Can you show the exact code you are using?
As a suggestion, do not use the A or W suffixes on Windows API calls. Use the base name, without the suffix, and let the compiler generate the correct call based on your projrct's Unicode/ASCII setting.
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???
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 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.
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 or CreateWindowEx.
You cannot normally do that, generated resource IDs are numbers. You can use strings to refer to resources but it requires a detailed knowledge of resource files and the rc compiler. This also begs the question, why do you need so many buttons?
I suspect you need all the buttons for something like I have done which was a grid display for a process plant control switches for pumps and the like.
What you can do is attach a text string as either a property of the button handle via "SetProp" or alternative set the string as
a resource using RT_STRING to the ID of the button and use FindResourceEx to pull back the string matching the button ID. The
String resources are stored in sections of up to 16 strings per section so you will need to provide a function to pull it back.
The SetProp way is easier but can only be created in the WM_CREATE of the button creation, or just after the CreateWindowEx call creating the button and so needs a little more setup work than a string resource list.