如何得到 MS WORD里插入符号的位置?下面的这段代码能获得其他程序中插入符的位置,但在MS word中不行unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure myWM_ACTIVATE(var Message: TMessage); message WM_ACTIVATE;
procedure Button1Click(Sender: TObject);//截获消息
private
{ Private declarations }
public
{ Public declarations }
HActWin,Hself: HWND;
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.myWM_ACTIVATE(var Message: TMessage);
begin
if Message.wParam = WA_CLICKACTIVE then
begin
//SetActiveWindow(message.lParam);
if (HActWin<>message.lParam) and (message.lParam<>Hself) then
HActWin:=message.lParam;
end;
end;procedure TForm1.Button1Click(Sender: TObject);
var
focushld,windowhld:hwnd;
threadld:dword;
P1:TPoint;
begin SetActiveWindow(HActWin);
windowhld:=GetForegroundWindow;
threadld:=GetWindowThreadProcessId(Windowhld,nil); //Windowhld
AttachThreadInput(GetCurrentThreadId,threadld,true);
GetCaretPos(P1);
Caption:=IntToStr(P1.X )+'::'+IntToStr(P1.y ) ;
Focushld:=getfocus;
AttachThreadInput(GetCurrentThreadId,threadld,false); if focushld = 0 then Exit;
end;end.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure myWM_ACTIVATE(var Message: TMessage); message WM_ACTIVATE;
procedure Button1Click(Sender: TObject);//截获消息
private
{ Private declarations }
public
{ Public declarations }
HActWin,Hself: HWND;
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.myWM_ACTIVATE(var Message: TMessage);
begin
if Message.wParam = WA_CLICKACTIVE then
begin
//SetActiveWindow(message.lParam);
if (HActWin<>message.lParam) and (message.lParam<>Hself) then
HActWin:=message.lParam;
end;
end;procedure TForm1.Button1Click(Sender: TObject);
var
focushld,windowhld:hwnd;
threadld:dword;
P1:TPoint;
begin SetActiveWindow(HActWin);
windowhld:=GetForegroundWindow;
threadld:=GetWindowThreadProcessId(Windowhld,nil); //Windowhld
AttachThreadInput(GetCurrentThreadId,threadld,true);
GetCaretPos(P1);
Caption:=IntToStr(P1.X )+'::'+IntToStr(P1.y ) ;
Focushld:=getfocus;
AttachThreadInput(GetCurrentThreadId,threadld,false); if focushld = 0 then Exit;
end;end.
如果是,那就事先在Word中插入书签,然后在程序中在指定书签处插入你的内容。
如果不是,只有帮你UP一下