1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
Tessai = class(TForm)
ListBox1: TListBox;
Button1: TButton;
Edit1: TEdit;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
winHandle: HWND;
winTitle : string;
end;
var
essai: Tessai;
implementation
{$R *.dfm}
var
s: String;
function EnumChildren(hwnd: HWND; lParam: LPARAM): BOOL; stdcall;
var
ClassName: array[0..259] of Char;
begin
Result := True;
GetClassName(hwnd, ClassName, Length(ClassName));
essai.ListBox1.Items.Add(IntToHex(hwnd,8) + ' ' + ClassName);
end;
procedure Tessai.Button1Click(Sender: TObject);
begin
ListBox1.Items.Clear;
// ---------------------------------
// 1. try to find main window hwnd:
// ---------------------------------
winHandle := FindWindow(nil,pchar('fenetre1'));
if winHandle =0 then begin
ListBox1.Items.Add('Error: 1.'); exit; end else
ListBox1.Items.Add('win: 0x' + IntToHex(winHandle,8));
// ---------------------------------
// 2. try to find window title:
// ---------------------------------
SetLength(winTitle, GetWindowTextLength(winHandle));
GetWindowText(winHandle, PChar(winTitle), Length(winTitle)+1);
if Length(Trim(winTitle)) < 2 then begin
ListBox1.Items.Add('Error: 2.'); exit; end else
ListBox1.Items.Add('title: ' + winTitle);
// ---------------------------------
// 3. cross check: try to get class:
// ---------------------------------
SetLength(s, 100);
GetClassName(winHandle, PChar(s), Length(s)+1);
if Length(Trim(s)) < 2 then begin
ListBox1.Items.Add('Error: 3.'); exit; end else
ListBox1.Items.Add('class: ' + s);
EnumChildWindows(winHandle, @EnumChildren, 0);
end;
procedure Tessai.Button2Click(Sender: TObject);
var
hand:thandle;
lpstring:pchar;
begin
hand:=strtoint('$'+essai.Edit1.Text);;
lpstring:=pchar(edit1.Text);
{sendmessage(hand,WM_SETTEXT,0,longint(lpstring));
{ sendmessage(hand,BM_CLICK,0,0);
sendmessage(hand,BN_DISABLE,0,0)
}
{PostMessage(hand, WM_COMMAND, MAKEWPARAM(GetDlgCtrlID(Button1.Handle), BN_CLICKED),hand); }
enablewindow(hand,false);
end;
procedure Tessai.Button3Click(Sender: TObject);
var
hand:thandle;
lpstring:pchar;
begin
hand:=strtoint('$'+essai.Edit1.Text);;
enablewindow(hand,true);
end;
end. |
Partager