只要响应application.onactivate事件可以了
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, AppEvnts;
const
wm_newcaret=wm_user+1;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Image1: TImage;
ApplicationEvents1: TApplicationEvents;
procedure Edit1Enter(Sender: TObject);
procedure ApplicationEvents1Activate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure newcaret(var msg:Tmessage);message wm_newcaret;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Edit1Enter(Sender: TObject);
begin
postmessage(handle,wm_newcaret,0,0);
end;
procedure TForm1.newcaret(var msg: Tmessage);
begin
edit1.setfocus;
CreateCaret(edit1.Handle,image1.Picture.Bitmap.Handle,edit1.width,edit1.height);
showcaret(edit1.handle);
end;
procedure TForm1.ApplicationEvents1Activate(Sender: TObject);
begin
CreateCaret(edit1.Handle,image1.Picture.Bitmap.Handle,edit1.width,edit1.height);
showcaret(edit1.handle);
end;
end.