【问题标题】:Putting an image inside an combobox (right-hand edge) in Delphi/Win32在 Delphi/Win32 中将图像放入组合框(右侧边缘)
【发布时间】:2011-10-13 09:09:50
【问题描述】:

我想在 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;

【问题讨论】:

    标签: delphi winapi combobox delphi-7


    【解决方案1】:

    实现它的方法是实现Owner-Drawn Combo Boxes。请参阅 MSDN 上的 Owner-Drawn Combo Boxes,或查找 Delphi 示例,例如Owner Draw - ComboBox.

    【讨论】:

    • 组合框的样式为 csDropDown。这不适用于 csOwnerDrawFixed 或 csOwnerDrawVariable。组合框应该是可编辑的,类似于浏览器的地址栏。我会将此信息添加到我的问题中,很抱歉忘记了这一点。
    猜你喜欢
    • 2023-04-02
    • 2015-03-26
    • 2021-06-02
    • 2014-05-19
    • 1970-01-01
    • 2023-03-25
    • 2017-12-13
    • 2020-04-23
    • 2014-10-18
    相关资源
    最近更新 更多