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.