Marco Cantù 1998, Mastering Delphi 4
Project: CALLBACK.DPR
Project Structure
CALLBACK.DPR
program Callback;
uses
Forms,
CbackF in 'CbackF.pas' {FormCallback};
{$R *.RES}
begin
Application.Initialize;
Application.CreateForm(TFormCallback, FormCallback);
Application.Run;
end.
CBACKF.PAS
unit CbackF;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;
type
TFormCallback = class(TForm)
ListBox1: TListBox;
Panel1: TPanel;
BtnTitles: TButton;
procedure BtnTitlesClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FormCallback: TFormCallback;
implementation
{$R *.DFM}
type
EnumWindowsProc = function (Hwnd: THandle;
Param: Pointer): Boolean; stdcall;
function GetTitle (Hwnd: THandle; Param: Pointer): Boolean; stdcall;
var
Text: string;
begin
SetLength (Text, 100);
GetWindowText (Hwnd, PChar (Text), 100);
FormCallBack.ListBox1.Items.Add (
IntToStr (Hwnd) + ': ' + Text);
Result := True;
end;
procedure TFormCallback.BtnTitlesClick(Sender: TObject);
var
EWProc: EnumWindowsProc;
begin
ListBox1.Items.Clear;
EWProc := GetTitle;
EnumWindows (@EWProc, 0);
end;
end.
CBACKF.DFM
object FormCallback: TFormCallback
Left = 200
Top = 108
Width = 304
Height = 352
Caption = 'Callback Function Call'
Font.Charset = ANSI_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
PixelsPerInch = 96
TextHeight = 13
object ListBox1: TListBox
Left = 0
Top = 41
Width = 296
Height = 284
Align = alClient
ItemHeight = 13
TabOrder = 0
end
object Panel1: TPanel
Left = 0
Top = 0
Width = 296
Height = 41
Align = alTop
TabOrder = 1
object BtnTitles: TButton
Left = 72
Top = 8
Width = 153
Height = 25
Caption = 'Get Windows Titles'
TabOrder = 0
OnClick = BtnTitlesClick
end
end
end
Copyright Marco Cantù 1998