如何将 Delphi XE2 皮肤应用到 DLL 中的表单?
使用 Delphi XE2,您可以选择将自定义样式(皮肤)嵌入到 VCL 项目中。
一切正常。现在我将一些表单放入一个单独的 dll 中,并动态显示。
当然那些没有剥皮。我该如何纠正这个问题?
我想我必须以某种方式对 TVisualStyle 进行一些调用,但没有运气。
主机:
procedure TForm1.Button1Click(Sender: TObject);
var
l: THandle;
p: procedure (const h: THandle); stdcall;
begin
l:= LoadLibrary('project1.dll');
if l > 0 then
begin
@p:= GetProcAddress(l,'ShowIt');
p(Application.Handle);
FreeLibrary(l);
end;
end;
dll:
procedure ShowIt(const h: THandle);stdcall;
var
form: TForm;
b: TButton;
han: THandle;
begin
han:= Application.Handle;
Application.Handle:= h;
form :=Tform.Create(Application);
b:= TButton.Create(form);
b.Parent:= form;
b.Caption:= 'ytes';
b.Left:= 2;
b.Top:= 2;
form.ShowModal;
form.Release;
Application.Handle:= han;
end;
exports ShowIt ;
begin
end.
非常标准的东西。现在,要使 dll 窗体使用主机的样式主题,到底必须做什么呢?
Using Delphi XE2, you have the option to embed custom styles (skins) to a VCL project.
Everything works fine. Now I have some forms into a separated dll that I show dynamically.
Of course those are not skinned. How can I rectify that?
I guess I must do some call to TVisualStyle somehow, but no luck.
The host:
procedure TForm1.Button1Click(Sender: TObject);
var
l: THandle;
p: procedure (const h: THandle); stdcall;
begin
l:= LoadLibrary('project1.dll');
if l > 0 then
begin
@p:= GetProcAddress(l,'ShowIt');
p(Application.Handle);
FreeLibrary(l);
end;
end;
The dll:
procedure ShowIt(const h: THandle);stdcall;
var
form: TForm;
b: TButton;
han: THandle;
begin
han:= Application.Handle;
Application.Handle:= h;
form :=Tform.Create(Application);
b:= TButton.Create(form);
b.Parent:= form;
b.Caption:= 'ytes';
b.Left:= 2;
b.Top:= 2;
form.ShowModal;
form.Release;
Application.Handle:= han;
end;
exports ShowIt ;
begin
end.
Pretty standard stuff. Now, what exactly must be done to make the dll form use the host's style theme?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您有两个不同的 VCL 实例。您已在可执行文件拥有的
StyleServices
实例中设置样式,但你的 DLL 对此一无所知。您可以通过以下任一方法解决此问题:StyleServices
实例。You have two distinct instances of the VCL. You have set the style in the
StyleServices
instance owned by the executable, but your DLL has no knowledge of that. You could solve this by either:StyleServices
instance.我在这方面遇到了很多麻烦,这是因为我使用的是
themes
而不是VCL.THEMES
和VCL.STYLES
。Delphi 抛出一个
customeStyleException
说“找不到样式”或EcustomStyleException
“此样式不支持功能”I had a lot of trouble with this and it was because I was using
themes
rather thanVCL.THEMES
andVCL.STYLES
.Delphi was throwing up a
customeStyleException
saying "style not found" orEcustomStyleException
"Feature not supported by this style"