I want draw a an image inside an combobox (right-hand edge) in Delphi/Win32.
The combobox has the style csDropDown. This doesn't work with csOwnerDrawFixed or csOwnerDrawVariable.
The combobox should be editable similar to the address bar of the browser.
Is there a Win32 solution without creating an additional Delphi component?
I tried the following, but it doesn't work. Can I do that with Delphi 7?
TForm1 = class(TForm)
...
private
FChDirComboWndProc: TWndMethod;
procedure ChDirComboWndProc(var Message: TMessage);
...
procedu开发者_StackOverflow中文版re TForm1.FormCreate(Sender: TObject);
begin
FChDirComboWndProc := ChDirComboBox.WindowProc; // save old window proc
ChDirComboBox.WindowProc := ChDirComboWndProc; // subclass
end;
procedure TForm1.ChDirComboWndProc(var Message: TMessage);
begin
WM_ERASEBKGND: begin // WM_PAINT ?
SetBkMode(Message.WParam, TRANSPARENT);
SetTextColor(Message.wParam, GetSysColor(COLOR_GRAYTEXT));
FillRect(Message.wParam, Rect(3,3,300,30), GetStockObject(BLACK_BRUSH ));
Rectangle(Message.wParam, 15,15, 100, 100); //Test
OutputDebugString(PCHar(Format('aa %d %d %d',[Message.WParam, Message.LParam, ChDirComboBox.Handle])));
end;
end;
FChDirComboWndProc(Message); // process message
end;
The way to do it is to implement an Owner-Drawn Combo Boxes
. See Owner-Drawn Combo Boxes on MSDN, or look for Delphi sample, e.g. Owner Draw - ComboBox.
精彩评论