how to select or highlight editbox text ?

Started by davidp@ensuredr.com, November 18, 2019, 02:16:52 AM

Previous topic - Next topic

davidp@ensuredr.com

how to select or highlight editbox text ?

for example like the drop down field in the picture.


td

In a previous topic, you mentioned the CB_SETEDITSEL message.  In a similar fashion, you can use EM_SETSEL to select part or all of an edit box's text.

https://docs.microsoft.com/en-us/windows/win32/controls/em-setsel

Note that since the message has two numeric parameters, you will need to use the DllCall function to call SendMessageW directly.  The WIL SendMessageW function can only be used when the LPARAM parameter is a string or 0.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

davidp@ensuredr.com

thanks it worked great! by the way you don't need dll call, for me it work like this:

         EM_SETSEL = 177 
         hWnd = DialogControlGet(handle, elementName, @dchWnd)
SendMessageW(hWnd, EM_SETSEL, 0, -1)


how do you know Which winbatch control belongs to Which windows control ? for example that EM_SETSEL will work with winbatch editbox.

td

Quote from: davidp@ensuredr.com on November 18, 2019, 11:29:33 PM
thanks it worked great! by the way you don't need dll call, for me it work like this:

         EM_SETSEL = 177 
         hWnd = DialogControlGet(handle, elementName, @dchWnd)
SendMessageW(hWnd, EM_SETSEL, 0, -1)


Using SendMessageW only appears to work because of dumb luck.  When you use SendMessageW you are not sending a -1 to the control.  You are sending the control a memory address of string text in the last parameter to the function.  The control treats the memory address as an integer that just happens to be big enough to cause the control to select the contents.  Use DllCall.

Quote
how do you know Which winbatch control belongs to Which windows control ? for example that EM_SETSEL will work with winbatch editbox.

It should be self-evident if you have any familiarity with the Windows UI elements.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade