Einzelnen Beitrag anzeigen

Sergej_Molotov

Registriert seit: 18. Jul 2006
61 Beiträge
 
Delphi 11 Alexandria
 
#7

AW: TCombobox - Autoselect deaktivieren

  Alt 8. Mai 2014, 14:36
Bin auch gerade auf den Beitrag gestoßen und habe mal eine Klasse gemacht, die dieses mit einer ComboBox anstellt.
Ich poste die einfach mal, falls andere dieses auch benötigen:

Delphi-Quellcode:
unit U_ComboBoxHelper;

interface

uses
  StdCtrls,
  Messages;

type
  TComboBoxHelper = class(TOBject)
  private
    FComboBox: TCustomComboBox;
    FOriginalListProc: Pointer;
    FCustomListProc: Pointer;
    FListHandle: THandle;

    procedure RegisterCustomHandler;
    procedure CustomHandleComboBox(var Msg: TMessage);
  public
    constructor Create(const aComboBox: TCustomComboBox);
    destructor Destroy; override;
  end;

implementation

uses
  Classes,
  Windows;

{ TComboBoxHelper }

constructor TComboBoxHelper.Create(const aComboBox: TCustomComboBox);
begin
  inherited Create;
  FComboBox := aComboBox;
  FOriginalListProc := nil;
  FCustomListProc := nil;
  FListHandle := 0;
  RegisterCustomHandler;
end;

destructor TComboBoxHelper.Destroy;
begin
  if Assigned(FOriginalListProc) then
    SetWindowLongPtr(FListHandle, GWL_WNDPROC, LONG_PTR(FOriginalListProc));

  inherited;
end;

procedure TComboBoxHelper.RegisterCustomHandler;
var
  aCBI: tagCOMBOBOXINFO;
begin
  fillchar(aCBI, SizeOf(aCBI), 0);
  aCBI.cbSize := SizeOf(aCBI);

  if Windows.GetComboBoxInfo(FComboBox.Handle, aCBI) then
  begin
    FCustomListProc := MakeObjectInstance(CustomHandleComboBox);
    FListHandle := aCBI.hwndList;
    FOriginalListProc := Pointer(SetWindowLongPtr(FListHandle, GWL_WNDPROC, LONG_PTR(FCustomListProc)));
  end;
end;

procedure TComboBoxHelper.CustomHandleComboBox(var Msg: TMessage);
begin
  if (Msg.Msg = LB_FINDSTRING) then
    Msg.Msg := LB_FINDSTRINGEXACT;

  Msg.result := CallWindowProc(FOriginalListProc, FListHandle, Msg.Msg, Msg.wParam, Msg.lParam);
end;


end.
Thomas
  Mit Zitat antworten Zitat