完整的例子API
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
GroupBox1: TGroupBox;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
procedure WinProc(var Message: TMessage);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
var
Label1: HWND;
OldProc: TWndMethod;
procedure TForm1.FormCreate(Sender: TObject);
begin
//你单击这个标签试试
Label1 := Windows.CreateWindow('static', 'testing', SS_NOTIFY or WS_VISIBLE or WS_CHILD,
10, 10, 100, 25, GroupBox1.Handle, 0, hInstance, nil);
if Label1 <> 0 then begin
OldProc := GroupBox1.WindowProc;
GroupBox1.WindowProc := WinProc;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
PH: HWND;
begin
//你要先找出GroupBox1.Handle的句柄
PH := FindWindowEx(GroupBox1.Handle, 0, nil, 'testing');
if PH <> 0 then begin
SendMessage(GroupBox1.Handle, WM_COMMAND, 0, PH);
// ShowMessage(Format('%2.2X', [PH]));
end;
end;
procedure TForm1.WinProc(var Message: TMessage);
begin
if Message.LParam = Label1 then
begin
if HIWORD(Message.WParam) = BN_CLICKED then
ShowMessage('testing notify click');
end
else OldProc(Message);
end;
end.
dfm:
=========
object Form1: TForm1
Left = 192
Top = 107
Width = 696
Height = 480
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object Button1: TButton
Left = 256
Top = 152
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 0
OnClick = Button1Click
end
object GroupBox1: TGroupBox
Left = 56
Top = 16
Width = 185
Height = 105
Caption = 'GroupBox1'
TabOrder = 1
end
end