procedure TForm1.FormCreate(Sender: TObject);
var
I : integer;
begin
List_Box_1:=TList_Box.Create(Self);
with List_Box_1 do
begin
Parent:=Form1;
Setbounds(16, 120, 160, 145);
OnDblClick:=List_Box_1DblClick;
for I:=1 to 100 do
AddItem(inttostr(I), nil);
end;
List_Box_2:=TList_Box.Create(Self);
with List_Box_2 do
begin
Parent:=Form1;
Setbounds(192, 120, 160, 145);
OnDblClick:=List_Box_2DblClick;
for I:=1 to 100 do
AddItem(inttostr(I), nil);
end;
end;
procedure TForm1.List_Box_1DblClick(Sender : TObject);
begin
showmessage('List_Box_1DblClick');
end;
procedure TForm1.List_Box_2DblClick(Sender : TObject);
begin
showmessage('List_Box_2DblClick');
end;
{ TList_Box }
constructor TList_Box.Create(AOwner: TComponent);
begin
inherited;
//
end;
destructor TList_Box.Destroy;
begin
inherited;
//
end;
var
Verrou : boolean;
procedure TList_Box.WndProc(var Message: TMessage);
var
Num_Index : Integer;
begin
if not Verrou then
try
Verrou:=true;
try
if Handle=Form1.List_Box_2.Handle then
begin
Num_Index:=SendMessage(Handle, LB_GETTOPINDEX, 0, 0);
SendMessage(Form1.List_Box_1.Handle, LB_SETTOPINDEX, Num_Index, 0);
if Form1.List_Box_1.ItemIndex<>ItemIndex then
Form1.List_Box_1.ItemIndex:=ItemIndex;
end
else
begin
Num_Index:=SendMessage(Handle, LB_GETTOPINDEX, 0, 0);
SendMessage(Form1.List_Box_2.Handle, LB_SETTOPINDEX, Num_Index, 0);
if Form1.List_Box_2.ItemIndex<>ItemIndex then
Form1.List_Box_2.ItemIndex:=ItemIndex;
end;
except
end;
finally
Verrou:=false;
end;
try
inherited WndProc(Message);
except
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
TChaine : array[0..255] of Char;
I : Cardinal;
Chaine_avec_zero_terminal : PChar;
P : ^PChar;
begin
try
// LB_INSERTSTRING
for I:=0 to length(Edit1.Text) do
TChaine[I]:=Copy(Edit1.Text, I, 1)[1];
Chaine_avec_zero_terminal:=TChaine;
P:=@Chaine_avec_zero_terminal[0];
// I:=P;
SendMessage(Form1.List_Box_1.Handle, LB_INSERTSTRING, -1, P);
except
end
end;