Emulating EnableVisualStyles()

  • Thread starter Thread starter Stephan Schaem
  • Start date Start date
S

Stephan Schaem

How does one write an unmanaged function that perform this functionality?

In short I want to turn off/on visual style in my app...

Thanks,

Stephan

PS: two people have been looking for some time, and no solution aside putting the manifest
in a file, and renaming the file before startup was found... very ugly hack ...
 
Hi Stephan,

Thanks for your post!

You can find a bundle of unmanaged API functions in UxTheme.dll:
Visual Styles Reference
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/pla
tform/commctls/userex/refentry.asp

Maybe the EnableTheming() and SetWindowTheme() functions are what you need.

Hope that helps!

Gary Chang
Microsoft Online Partner Support
Get Secure! – www.microsoft.com/security
This posting is provided "AS IS" with no warranties,and confers no rights.
--------------------
| From: "Stephan Schaem" <[email protected]>
| Subject: Emulating EnableVisualStyles()
| Date: Tue, 21 Oct 2003 19:57:31 -0700
| Lines: 54
| MIME-Version: 1.0
| Content-Type: multipart/alternative;
| boundary="----=_NextPart_000_00FC_01C3980D.904F51A0"
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <#[email protected]>
| Newsgroups:
microsoft.public.dotnet.framework,microsoft.public.dotnet.languages.vc
| NNTP-Posting-Host: adsl-64-167-237-174.dsl.scrm01.pacbell.net
64.167.237.174
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vc:29625
microsoft.public.dotnet.framework:56763
| X-Tomcat-NG: microsoft.public.dotnet.languages.vc
|
| How does one write an unmanaged function that perform this functionality?
| In short I want to turn off/on visual style in my app...
| Thanks,
| Stephan
| PS: two people have been looking for some time, and no solution aside
putting the manifest
| in a file, and renaming the file before startup was found... very ugly
hack ...
|
 
The function you outlined are global settings.
So far, their is no real elegant solution to turn on off the style on the fly
but Alex Feinman showed me this solution (See his post below) to allow this to be done at startup time.

In short it manually load the manifest using the "Activation Context Reference" API.

Stephan

To do this you use CreateActCtx function to create activation context prior to any window-creating activity. The activation context
will still require a manifest file, but whether to use it will be decided programmatically.

I've put together an MFC sample for you: http://www.alexfeinman.com/download.asp?doc=ThemedApp.zip

If you look inside InitInstance, you will find a call to ActivateContext function, which performs the actual work.

Naturally, due to the way theming is implemented, you will not be able to switch theming support on the fly; at least not without
recreating your windows.
If you activate context prior to displaying a dialog, the dialog will be created with theme support
 
Hi Stephan,

Thanks for sharing Alex's sample with us.

However it has no way to turn on/off the visual style on the runtime,
unless to redraw each control in the app manually to mimic the theme, but
that seems too complicated.

Regards

Gary Chang
Microsoft Online Partner Support
Get Secure! – www.microsoft.com/security
This posting is provided "AS IS" with no warranties,and confers no rights.
--------------------
| From: "Stephan Schaem" <[email protected]>
| References: <#[email protected]>
<[email protected]>
| Subject: Re: Emulating EnableVisualStyles()
| Date: Thu, 23 Oct 2003 01:13:06 -0700
| Lines: 72
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.languages.vc
| NNTP-Posting-Host: adsl-64-167-237-174.dsl.scrm01.pacbell.net
64.167.237.174
| Path:
cpmsftngxa06.phx.gbl!cpmsftngxa09.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.
phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vc:29672
| X-Tomcat-NG: microsoft.public.dotnet.languages.vc
|
| The function you outlined are global settings.
| So far, their is no real elegant solution to turn on off the style on the
fly
| but Alex Feinman showed me this solution (See his post below) to allow
this to be done at startup time.
|
| In short it manually load the manifest using the "Activation Context
Reference" API.
|
| Stephan
|
| To do this you use CreateActCtx function to create activation context
prior to any window-creating activity. The activation context
| will still require a manifest file, but whether to use it will be
decided programmatically.
|
| I've put together an MFC sample for you:
http://www.alexfeinman.com/download.asp?doc=ThemedApp.zip
|
| If you look inside InitInstance, you will find a call to ActivateContext
function, which performs the actual work.
|
| Naturally, due to the way theming is implemented, you will not be able to
switch theming support on the fly; at least not without
| recreating your windows.
| If you activate context prior to displaying a dialog, the dialog will be
created with theme support
|
|
| > Hi Stephan,
| >
| > Thanks for your post!
| >
| > You can find a bundle of unmanaged API functions in UxTheme.dll:
| > Visual Styles Reference
| >
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/pla
| > tform/commctls/userex/refentry.asp
| >
| > Maybe the EnableTheming() and SetWindowTheme() functions are what you
need.
| >
| > Hope that helps!
| >
| > Gary Chang
| > Microsoft Online Partner Support
| > Get Secure! - www.microsoft.com/security
| > This posting is provided "AS IS" with no warranties,and confers no
rights.
| > --------------------
| > | From: "Stephan Schaem" <[email protected]>
| > | Subject: Emulating EnableVisualStyles()
| > | Date: Tue, 21 Oct 2003 19:57:31 -0700
| > | Lines: 54
| > | MIME-Version: 1.0
| > | Content-Type: multipart/alternative;
| > | boundary="----=_NextPart_000_00FC_01C3980D.904F51A0"
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > | Message-ID: <#[email protected]>
| > | Newsgroups:
| > microsoft.public.dotnet.framework,microsoft.public.dotnet.languages.vc
| > | NNTP-Posting-Host: adsl-64-167-237-174.dsl.scrm01.pacbell.net
| > 64.167.237.174
| > | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
| > | Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vc:29625
| > microsoft.public.dotnet.framework:56763
| > | X-Tomcat-NG: microsoft.public.dotnet.languages.vc
| > |
| > | How does one write an unmanaged function that perform this
functionality?
| > | In short I want to turn off/on visual style in my app...
| > | Thanks,
| > | Stephan
| > | PS: two people have been looking for some time, and no solution aside
| > putting the manifest
| > | in a file, and renaming the file before startup was found... very ugly
| > hack ...
| > |
| >
|
|
|
 
Gary,

The problem with enabling styles at the runtime is that application with
visual styles enabled has its common controls serviced by a side-by-side
component. This can only be changed before child controls are created. For
the regular windows Theme service installs a hook that forces non-client
part of the window to repaint differently as well as affects the controls
painting. To the best of my knowledge this hook cannot be turned off on a
per-window basis.
 
I would like to document a problem with the current solution.
By using a string name for the manifest we couldn't get our icon in list control to show up
when the skinning was enabled.

What ever we did, the list box would always be blank in skinning mode.

Then we simply renamed the manifest from "AppName" to "2" and things started to work and

This might is really bizarre in my view... and who ever can see the windows source code
should check this behavior, because it make no sense to me and might hide other issues.

To recap:

We are successfully loading a manifest manually to control skinning at startup time, by
using a numeric name for the manifest file that we placed in the resource.

Stephan
 
Back
Top