1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38:
| function GetFocusedControlSelText: String; var focusedHandle, activeWinHandle: HWND; focusedThreadID : DWORD; pc:PWideChar; str:String; i,lpos,fpos:integer; begin i:=0; Windows.SetFocus(0); SetLengtH(str,65536); pc := PWideChar(stR); activeWinHandle := GetForegroundWindow; focusedThreadID := GetWindowThreadProcessID(activeWinHandle, nil) ; if AttachThreadInput(GetCurrentThreadID, focusedThreadID, true) then try focusedHandle := Windows.GetFocus; if focusedHandle <> 0 then begin i := SendMessage(focusedHandle, EM_GETSEL, 0, 0); if( i > 0 ) then begin lpos := (i shr 16) AND $FFFF; fpos := i and $FFFF; i := SendMessage(focusedHandle, WM_GETTEXT, 65536, Integer(pc)); if( i <> 0 ) then begin result := copy(str,fpos+1,lpos-fpos); end; end; SetLength(str,i); result := str; end finally AttachThreadInput(GetCurrentThreadID, focusedThreadID, false) ; end; end; |