2014-06-10 29 views
2

我正在使用Delphi XE3構建VCL應用程序。這個VCL應用程序使用從單元Vcl.Styles生成的buildin進行樣式化。在TEdit中爲選定的文本使用樣式化的SysColor

在風格我使用SysColor clHighlight已被改變,但是當一段文字中選擇一個TEdit(或TComboBoxTMemo)的默認系統高亮顏色被使用(默認爲藍色)用於着色的背景所選文字。

注意:其他控件對樣式中的選定項使用SysColor clHighlight

問題:如何在樣式中指定此顏色?

回答

3

這是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

enter image description here

後者均基於VCL Styles Utils項目包括與此掛鉤的單位。

+0

將Vcl.Styles.Hooks添加到項目後,編輯控件看起來很棒。僅:在'DDetours'單元中,我需要添加'{$ Q-}'以避免啓動時出現'EIntOverflow'異常。 –

+0

您可以在項目頁面https://code.google.com/p/delphi-detours-library/上報告有關彎路庫的問題 – RRUZ

相關問題