ホットキーを押すと、特定のテキストをウィンドウから選択したテキストに連結するプログラムを作成しようとしています。例:「マウスで選択したテキストをキャプチャする」というテキストがあり、マウスで「テキスト」という単語を選択すると、特定のホットキーを押すと、次のようにクリップボードにコピーされます:xxx + text + xxx。私の質問は、マウスで選択した単語を返す方法ですか?
ありがとう!!
あなたが私に言ったことから、私はこれを理解しました:
unit Unit4;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Clipbrd;
type
TForm4 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure WMHotkey(var Message: TWMHotKey); message WM_HOTKEY;
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form4: TForm4;
implementation
const
MY_ID = 123;
{$R *.dfm}
procedure TForm4.FormCreate(Sender: TObject);
begin
RegisterHotKey(Handle, MY_ID, MOD_CONTROL, ord('1'));
end;
procedure TForm4.FormDestroy(Sender: TObject);
begin
UnregisterHotKey(Handle, MY_ID);
end;
procedure TForm4.WMHotkey(var Message: TWMHotKey);
lookup_word: string;
begin
clipboard.clear;
if Message.HotKey = MY_ID then
begin
if not AttachThreadInput(GetCurrentThreadId, GetWindowThreadProcessId(GetForegroundWindow), true) then
RaiseLastOSError;
try
SendMessage( GetFocus, WM_GETTEXT, 0, 0 );
lookup_word:= clipboard.astext;
edit1.Text := lookup_word;
Clipboard.AsText := '<font color=blue> edit1.text </font>';
SendMessage(GetFocus, WM_PASTE, 0, 0);
finally
AttachThreadInput(GetCurrentThreadId, GetWindowThreadProcessId(GetForegroundWindow), false);
end;
end;
end;
end;
end.
これでよろしいですか?
意図したとおりにアプリを作成することができました。しかし、私は今別の問題に遭遇しました。aspx アプリケーションでは動作しません。aspx 編集ボックスからのテキストを認識しません。この問題を回避する方法はありますか?
ありがとう!