Author Topic: how to select or highlight editbox text ?  (Read 80 times)

davidp@ensuredr.com

  • Newbie
  • *
  • Posts: 12
how to select or highlight editbox text ?
« on: November 18, 2019, 02:16:52 am »
how to select or highlight editbox text ?

for example like the drop down field in the picture.


td

  • Tech Support
  • *****
  • Posts: 3103
    • WinBatch
Re: how to select or highlight editbox text ?
« Reply #1 on: November 18, 2019, 08:08:47 am »
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

  • Newbie
  • *
  • Posts: 12
Re: how to select or highlight editbox text ?
« Reply #2 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:
Code: [Select]
         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

  • Tech Support
  • *****
  • Posts: 3103
    • WinBatch
Re: how to select or highlight editbox text ?
« Reply #3 on: November 19, 2019, 08:08:05 am »
thanks it worked great! by the way you don't need dll call, for me it work like this:
Code: [Select]
         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

davidp@ensuredr.com

  • Newbie
  • *
  • Posts: 12
Re: how to select or highlight editbox text ?
« Reply #4 on: November 20, 2019, 12:37:24 am »
thanks!