delphi - 在 Delphi/Win32 中将图像放入组合框(右侧边缘)内

标签 delphi winapi combobox delphi-7

我想在 Delphi/Win32 中的组合框(右侧边缘)内绘制图像。

组合框的样式为csDropDown。这不适用于csOwnerDrawFixedcsOwnerDrawVariable

组合框应该是可编辑的,类似于浏览器的地址栏。

是否有无需创建额外的 Delphi 组件的 Win32 解决方案?

我尝试了以下方法,但不起作用。我可以用 Delphi 7 做到这一点吗?

TForm1 = class(TForm)
  ...
private
  FChDirComboWndProc: TWndMethod;
  procedure ChDirComboWndProc(var Message: TMessage);
  ...

procedure 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;

最佳答案

实现这一点的方法是实现一个所有者绘制的组合框。请参阅Owner-Drawn Combo Boxes在 MSDN 上,或查找 Delphi 示例,例如Owner Draw - ComboBox .

关于delphi - 在 Delphi/Win32 中将图像放入组合框(右侧边缘)内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7751812/

相关文章:

c# - 从 Combobox C# 选择默认项

delphi - 从 FireDac 存储过程检索输出参数

Delphi:混合两个音频流

delphi - 什么safearraygetdata函数将safearray作为Delphi中的输入参数而不是vararray

windows - 移植 - 共享内存 x32 和 x64 进程

c++ - WIN32 对话框上的自定义颜色形状

c++ - 字体更改后更新文本字段 (Win32)

delphi - 在 Delphi XE2 中使用 PayPal REST 客户端

apache-flex - flex 3 组合框选定的项目

jquery "select"标签或组合框上的上下滑动效果