Copy Command Window Selected Text to Clipboard Programmatically

The code uses Editor functions from Foxtools.fll. See George Tasker's Extended Foxtools Help Download #9333 on UT for more info.

This is sample code. Add error handling and adjust to your requirements as necessary.

LOCAL ARRAY laEnv [25]
SET LIBRARY TO FoxTools ADDITIVE
&& Get the whandle for the current window
lnHandle = _WonTop()
lnResult = _EdGetEnv( lnHandle, @laEnv )
&& [ 17 ] SelStart
&& [ 18 ] SelEnd
&& [ 25 ] Editor Session:  0 - Command Window
 
IF ( lnResult = 0 ) OR ( laEnv[17] = 0 ) OR ( laEnv[25] <> 0 )
  _CLIPTEXT = ""
  RETURN
ENDIF
 
&& Get the current cursor position
lnSelStart = laEnv[17] 
lnSelEnd = laEnv[18] 
&& Store result into clipboard
_CLIPTEXT = _EdGetStr( lnHandle, lnSelStart, lnSelEnd )