使用Styled SysColor在TEdit中选择文本

时间:2014-06-10 11:51:32

标签: delphi vcl delphi-xe3

我正在使用Delphi XE3来构建VCL应用程序。此VCL应用程序使用来自单元Vcl.Styles的构建方式进行样式设置。

我使用SysColor clHighlight的样式已被更改,但在TEdit(或TComboBoxTMemo)中选择了一段文字时,默认系统突出显示颜色(默认为蓝色)用于着色所选文本的背景。

注意:其他控件对样式中的选定项使用SysColor clHighlight

问题:如何在样式中指定此颜色?

1 个答案:

答案 0 :(得分:3)

这是WinApi的限制,这些控件使用的突出显示颜色无法直接修改。唯一的解决方法是使用GetSysColor函数挂钩并替换StyleServices.GetSystemColor方法。像这样

implementation

uses
  DDetours,
  WinApi.Windows,
  Vcl.Styles,
  Vcl.Themes;

var
  TrampolineGetSysColor:  function (nIndex: Integer): DWORD; stdcall;
  GetSysColorOrgPointer : Pointer = nil;

function InterceptGetSysColor(nIndex: Integer): DWORD; stdcall;
begin
  if StyleServices.IsSystemStyle then
   Result:= TrampolineGetSysColor(nIndex)
  else
   Result:= StyleServices.GetSystemColor(nIndex or Integer($FF000000));
end;

initialization
 if StyleServices.Available then
 begin
    GetSysColorOrgPointer := GetProcAddress(GetModuleHandle('user32.dll'), 'GetSysColor');
    @TrampolineGetSysColor := InterceptCreate(GetSysColorOrgPointer, @InterceptGetSysColor);
 end;
finalization
  if GetSysColorOrgPointer<>nil then
    InterceptRemove(@TrampolineGetSysColor);

end. 

enter image description here

enter image description here

顺便说一下,VCL Styles Utils项目包含一个带有此挂钩的单元。

相关问题