Registriert seit: 19. Jul 2005
43 Beiträge
|
Re: Caret in ComboBox
31. Aug 2005, 18:03
Delphi-Quellcode:
const
Hook: Hhook = 0;
var
pos: integer;
procedure TForm1.ComboBox1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
pos := Combobox1.selstart;
end;
function MouseProc(HookCode: Integer; WParam: WPARAM;
LParam: LPARAM): LRESULT; stdcall;
var pt: TPoint;
begin
if (HookCode = HC_ACTION) and (WParam = WM_LBUTTONUP) then begin
with Form1.Combobox1 do begin
pt := ScreenToClient(PMOUSEHOOKSTRUCT(LParam)^.pt);
if ptinrect(rect(0, 0, width, height), pt) then begin
pos := selstart;
result := 0;
exit;
end;
end;
end;
result := CallNextHookEx(Hook, HookCode, WParam, LParam);
end;
procedure HookInst;
begin
if Hook <> 0 then exit;
Hook := SetWindowsHookEx(WH_MOUSE, MouseProc,
HInstance, GetCurrentThreadId);
if Hook = 0 then
MessageBox(0, 'Der Hook wurde nicht installiert!',
'FEHLER', MB_ICONERROR);
end;
procedure HookUninst;
begin
if Hook <> 0 then UnhookWindowsHookEx(Hook);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
// ---- zum Testen ---------------
combobox1.items[0] := 'Zeile 1';
combobox1.items[1] := 'Zeile 2';
combobox1.items[2] := 'Zeile 3';
combobox1.items[3] := 'Zeile 4';
combobox1.items[4] := 'Zeile 5';
// ------------------------------
combobox1.itemindex := 0;
HookInst;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
HookUninst;
end;
procedure TForm1.Button1Click(Sender: TObject);
var s: string;
begin
s := Combobox1.text;
insert('###', s, pos);
Combobox1.text := s;
end;
Gruß DBR
|
|
Zitat
|