如何在别的应用程序的窗口中创建一个按钮之类的控件,差捕捉其事件? (70分)

  • 主题发起人 主题发起人 zxp_ping
  • 开始时间 开始时间
Z

zxp_ping

Unregistered / Unconfirmed
GUEST, unregistred user!
没人知道吗?
 
[blue]下面的代码绝对管用[/blue]
代码:
unit main;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    procedure ButtonMouseUp(Sender: TObject; Button: TMouseButton;Shift: TShiftState; X, Y: Integer);
    procedure ButtonMouseDown(Sender: TObject; Button: TMouseButton;Shift: TShiftState; X, Y: Integer);
    procedure FormDestroy(Sender: TObject);
    procedure FormActivate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  btnNewStart:TButton;
  Shell_TrayWnd:Hwnd;
  SystemStartButton:Hwnd;
  MouseClicked:Boolean=False;
implementation

{$R *.DFM}
procedure TForm1.ButtonMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
begin
  if PtInRect(btnNewStart.BoundsRect,Point(X,Y)) and MouseClicked then
  begin
[red]在这儿写你自己的代码[/red]
代码:
  end;
  MouseClicked:=False;
end;

procedure TForm1.ButtonMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
begin
  if PtInRect(btnNewStart.BoundsRect,Point(X,Y)) then
    MouseClicked:=True
  else
    MouseClicked:=False;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  ShowWindow(SystemStartButton,SW_SHOW);
end;

procedure TForm1.FormActivate(Sender: TObject);
begin
  Shell_TrayWnd:=FindWindow('Shell_TrayWnd','');
  SystemStartButton:=GetWindow(Shell_TrayWnd,GW_CHILD);
  ShowWindow(SystemStartButton,SW_HIDE);
  btnNewStart:=TButton.CreateParented(Shell_TrayWnd);
  btnNewStart.Caption := '新开始';
  btnNewStart.OnMouseUp := ButtonMouseUp;
  btnNewStart.OnMouseDown := ButtonMouseDown;
  ShowWindow(btnNewStart.handle,SW_SHOW);
end;

end.
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
916
SUNSTONE的Delphi笔记
S
S
回复
0
查看
894
SUNSTONE的Delphi笔记
S
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
后退
顶部