473,405 Members | 2,310 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Selectively enabling Visual Styles with SetWindowTheme

Hi,

I'm develing a COM add-in for Microsoft Word XP that displays a form. I'd
like to have the form display using the Windows XP theme. However, neither
using a manifest nor calling Application.EnableVisualStyles does the trick.
(EnableVisualStyles works but massive instability, probably because the
system is trying to theme the Word application itself.)

I'm now trying to selectively enable the themes for just my form, or just
certain elements on my form, by using the SetWindowTheme api. My
understanding is that SetWindowTheme doesn't need a manifest to work. (MSDN
isn't particularly clear.)

Herfried posted an article that discussed using this function with VB6:
http://www.activevb.de/tutorials/tut.../xpstyles.html

Here's a (poorly) translated version:
http://translate.google.com/translat...pstyles%2Ehtml
(You gotta love using the "Communist manifesto" in Visual Basic. <g>)

I created a test WinForms app that contains just a simple form with a
button. In the code below, I'm trying to theme the button. The function is
returning a 0 (success?) but still appears in the classic style. It happens
regardless of whether the button has "Standard" or "System" FlatStyle.

Any suggestions?

Thanks,
Robert Jacobson

Private Declare Function ActivateWindowTheme Lib "uxtheme" Alias
"SetWindowTheme" ( _
ByVal hWnd As IntPtr, _
Optional ByVal pszSubAppName As Integer = 0, _
Optional ByVal pszSubIdList As Integer = 0) _
As Integer

Private Declare Function DeactivateWindowTheme Lib "uxtheme" Alias
"SetWindowTheme" ( _
ByVal hWnd As IntPtr, _
Optional ByRef pszSubAppName As String = " ", _
Optional ByRef pszSubIdList As String = " ") _
As Integer

Private Declare Sub InitCommonControls Lib "comctl32" ()

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call
Call InitCommonControls()
Dim Result As Integer = ActivateWindowTheme(Button1.Handle)
Debug.WriteLine(Result)

End Sub
Nov 20 '05 #1
10 14319
: Private Declare Function ActivateWindowTheme Lib "uxtheme" Alias
: "SetWindowTheme" ( _
: ByVal hWnd As IntPtr, _
: Optional ByVal pszSubAppName As Integer = 0, _
: Optional ByVal pszSubIdList As Integer = 0) _
: As Integer

Untested:

You've omitted pszSubAppName and pszSubIdList, which will disable the theme.
Also, your declare is wrong. Try this:

(Change the integers, to strings)

ActivateWindowTheme(Button1.Handle, "BUTTON", "")

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

"Maybe it's a game called 'Punish the User'"
"Robert Jacobson" <rj**********************@nospam.com> wrote in message
news:#9*************@TK2MSFTNGP09.phx.gbl...
: Hi,
:
: I'm develing a COM add-in for Microsoft Word XP that displays a form. I'd
: like to have the form display using the Windows XP theme. However,
neither
: using a manifest nor calling Application.EnableVisualStyles does the
trick.
: (EnableVisualStyles works but massive instability, probably because the
: system is trying to theme the Word application itself.)
:
: I'm now trying to selectively enable the themes for just my form, or just
: certain elements on my form, by using the SetWindowTheme api. My
: understanding is that SetWindowTheme doesn't need a manifest to work.
(MSDN
: isn't particularly clear.)
:
: Herfried posted an article that discussed using this function with VB6:
: http://www.activevb.de/tutorials/tut.../xpstyles.html
:
: Here's a (poorly) translated version:
:
http://translate.google.com/translat...xt&hl=en&u=htt
p%3A%2F%2Fwww%2Eactivevb%2Ede%2Ftutorials%2Ftut%5F xpstyles%2Fxpstyles%2Ehtml
: (You gotta love using the "Communist manifesto" in Visual Basic. <g>)
:
: I created a test WinForms app that contains just a simple form with a
: button. In the code below, I'm trying to theme the button. The function
is
: returning a 0 (success?) but still appears in the classic style. It
happens
: regardless of whether the button has "Standard" or "System" FlatStyle.
:
: Any suggestions?
:
: Thanks,
: Robert Jacobson
:
:
:
: Private Declare Function ActivateWindowTheme Lib "uxtheme" Alias
: "SetWindowTheme" ( _
: ByVal hWnd As IntPtr, _
: Optional ByVal pszSubAppName As Integer = 0, _
: Optional ByVal pszSubIdList As Integer = 0) _
: As Integer
:
: Private Declare Function DeactivateWindowTheme Lib "uxtheme" Alias
: "SetWindowTheme" ( _
: ByVal hWnd As IntPtr, _
: Optional ByRef pszSubAppName As String = " ", _
: Optional ByRef pszSubIdList As String = " ") _
: As Integer
:
: Private Declare Sub InitCommonControls Lib "comctl32" ()
:
: #Region " Windows Form Designer generated code "
:
: Public Sub New()
: MyBase.New()
:
: 'This call is required by the Windows Form Designer.
: InitializeComponent()
:
: 'Add any initialization after the InitializeComponent() call
: Call InitCommonControls()
: Dim Result As Integer = ActivateWindowTheme(Button1.Handle)
: Debug.WriteLine(Result)
:
: End Sub
:
:
Nov 20 '05 #2
Thanks, Tom.

Revised code, with a more traditional declare for SetWindowTheme:

Private Declare Function SetWindowTheme Lib "uxtheme" ( _
ByVal hWnd As IntPtr, _
ByRef pszSubAppName As String, _
ByRef pszSubIdList As String) _
As Integer
....
Dim Result As Integer = SetWindowTheme(Button1.Handle, "BUTTON", "")

Unfortunately, it didn't work -- I'm still getting the classic style.

My first code was just a port of Herfried's code to VB.Net. I think he was
using zeroes for the last two properties as substitutes for a null string.
(Hard for me to know exactly -- the automated translation of the page was
really bad, and my German's even worse. <g>)

Any other thoughts?

--Robert
"Tom Spink" <th**********@ntlworld.com> wrote in message
news:u$**************@TK2MSFTNGP11.phx.gbl...
: Private Declare Function ActivateWindowTheme Lib "uxtheme" Alias
: "SetWindowTheme" ( _
: ByVal hWnd As IntPtr, _
: Optional ByVal pszSubAppName As Integer = 0, _
: Optional ByVal pszSubIdList As Integer = 0) _
: As Integer

Untested:

You've omitted pszSubAppName and pszSubIdList, which will disable the theme. Also, your declare is wrong. Try this:

(Change the integers, to strings)

ActivateWindowTheme(Button1.Handle, "BUTTON", "")

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

"Maybe it's a game called 'Punish the User'"
"Robert Jacobson" <rj**********************@nospam.com> wrote in message
news:#9*************@TK2MSFTNGP09.phx.gbl...
: Hi,
:
: I'm develing a COM add-in for Microsoft Word XP that displays a form. I'd : like to have the form display using the Windows XP theme. However,
neither
: using a manifest nor calling Application.EnableVisualStyles does the
trick.
: (EnableVisualStyles works but massive instability, probably because the
: system is trying to theme the Word application itself.)
:
: I'm now trying to selectively enable the themes for just my form, or just : certain elements on my form, by using the SetWindowTheme api. My
: understanding is that SetWindowTheme doesn't need a manifest to work.
(MSDN
: isn't particularly clear.)
:
: Herfried posted an article that discussed using this function with VB6:
: http://www.activevb.de/tutorials/tut.../xpstyles.html
:
: Here's a (poorly) translated version:
:
http://translate.google.com/translat...xt&hl=en&u=htt p%3A%2F%2Fwww%2Eactivevb%2Ede%2Ftutorials%2Ftut%5F xpstyles%2Fxpstyles%2Ehtml : (You gotta love using the "Communist manifesto" in Visual Basic. <g>)
:
: I created a test WinForms app that contains just a simple form with a
: button. In the code below, I'm trying to theme the button. The function is
: returning a 0 (success?) but still appears in the classic style. It
happens
: regardless of whether the button has "Standard" or "System" FlatStyle.
:
: Any suggestions?
:
: Thanks,
: Robert Jacobson
:
:
:
: Private Declare Function ActivateWindowTheme Lib "uxtheme" Alias
: "SetWindowTheme" ( _
: ByVal hWnd As IntPtr, _
: Optional ByVal pszSubAppName As Integer = 0, _
: Optional ByVal pszSubIdList As Integer = 0) _
: As Integer
:
: Private Declare Function DeactivateWindowTheme Lib "uxtheme" Alias
: "SetWindowTheme" ( _
: ByVal hWnd As IntPtr, _
: Optional ByRef pszSubAppName As String = " ", _
: Optional ByRef pszSubIdList As String = " ") _
: As Integer
:
: Private Declare Sub InitCommonControls Lib "comctl32" ()
:
: #Region " Windows Form Designer generated code "
:
: Public Sub New()
: MyBase.New()
:
: 'This call is required by the Windows Form Designer.
: InitializeComponent()
:
: 'Add any initialization after the InitializeComponent() call
: Call InitCommonControls()
: Dim Result As Integer = ActivateWindowTheme(Button1.Handle)
: Debug.WriteLine(Result)
:
: End Sub
:
:

Nov 20 '05 #3
Well Yes, It was silly of me to suggest it, because thinking about it, you
are going to need a manifest, no matter what, because your application needs
to reference Version 6 of common controls.

The reason SetWindowTheme doesn't work is because it's designed for setting
the theme, when Common Controls 6 are being used, and Herfried uses it to
disabled themes.

However, do not despair... I have written a control that owner-draw's a
button all the way, using uxtheme.dll.

http://download.betasafe.com/ActiveButton.zip
--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

"Maybe it's a game called 'Punish the User'"
"Robert Jacobson" <rj**********************@nospam.com> wrote in message
news:eP**************@tk2msftngp13.phx.gbl...
: Thanks, Tom.
:
: Revised code, with a more traditional declare for SetWindowTheme:
:
: Private Declare Function SetWindowTheme Lib "uxtheme" ( _
: ByVal hWnd As IntPtr, _
: ByRef pszSubAppName As String, _
: ByRef pszSubIdList As String) _
: As Integer
: ...
: Dim Result As Integer = SetWindowTheme(Button1.Handle, "BUTTON", "")
:
: Unfortunately, it didn't work -- I'm still getting the classic style.
:
: My first code was just a port of Herfried's code to VB.Net. I think he
was
: using zeroes for the last two properties as substitutes for a null string.
: (Hard for me to know exactly -- the automated translation of the page was
: really bad, and my German's even worse. <g>)
:
: Any other thoughts?
:
: --Robert
:
:
: "Tom Spink" <th**********@ntlworld.com> wrote in message
: news:u$**************@TK2MSFTNGP11.phx.gbl...
: > : Private Declare Function ActivateWindowTheme Lib "uxtheme" Alias
: > : "SetWindowTheme" ( _
: > : ByVal hWnd As IntPtr, _
: > : Optional ByVal pszSubAppName As Integer = 0, _
: > : Optional ByVal pszSubIdList As Integer = 0) _
: > : As Integer
: >
: > Untested:
: >
: > You've omitted pszSubAppName and pszSubIdList, which will disable the
: theme.
: > Also, your declare is wrong. Try this:
: >
: > (Change the integers, to strings)
: >
: > ActivateWindowTheme(Button1.Handle, "BUTTON", "")
: >
: > --
: > HTH,
: > -- Tom Spink, Über Geek
: >
: > Please respond to the newsgroup,
: > so all can benefit
: >
: > "Maybe it's a game called 'Punish the User'"
: >
: >
: > "Robert Jacobson" <rj**********************@nospam.com> wrote in message
: > news:#9*************@TK2MSFTNGP09.phx.gbl...
: > : Hi,
: > :
: > : I'm develing a COM add-in for Microsoft Word XP that displays a form.
: I'd
: > : like to have the form display using the Windows XP theme. However,
: > neither
: > : using a manifest nor calling Application.EnableVisualStyles does the
: > trick.
: > : (EnableVisualStyles works but massive instability, probably because
the
: > : system is trying to theme the Word application itself.)
: > :
: > : I'm now trying to selectively enable the themes for just my form, or
: just
: > : certain elements on my form, by using the SetWindowTheme api. My
: > : understanding is that SetWindowTheme doesn't need a manifest to work.
: > (MSDN
: > : isn't particularly clear.)
: > :
: > : Herfried posted an article that discussed using this function with
VB6:
: > : http://www.activevb.de/tutorials/tut.../xpstyles.html
: > :
: > : Here's a (poorly) translated version:
: > :
: >
:
http://translate.google.com/translat...xt&hl=en&u=htt
: >
:
p%3A%2F%2Fwww%2Eactivevb%2Ede%2Ftutorials%2Ftut%5F xpstyles%2Fxpstyles%2Ehtml
: > : (You gotta love using the "Communist manifesto" in Visual Basic. <g>)
: > :
: > : I created a test WinForms app that contains just a simple form with a
: > : button. In the code below, I'm trying to theme the button. The
: function
: > is
: > : returning a 0 (success?) but still appears in the classic style. It
: > happens
: > : regardless of whether the button has "Standard" or "System" FlatStyle.
: > :
: > : Any suggestions?
: > :
: > : Thanks,
: > : Robert Jacobson
: > :
: > :
: > :
: > : Private Declare Function ActivateWindowTheme Lib "uxtheme" Alias
: > : "SetWindowTheme" ( _
: > : ByVal hWnd As IntPtr, _
: > : Optional ByVal pszSubAppName As Integer = 0, _
: > : Optional ByVal pszSubIdList As Integer = 0) _
: > : As Integer
: > :
: > : Private Declare Function DeactivateWindowTheme Lib "uxtheme" Alias
: > : "SetWindowTheme" ( _
: > : ByVal hWnd As IntPtr, _
: > : Optional ByRef pszSubAppName As String = " ", _
: > : Optional ByRef pszSubIdList As String = " ") _
: > : As Integer
: > :
: > : Private Declare Sub InitCommonControls Lib "comctl32" ()
: > :
: > : #Region " Windows Form Designer generated code "
: > :
: > : Public Sub New()
: > : MyBase.New()
: > :
: > : 'This call is required by the Windows Form Designer.
: > : InitializeComponent()
: > :
: > : 'Add any initialization after the InitializeComponent() call
: > : Call InitCommonControls()
: > : Dim Result As Integer = ActivateWindowTheme(Button1.Handle)
: > : Debug.WriteLine(Result)
: > :
: > : End Sub
: > :
: > :
: >
: >
:
:
Nov 20 '05 #4
Robert,
Private Declare Function SetWindowTheme Lib "uxtheme" ( _
ByVal hWnd As IntPtr, _
ByRef pszSubAppName As String, _
ByRef pszSubIdList As String) _
As Integer


FWIW, the strings should be passed ByVal, and the declaration should
include the Unicode modifier keyword.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 20 '05 #5
Hello,

"Robert Jacobson" <rj**********************@nospam.com> schrieb:
Revised code, with a more traditional declare for SetWindowTheme:

Private Declare Function SetWindowTheme Lib "uxtheme" ( _
ByVal hWnd As IntPtr, _
ByRef pszSubAppName As String, _
ByRef pszSubIdList As String) _
As Integer


I would use this declare (untested):

\\\
Private Declare Unicode Function SetWindowTheme Lib "uxtheme.dll" ( _
ByVal hWnd As IntPtr, _
ByVal pszSubAppName As String, _
ByVal pszSubIdList As String _
) As Int32
///

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #6
Very impressive work with the buttons! I see your uxtheme declares in the
Themes module, but it looks like you're handling most of the drawing
yourself. (Unfortunately, although the Buttons are great, I also have a
progess bar and status bar to theme. My app would probably look goofy with
a half-themed appearance.)

Bad news about SetWindowTheme though. I've seen several examples of using a
manifest to enable XP themes and then manually disable themes from
individual controls with SetWindowTheme. (Which won't work for me.) I had
thought that calling InitCommonControls would bypass the need for a
manifest, and then let me selectively turn the visual styles on. Do you
know of any other way to reference version 6, without using
Application.EnableVisualStyles or a manifest?

My only other hope is a real kludge -- first call
Application.EnableVisualStyles (to get the Version 6 reference), then call
SetThemeAppProperties to disable visual styles application-wide (so Word
won't crash), and finally use SetWindowTheme to reenable visual styles for
just my form. That will be my next step, unless you have any other
thoughts.

Thanks again!

--Robert


"Tom Spink" <th**********@ntlworld.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Well Yes, It was silly of me to suggest it, because thinking about it, you
are going to need a manifest, no matter what, because your application needs to reference Version 6 of common controls.

The reason SetWindowTheme doesn't work is because it's designed for setting the theme, when Common Controls 6 are being used, and Herfried uses it to
disabled themes.

However, do not despair... I have written a control that owner-draw's a
button all the way, using uxtheme.dll.

http://download.betasafe.com/ActiveButton.zip
--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

"Maybe it's a game called 'Punish the User'"
"Robert Jacobson" <rj**********************@nospam.com> wrote in message
news:eP**************@tk2msftngp13.phx.gbl...
: Thanks, Tom.
:
: Revised code, with a more traditional declare for SetWindowTheme:
:
: Private Declare Function SetWindowTheme Lib "uxtheme" ( _
: ByVal hWnd As IntPtr, _
: ByRef pszSubAppName As String, _
: ByRef pszSubIdList As String) _
: As Integer
: ...
: Dim Result As Integer = SetWindowTheme(Button1.Handle, "BUTTON", "")
:
: Unfortunately, it didn't work -- I'm still getting the classic style.
:
: My first code was just a port of Herfried's code to VB.Net. I think he
was
: using zeroes for the last two properties as substitutes for a null string. : (Hard for me to know exactly -- the automated translation of the page was : really bad, and my German's even worse. <g>)
:
: Any other thoughts?
:
: --Robert
:
:
: "Tom Spink" <th**********@ntlworld.com> wrote in message
: news:u$**************@TK2MSFTNGP11.phx.gbl...
: > : Private Declare Function ActivateWindowTheme Lib "uxtheme" Alias
: > : "SetWindowTheme" ( _
: > : ByVal hWnd As IntPtr, _
: > : Optional ByVal pszSubAppName As Integer = 0, _
: > : Optional ByVal pszSubIdList As Integer = 0) _
: > : As Integer
: >
: > Untested:
: >
: > You've omitted pszSubAppName and pszSubIdList, which will disable the
: theme.
: > Also, your declare is wrong. Try this:
: >
: > (Change the integers, to strings)
: >
: > ActivateWindowTheme(Button1.Handle, "BUTTON", "")
: >
: > --
: > HTH,
: > -- Tom Spink, Über Geek
: >
: > Please respond to the newsgroup,
: > so all can benefit
: >
: > "Maybe it's a game called 'Punish the User'"
: >
: >
: > "Robert Jacobson" <rj**********************@nospam.com> wrote in message : > news:#9*************@TK2MSFTNGP09.phx.gbl...
: > : Hi,
: > :
: > : I'm develing a COM add-in for Microsoft Word XP that displays a form. : I'd
: > : like to have the form display using the Windows XP theme. However,
: > neither
: > : using a manifest nor calling Application.EnableVisualStyles does the
: > trick.
: > : (EnableVisualStyles works but massive instability, probably because
the
: > : system is trying to theme the Word application itself.)
: > :
: > : I'm now trying to selectively enable the themes for just my form, or
: just
: > : certain elements on my form, by using the SetWindowTheme api. My
: > : understanding is that SetWindowTheme doesn't need a manifest to work. : > (MSDN
: > : isn't particularly clear.)
: > :
: > : Herfried posted an article that discussed using this function with
VB6:
: > : http://www.activevb.de/tutorials/tut.../xpstyles.html
: > :
: > : Here's a (poorly) translated version:
: > :
: >
:
http://translate.google.com/translat...xt&hl=en&u=htt : >
:
p%3A%2F%2Fwww%2Eactivevb%2Ede%2Ftutorials%2Ftut%5F xpstyles%2Fxpstyles%2Ehtml : > : (You gotta love using the "Communist manifesto" in Visual Basic. <g>) : > :
: > : I created a test WinForms app that contains just a simple form with a : > : button. In the code below, I'm trying to theme the button. The
: function
: > is
: > : returning a 0 (success?) but still appears in the classic style. It
: > happens
: > : regardless of whether the button has "Standard" or "System" FlatStyle. : > :
: > : Any suggestions?
: > :
: > : Thanks,
: > : Robert Jacobson
: > :
: > :
: > :
: > : Private Declare Function ActivateWindowTheme Lib "uxtheme" Alias
: > : "SetWindowTheme" ( _
: > : ByVal hWnd As IntPtr, _
: > : Optional ByVal pszSubAppName As Integer = 0, _
: > : Optional ByVal pszSubIdList As Integer = 0) _
: > : As Integer
: > :
: > : Private Declare Function DeactivateWindowTheme Lib "uxtheme" Alias
: > : "SetWindowTheme" ( _
: > : ByVal hWnd As IntPtr, _
: > : Optional ByRef pszSubAppName As String = " ", _
: > : Optional ByRef pszSubIdList As String = " ") _
: > : As Integer
: > :
: > : Private Declare Sub InitCommonControls Lib "comctl32" ()
: > :
: > : #Region " Windows Form Designer generated code "
: > :
: > : Public Sub New()
: > : MyBase.New()
: > :
: > : 'This call is required by the Windows Form Designer.
: > : InitializeComponent()
: > :
: > : 'Add any initialization after the InitializeComponent() call
: > : Call InitCommonControls()
: > : Dim Result As Integer = ActivateWindowTheme(Button1.Handle)
: > : Debug.WriteLine(Result)
: > :
: > : End Sub
: > :
: > :
: >
: >
:
:

Nov 20 '05 #7
Thanks, Mattias. I changed my declaration but it didn't help. I think the
problems are more fundanmental.
"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:ux**************@TK2MSFTNGP11.phx.gbl...
Robert,
Private Declare Function SetWindowTheme Lib "uxtheme" ( _
ByVal hWnd As IntPtr, _
ByRef pszSubAppName As String, _
ByRef pszSubIdList As String) _
As Integer


FWIW, the strings should be passed ByVal, and the declaration should
include the Unicode modifier keyword.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.

Nov 20 '05 #8
Thanks, but unfortunately, it doesn't help. It sounds like it won't work
without a manifest or Application.EnableVisualStyles. Please let me know if
I'm wrong.
"Herfried K. Wagner [MVP]" <hi*******@m.activevb.de> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hello,

"Robert Jacobson" <rj**********************@nospam.com> schrieb:
Revised code, with a more traditional declare for SetWindowTheme:

Private Declare Function SetWindowTheme Lib "uxtheme" ( _
ByVal hWnd As IntPtr, _
ByRef pszSubAppName As String, _
ByRef pszSubIdList As String) _
As Integer


I would use this declare (untested):

\\\
Private Declare Unicode Function SetWindowTheme Lib "uxtheme.dll" ( _
ByVal hWnd As IntPtr, _
ByVal pszSubAppName As String, _
ByVal pszSubIdList As String _
) As Int32
///

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet

Nov 20 '05 #9
Hello,

"Robert Jacobson" <rj**********************@nospam.com> schrieb:
Thanks, but unfortunately, it doesn't help. It sounds like
it won't work without a manifest or Application.EnableVisualStyles.
Please let me know if I'm wrong.


You will still need an application manifest.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #10
I looked at the IL for Application.EnableVisualStyles, and all it does is
enable a shared boolean in the application object....

I have no idea how this enables visual styles.

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

"Chaos, Panic, Disorder, my work here is done"
"Robert Jacobson" <rj**********************@nospam.com> wrote in message
news:u9**************@tk2msftngp13.phx.gbl...
: Very impressive work with the buttons! I see your uxtheme declares in the
: Themes module, but it looks like you're handling most of the drawing
: yourself. (Unfortunately, although the Buttons are great, I also have a
: progess bar and status bar to theme. My app would probably look goofy
with
: a half-themed appearance.)
:
: Bad news about SetWindowTheme though. I've seen several examples of using
a
: manifest to enable XP themes and then manually disable themes from
: individual controls with SetWindowTheme. (Which won't work for me.) I
had
: thought that calling InitCommonControls would bypass the need for a
: manifest, and then let me selectively turn the visual styles on. Do you
: know of any other way to reference version 6, without using
: Application.EnableVisualStyles or a manifest?
:
: My only other hope is a real kludge -- first call
: Application.EnableVisualStyles (to get the Version 6 reference), then call
: SetThemeAppProperties to disable visual styles application-wide (so Word
: won't crash), and finally use SetWindowTheme to reenable visual styles for
: just my form. That will be my next step, unless you have any other
: thoughts.
:
: Thanks again!
:
: --Robert
:
:
:
:
:
:
: "Tom Spink" <th**********@ntlworld.com> wrote in message
: news:%2****************@TK2MSFTNGP09.phx.gbl...
: > Well Yes, It was silly of me to suggest it, because thinking about it,
you
: > are going to need a manifest, no matter what, because your application
: needs
: > to reference Version 6 of common controls.
: >
: > The reason SetWindowTheme doesn't work is because it's designed for
: setting
: > the theme, when Common Controls 6 are being used, and Herfried uses it
to
: > disabled themes.
: >
: > However, do not despair... I have written a control that owner-draw's a
: > button all the way, using uxtheme.dll.
: >
: > http://download.betasafe.com/ActiveButton.zip
: >
: >
: > --
: > HTH,
: > -- Tom Spink, Über Geek
: >
: > Please respond to the newsgroup,
: > so all can benefit
: >
: > "Maybe it's a game called 'Punish the User'"
: >
: >
: > "Robert Jacobson" <rj**********************@nospam.com> wrote in message
: > news:eP**************@tk2msftngp13.phx.gbl...
: > : Thanks, Tom.
: > :
: > : Revised code, with a more traditional declare for SetWindowTheme:
: > :
: > : Private Declare Function SetWindowTheme Lib "uxtheme" ( _
: > : ByVal hWnd As IntPtr, _
: > : ByRef pszSubAppName As String, _
: > : ByRef pszSubIdList As String) _
: > : As Integer
: > : ...
: > : Dim Result As Integer = SetWindowTheme(Button1.Handle, "BUTTON", "")
: > :
: > : Unfortunately, it didn't work -- I'm still getting the classic style.
: > :
: > : My first code was just a port of Herfried's code to VB.Net. I think
he
: > was
: > : using zeroes for the last two properties as substitutes for a null
: string.
: > : (Hard for me to know exactly -- the automated translation of the page
: was
: > : really bad, and my German's even worse. <g>)
: > :
: > : Any other thoughts?
: > :
: > : --Robert
: > :
: > :
: > : "Tom Spink" <th**********@ntlworld.com> wrote in message
: > : news:u$**************@TK2MSFTNGP11.phx.gbl...
: > : > : Private Declare Function ActivateWindowTheme Lib "uxtheme" Alias
: > : > : "SetWindowTheme" ( _
: > : > : ByVal hWnd As IntPtr, _
: > : > : Optional ByVal pszSubAppName As Integer = 0, _
: > : > : Optional ByVal pszSubIdList As Integer = 0) _
: > : > : As Integer
: > : >
: > : > Untested:
: > : >
: > : > You've omitted pszSubAppName and pszSubIdList, which will disable
the
: > : theme.
: > : > Also, your declare is wrong. Try this:
: > : >
: > : > (Change the integers, to strings)
: > : >
: > : > ActivateWindowTheme(Button1.Handle, "BUTTON", "")
: > : >
: > : > --
: > : > HTH,
: > : > -- Tom Spink, Über Geek
: > : >
: > : > Please respond to the newsgroup,
: > : > so all can benefit
: > : >
: > : > "Maybe it's a game called 'Punish the User'"
: > : >
: > : >
: > : > "Robert Jacobson" <rj**********************@nospam.com> wrote in
: message
: > : > news:#9*************@TK2MSFTNGP09.phx.gbl...
: > : > : Hi,
: > : > :
: > : > : I'm develing a COM add-in for Microsoft Word XP that displays a
: form.
: > : I'd
: > : > : like to have the form display using the Windows XP theme.
However,
: > : > neither
: > : > : using a manifest nor calling Application.EnableVisualStyles does
the
: > : > trick.
: > : > : (EnableVisualStyles works but massive instability, probably
because
: > the
: > : > : system is trying to theme the Word application itself.)
: > : > :
: > : > : I'm now trying to selectively enable the themes for just my form,
or
: > : just
: > : > : certain elements on my form, by using the SetWindowTheme api. My
: > : > : understanding is that SetWindowTheme doesn't need a manifest to
: work.
: > : > (MSDN
: > : > : isn't particularly clear.)
: > : > :
: > : > : Herfried posted an article that discussed using this function with
: > VB6:
: > : > : http://www.activevb.de/tutorials/tut.../xpstyles.html
: > : > :
: > : > : Here's a (poorly) translated version:
: > : > :
: > : >
: > :
: >
:
http://translate.google.com/translat...xt&hl=en&u=htt
: > : >
: > :
: >
:
p%3A%2F%2Fwww%2Eactivevb%2Ede%2Ftutorials%2Ftut%5F xpstyles%2Fxpstyles%2Ehtml
: > : > : (You gotta love using the "Communist manifesto" in Visual Basic.
: <g>)
: > : > :
: > : > : I created a test WinForms app that contains just a simple form
with
: a
: > : > : button. In the code below, I'm trying to theme the button. The
: > : function
: > : > is
: > : > : returning a 0 (success?) but still appears in the classic style.
It
: > : > happens
: > : > : regardless of whether the button has "Standard" or "System"
: FlatStyle.
: > : > :
: > : > : Any suggestions?
: > : > :
: > : > : Thanks,
: > : > : Robert Jacobson
: > : > :
: > : > :
: > : > :
: > : > : Private Declare Function ActivateWindowTheme Lib "uxtheme" Alias
: > : > : "SetWindowTheme" ( _
: > : > : ByVal hWnd As IntPtr, _
: > : > : Optional ByVal pszSubAppName As Integer = 0, _
: > : > : Optional ByVal pszSubIdList As Integer = 0) _
: > : > : As Integer
: > : > :
: > : > : Private Declare Function DeactivateWindowTheme Lib "uxtheme"
Alias
: > : > : "SetWindowTheme" ( _
: > : > : ByVal hWnd As IntPtr, _
: > : > : Optional ByRef pszSubAppName As String = " ", _
: > : > : Optional ByRef pszSubIdList As String = " ") _
: > : > : As Integer
: > : > :
: > : > : Private Declare Sub InitCommonControls Lib "comctl32" ()
: > : > :
: > : > : #Region " Windows Form Designer generated code "
: > : > :
: > : > : Public Sub New()
: > : > : MyBase.New()
: > : > :
: > : > : 'This call is required by the Windows Form Designer.
: > : > : InitializeComponent()
: > : > :
: > : > : 'Add any initialization after the InitializeComponent() call
: > : > : Call InitCommonControls()
: > : > : Dim Result As Integer = ActivateWindowTheme(Button1.Handle)
: > : > : Debug.WriteLine(Result)
: > : > :
: > : > : End Sub
: > : > :
: > : > :
: > : >
: > : >
: > :
: > :
: >
: >
:
:
Nov 20 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: ht990332 | last post by:
I'm writing applications in vc++ .net 2003. How do I give the applications visual styles on winxp without adding a ..manifest file?
0
by: Anand | last post by:
Hi, I have done a sample windows application with controls looks resembling to Windows XP Visual Styles by using the guidelines http://msdn.microsoft.com/library/default.asp? url=/library/en-...
2
by: Alvo von Cossel I | last post by:
hi, i have an app with a lot of stuff including an optios form. 1 of the options is disabling the xp visual styles. i know how to enable them but not how to disable them. has anyone got an...
3
by: Brian Henry | last post by:
here's something odd, maybe someone can explain it, when i turn on application.enablevisualstyles at application start before i do my application.run(context) command in the sub main, when the app...
5
by: MLM450 | last post by:
I want to use visual styles in my app, but it is causing a problem with a DLL I use. Is there a way to disable visual styles for that DLL? I do not have access to the code for the DLL. The DLL's...
1
by: sklett | last post by:
Hi, I'm not SURE if Visual Styles is what I'm delaing with, but there is my situation. On computer A which I have chosen "Classic Windows" as my "Theme" my application appears the way I want it...
3
by: nkarnold | last post by:
My application seems to be ignoring Enable XP visual styles, which is ticked on in the application properties. the Toolbar and Menubar, which appear the nice looking shaded blue appear like that...
2
by: Flash | last post by:
Hello, recently I was looking through the system properties and came accross system.visualstyles namespace. This appears to contain all of the visual style elements in xp and I was wondering if it...
1
by: =?Utf-8?B?UmljaA==?= | last post by:
On my old workstation (development workstation) if I set Application/Enable XP visual styles - I was able to get/see the visual styles - like button borders highlighting when you run the mouse over...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.