在 Delphi/Win32 中将图像放入组合框(右侧边缘)内
我想在 Delphi/Win32 中的组合框(右侧边缘)内绘制图像。
该组合框的样式为 csDropDown。这不适用于csOwnerDrawFixed或csOwnerDrawVariable。
组合框应该是可编辑的,类似于浏览器的地址栏。
是否有无需创建额外的 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;
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);
...
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;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实现方法是实现一个
Owner-Drawn Combo Boxes
。请参阅所有者绘制组合MSDN 上的框,或者查找 Delphi 示例,例如 所有者抽奖 - 组合框。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.