- unit Unit3;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
- System.Classes, Vcl.Graphics,
- Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
- type
- TForm3 = class(TForm)
- ComboBox1: TComboBox;
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- Form3: TForm3;
- implementation
- uses
- Vcl.Themes,
- Vcl.Styles;
- {$R *.dfm}
- type
- TComboBoxStyleHookFix = class(TComboBoxStyleHook)
- protected
- procedure DrawItem(Canvas: TCanvas; Index: Integer; const R: TRect;
- Selected: Boolean); override;
- end;
- procedure TComboBoxStyleHookFix.DrawItem(Canvas: TCanvas; Index: Integer;
- const R: TRect; Selected: Boolean);
- var
- DIS: TDrawItemStruct;
- Text: string;
- begin
- begin
- FillChar(DIS, SizeOf(DIS), 0);
- DIS.CtlType := ODT_COMBOBOX;
- DIS.CtlID := GetDlgCtrlID(Handle);
- DIS.itemAction := ODA_DRAWENTIRE;
- DIS.hDC := Canvas.Handle;
- DIS.hwndItem := Handle;
- DIS.rcItem := R;
- Text := TComboBox(Control).Items[Index];
- DIS.rcItem.Left := DIS.rcItem.Left +
- (DIS.rcItem.Width - Canvas.TextWidth(Text) - 5);
- DIS.itemID := Index;
- DIS.itemData := SendMessage(ListHandle, LB_GETITEMDATA, 0, 0);
- if Selected then
- DIS.itemState := DIS.itemState { or ODS_FOCUS } or ODS_SELECTED;
- SendMessage(Handle, WM_DRAWITEM, Handle, LPARAM(@DIS));
- end;
- end;
- initialization
- TStyleManager.Engine.RegisterStyleHook(TComboBox, TComboBoxStyleHookFix);
- end.