11-24-2007, 05:30 PM
I tested EM_REPLACESEL, and it does not work when the window belongs to other process. But can be used str.setsel or WM_CHAR.
Function EditControlSelectReplace
Now tested with EM_REPLACESEL on Windows 7, and it works. Then better use this version:
Function EditControlSelectReplace
Function EditControlSelectReplace
;/
function hwnd ifrom ito [$replacetext]
;Selects and optionally replaces part of text of an Edit or rich edit control.
;The window can be inactive. It can belong to any process.
;hwnd - control handle.
;ifrom, ito - 0-based character index. Use 0/-1 to select all text. Use -1/-1 to remove selection. Use -2/-2 to move the text cursor to the end.
;replacetext - text that will replace the selection. Can be "" to remove the selected text. If omitted or 0, does not replace.
SendMessage hwnd EM_SETSEL ifrom ito
if(replacetext)
,if(!replacetext[0]) SendMessage hwnd EM_REPLACESEL 0 0 ;;this works in other process too
,else
,,GetWindowThreadProcessId hwnd &_i
,,if(_i=GetCurrentProcessId) SendMessage hwnd EM_REPLACESEL 0 replacetext
,,else for(_i 0 len(replacetext)) SendMessage hwnd WM_CHAR replacetext[_i] 0
Now tested with EM_REPLACESEL on Windows 7, and it works. Then better use this version:
Function EditControlSelectReplace
;/
function hwnd ifrom ito [$replacetext]
;Selects and optionally replaces part of text of an Edit or rich edit control.
;The window can be inactive. It can belong to any process.
;hwnd - control handle.
;ifrom, ito - 0-based character index. Use 0/-1 to select all text. Use -1/-1 to remove selection. Use -2/-2 to move the text cursor to the end.
;replacetext - text that will replace the selection. Can be "" to remove the selected text. If omitted or 0, does not replace.
SendMessageW hwnd EM_SETSEL ifrom ito
if(replacetext) SendMessageW hwnd EM_REPLACESEL 1 _s.unicode(replacetext)