這是WinApi的限制,這些控件使用的高亮顏色不能直接修改。唯一的解決方法是掛鉤,並用StyleServices.GetSystemColor函數取代GetSysColor
方法。像這樣
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](https://i.stack.imgur.com/IoDvw.png)
![enter image description here](https://i.stack.imgur.com/bZykf.png)
後者均基於VCL Styles Utils
項目包括與此掛鉤的單位。
將Vcl.Styles.Hooks添加到項目後,編輯控件看起來很棒。僅:在'DDetours'單元中,我需要添加'{$ Q-}'以避免啓動時出現'EIntOverflow'異常。 –
您可以在項目頁面https://code.google.com/p/delphi-detours-library/上報告有關彎路庫的問題 – RRUZ