여기에서 link에 대해 알아야 할 사항이 설명되어 있습니다.
기본적으로 이미 알고있는 "null 후크"를 넣거나 누락 된 부분의 절반 인 "VCL 색상"후크를 넣어야합니다. 나머지 절반은 포인터없는 문제입니다.
이 (당신처럼)은 TEdit 유도체를 만들기 위해 VCL 표준 색상처럼 당신이 당신의 컨트롤을 사용하여 작업 할 수 있도록하는 데 필요한 코드를 보는 것은 이것이다 :
uses
Winapi.Messages,
Vcl.Controls,
Vcl.StdCtrls,
Vcl.Forms,
Vcl.Themes,
Vcl.Styles;
type
TEditStyleHookColor = class(TEditStyleHook)
private
procedure UpdateColors;
protected
procedure WndProc(var Message: TMessage); override;
constructor Create(AControl: TWinControl); override;
end;
implementation
type
TWinControlH= class(TWinControl);
constructor TEditStyleHookColor.Create(AControl: TWinControl);
begin
inherited;
//call the UpdateColors method to use the custom colors
UpdateColors;
end;
//Here you set the colors of the style hook
procedure TEditStyleHookColor.UpdateColors;
var
LStyle: TCustomStyleServices;
begin
if Control.Enabled then
begin
Brush.Color := TWinControlH(Control).Color; //use the Control color
FontColor := TWinControlH(Control).Font.Color;//use the Control font color
end
else
begin
//if the control is disabled use the colors of the style
LStyle := StyleServices;
Brush.Color := LStyle.GetStyleColor(scEditDisabled);
FontColor := LStyle.GetStyleFontColor(sfEditBoxTextDisabled);
end;
end;
//Handle the messages of the control
procedure TEditStyleHookColor.WndProc(var Message: TMessage);
begin
case Message.Msg of
CN_CTLCOLORMSGBOX..CN_CTLCOLORSTATIC:
begin
//Get the colors
UpdateColors;
SetTextColor(Message.WParam, ColorToRGB(FontColor));
SetBkColor(Message.WParam, ColorToRGB(Brush.Color));
Message.Result := LRESULT(Brush.Handle);
Handled := True;
end;
CM_ENABLEDCHANGED:
begin
//Get the colors
UpdateColors;
Handled := False;
end
else
inherited WndProc(Message);
end;
end;
Procedure ApplyVCLColorsStyleHook(ControlClass :TClass);
begin
if Assigned(TStyleManager.Engine) then
TStyleManager.Engine.RegisterStyleHook(ControlClass, TEditStyleHookColor);
end;
initialization
ApplyVCLColorsStyleHook(TwwDBComboDlg);
NIL에 귀하의 문제는 당신이없는 경우에 그 VCL 테마가 켜져 있으면 Engine은 nil이므로 호출중인 함수를 호출하지 않고 해당 코드를 확인하고 반환해야합니다. 당신이 테마를 켤 경우 여기에 당신이 그것을 놓친 경우이다 :
흥미로운 측면 물건 : the VCL Styles utils 라이브러리를 가져옵니다.
TCustomStyleExt(TStyleManager.ActiveStyle).SetStyleColor(scEdit, clWindow);
TCustomStyleExt(TStyleManager.ActiveStyle).SetStyleFontColor(sfEditBoxTextNormal
,clWindowText);
당신은 스타일을 만들고, 특정 컨트롤에 그 스타일을 적용, 심지어 테마 엔진을 확장 할 수 있습니다, VCL 스타일의 Utils 도구를 사용 할 수 있습니다 여기 물건의 색상을 변경하는 데 사용의 예 원하는 결과를 얻지 만 사소한 것은 아닙니다.
예외는 무엇입니까? – RRUZ
위의 호출에 대한 액세스 위반입니다. 그것의 구성 요소를 비활성화하려고 양식의 초기화 부분에. – mike
TStyleManager.Engine.RegisterStyleHook을 시도해보십시오 (ClrMeans.TwwDBComboDLG, TStyleHook); – RRUZ