Selectively enabling Visual Styles with SetWindowTheme

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Robert Jacobson

    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.Ena bleVisualStyles does the trick.
    (EnableVisualSt yles 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:
    Wie man die WindowsXP-Styles, einen erweiterten grafischen Darstellungsmodus, für seine Anwendungen einsetzt.


    Here's a (poorly) translated version:

    (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 ActivateWindowT heme 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 DeactivateWindo wTheme Lib "uxtheme" Alias
    "SetWindowTheme " ( _
    ByVal hWnd As IntPtr, _
    Optional ByRef pszSubAppName As String = " ", _
    Optional ByRef pszSubIdList As String = " ") _
    As Integer

    Private Declare Sub InitCommonContr ols Lib "comctl32" ()

    #Region " Windows Form Designer generated code "

    Public Sub New()
    MyBase.New()

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

    'Add any initialization after the InitializeCompo nent() call
    Call InitCommonContr ols()
    Dim Result As Integer = ActivateWindowT heme(Button1.Ha ndle)
    Debug.WriteLine (Result)

    End Sub


  • Tom Spink

    #2
    Re: Selectively enabling Visual Styles with SetWindowTheme

    : Private Declare Function ActivateWindowT heme 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)

    ActivateWindowT heme(Button1.Ha ndle, "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" <rjacobson_at_o ddpost_com@nosp am.com> wrote in message
    news:#9G7MUifDH A.696@TK2MSFTNG P09.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.Ena bleVisualStyles does the
    trick.
    : (EnableVisualSt yles 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:
    :

    p%3A%2F%2Fwww%2 Eactivevb%2Ede% 2Ftutorials%2Ft ut%5Fxpstyles%2 Fxpstyles%2Ehtm l
    : (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 ActivateWindowT heme 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 DeactivateWindo wTheme Lib "uxtheme" Alias
    : "SetWindowTheme " ( _
    : ByVal hWnd As IntPtr, _
    : Optional ByRef pszSubAppName As String = " ", _
    : Optional ByRef pszSubIdList As String = " ") _
    : As Integer
    :
    : Private Declare Sub InitCommonContr ols Lib "comctl32" ()
    :
    : #Region " Windows Form Designer generated code "
    :
    : Public Sub New()
    : MyBase.New()
    :
    : 'This call is required by the Windows Form Designer.
    : InitializeCompo nent()
    :
    : 'Add any initialization after the InitializeCompo nent() call
    : Call InitCommonContr ols()
    : Dim Result As Integer = ActivateWindowT heme(Button1.Ha ndle)
    : Debug.WriteLine (Result)
    :
    : End Sub
    :
    :


    Comment

    • Robert Jacobson

      #3
      Re: Selectively enabling Visual Styles with SetWindowTheme

      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" <thomas.spink@n tlworld.com> wrote in message
      news:u$SrEbifDH A.3464@TK2MSFTN GP11.phx.gbl...[color=blue]
      > : Private Declare Function ActivateWindowT heme 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[/color]
      theme.[color=blue]
      > Also, your declare is wrong. Try this:
      >
      > (Change the integers, to strings)
      >
      > ActivateWindowT heme(Button1.Ha ndle, "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" <rjacobson_at_o ddpost_com@nosp am.com> wrote in message
      > news:#9G7MUifDH A.696@TK2MSFTNG P09.phx.gbl...
      > : Hi,
      > :
      > : I'm develing a COM add-in for Microsoft Word XP that displays a form.[/color]
      I'd[color=blue]
      > : like to have the form display using the Windows XP theme. However,
      > neither
      > : using a manifest nor calling Application.Ena bleVisualStyles does the
      > trick.
      > : (EnableVisualSt yles 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[/color]
      just[color=blue]
      > : 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:
      > :
      >[/color]
      http://translate.google.com/translat...xt&hl=en&u=htt[color=blue]
      >[/color]
      p%3A%2F%2Fwww%2 Eactivevb%2Ede% 2Ftutorials%2Ft ut%5Fxpstyles%2 Fxpstyles%2Ehtm l[color=blue]
      > : (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[/color]
      function[color=blue]
      > 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 ActivateWindowT heme 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 DeactivateWindo wTheme Lib "uxtheme" Alias
      > : "SetWindowTheme " ( _
      > : ByVal hWnd As IntPtr, _
      > : Optional ByRef pszSubAppName As String = " ", _
      > : Optional ByRef pszSubIdList As String = " ") _
      > : As Integer
      > :
      > : Private Declare Sub InitCommonContr ols Lib "comctl32" ()
      > :
      > : #Region " Windows Form Designer generated code "
      > :
      > : Public Sub New()
      > : MyBase.New()
      > :
      > : 'This call is required by the Windows Form Designer.
      > : InitializeCompo nent()
      > :
      > : 'Add any initialization after the InitializeCompo nent() call
      > : Call InitCommonContr ols()
      > : Dim Result As Integer = ActivateWindowT heme(Button1.Ha ndle)
      > : Debug.WriteLine (Result)
      > :
      > : End Sub
      > :
      > :
      >
      >[/color]


      Comment

      • Tom Spink

        #4
        Re: Selectively enabling Visual Styles with SetWindowTheme

        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.




        --
        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" <rjacobson_at_o ddpost_com@nosp am.com> wrote in message
        news:ePa#drifDH A.3024@tk2msftn gp13.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" <thomas.spink@n tlworld.com> wrote in message
        : news:u$SrEbifDH A.3464@TK2MSFTN GP11.phx.gbl...
        : > : Private Declare Function ActivateWindowT heme 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)
        : >
        : > ActivateWindowT heme(Button1.Ha ndle, "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" <rjacobson_at_o ddpost_com@nosp am.com> wrote in message
        : > news:#9G7MUifDH A.696@TK2MSFTNG P09.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.Ena bleVisualStyles does the
        : > trick.
        : > : (EnableVisualSt yles 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:
        : > :
        : >
        :

        : >
        :
        p%3A%2F%2Fwww%2 Eactivevb%2Ede% 2Ftutorials%2Ft ut%5Fxpstyles%2 Fxpstyles%2Ehtm l
        : > : (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 ActivateWindowT heme 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 DeactivateWindo wTheme Lib "uxtheme" Alias
        : > : "SetWindowTheme " ( _
        : > : ByVal hWnd As IntPtr, _
        : > : Optional ByRef pszSubAppName As String = " ", _
        : > : Optional ByRef pszSubIdList As String = " ") _
        : > : As Integer
        : > :
        : > : Private Declare Sub InitCommonContr ols Lib "comctl32" ()
        : > :
        : > : #Region " Windows Form Designer generated code "
        : > :
        : > : Public Sub New()
        : > : MyBase.New()
        : > :
        : > : 'This call is required by the Windows Form Designer.
        : > : InitializeCompo nent()
        : > :
        : > : 'Add any initialization after the InitializeCompo nent() call
        : > : Call InitCommonContr ols()
        : > : Dim Result As Integer = ActivateWindowT heme(Button1.Ha ndle)
        : > : Debug.WriteLine (Result)
        : > :
        : > : End Sub
        : > :
        : > :
        : >
        : >
        :
        :


        Comment

        • Mattias Sjögren

          #5
          Re: Selectively enabling Visual Styles with SetWindowTheme

          Robert,
          [color=blue]
          > Private Declare Function SetWindowTheme Lib "uxtheme" ( _
          > ByVal hWnd As IntPtr, _
          > ByRef pszSubAppName As String, _
          > ByRef pszSubIdList As String) _
          > As Integer[/color]

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



          Mattias

          --
          Mattias Sjögren [MVP] mattias @ mvps.org

          Please reply only to the newsgroup.

          Comment

          • Herfried K. Wagner [MVP]

            #6
            Re: Selectively enabling Visual Styles with SetWindowTheme

            Hello,

            "Robert Jacobson" <rjacobson_at_o ddpost_com@nosp am.com> schrieb:[color=blue]
            > 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[/color]

            I would use this declare (untested):

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

            --
            Herfried K. Wagner
            MVP · VB Classic, VB.NET
            Die Website von H. Wagner zu .NET, Visual Basic .NET, Classic Visual Basic, Webentwicklung und mehr.



            Comment

            • Robert Jacobson

              #7
              Re: Selectively enabling Visual Styles with SetWindowTheme

              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 InitCommonContr ols 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.Ena bleVisualStyles or a manifest?

              My only other hope is a real kludge -- first call
              Application.Ena bleVisualStyles (to get the Version 6 reference), then call
              SetThemeAppProp erties 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" <thomas.spink@n tlworld.com> wrote in message
              news:%23b96gyif DHA.2408@TK2MSF TNGP09.phx.gbl. ..[color=blue]
              > 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[/color]
              needs[color=blue]
              > to reference Version 6 of common controls.
              >
              > The reason SetWindowTheme doesn't work is because it's designed for[/color]
              setting[color=blue]
              > 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" <rjacobson_at_o ddpost_com@nosp am.com> wrote in message
              > news:ePa#drifDH A.3024@tk2msftn gp13.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[/color]
              string.[color=blue]
              > : (Hard for me to know exactly -- the automated translation of the page[/color]
              was[color=blue]
              > : really bad, and my German's even worse. <g>)
              > :
              > : Any other thoughts?
              > :
              > : --Robert
              > :
              > :
              > : "Tom Spink" <thomas.spink@n tlworld.com> wrote in message
              > : news:u$SrEbifDH A.3464@TK2MSFTN GP11.phx.gbl...
              > : > : Private Declare Function ActivateWindowT heme 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)
              > : >
              > : > ActivateWindowT heme(Button1.Ha ndle, "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" <rjacobson_at_o ddpost_com@nosp am.com> wrote in[/color]
              message[color=blue]
              > : > news:#9G7MUifDH A.696@TK2MSFTNG P09.phx.gbl...
              > : > : Hi,
              > : > :
              > : > : I'm develing a COM add-in for Microsoft Word XP that displays a[/color]
              form.[color=blue]
              > : I'd
              > : > : like to have the form display using the Windows XP theme. However,
              > : > neither
              > : > : using a manifest nor calling Application.Ena bleVisualStyles does the
              > : > trick.
              > : > : (EnableVisualSt yles 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[/color]
              work.[color=blue]
              > : > (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:
              > : > :
              > : >
              > :
              >[/color]
              http://translate.google.com/translat...xt&hl=en&u=htt[color=blue]
              > : >
              > :
              >[/color]
              p%3A%2F%2Fwww%2 Eactivevb%2Ede% 2Ftutorials%2Ft ut%5Fxpstyles%2 Fxpstyles%2Ehtm l[color=blue]
              > : > : (You gotta love using the "Communist manifesto" in Visual Basic.[/color]
              <g>)[color=blue]
              > : > :
              > : > : I created a test WinForms app that contains just a simple form with[/color]
              a[color=blue]
              > : > : 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"[/color]
              FlatStyle.[color=blue]
              > : > :
              > : > : Any suggestions?
              > : > :
              > : > : Thanks,
              > : > : Robert Jacobson
              > : > :
              > : > :
              > : > :
              > : > : Private Declare Function ActivateWindowT heme 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 DeactivateWindo wTheme Lib "uxtheme" Alias
              > : > : "SetWindowTheme " ( _
              > : > : ByVal hWnd As IntPtr, _
              > : > : Optional ByRef pszSubAppName As String = " ", _
              > : > : Optional ByRef pszSubIdList As String = " ") _
              > : > : As Integer
              > : > :
              > : > : Private Declare Sub InitCommonContr ols Lib "comctl32" ()
              > : > :
              > : > : #Region " Windows Form Designer generated code "
              > : > :
              > : > : Public Sub New()
              > : > : MyBase.New()
              > : > :
              > : > : 'This call is required by the Windows Form Designer.
              > : > : InitializeCompo nent()
              > : > :
              > : > : 'Add any initialization after the InitializeCompo nent() call
              > : > : Call InitCommonContr ols()
              > : > : Dim Result As Integer = ActivateWindowT heme(Button1.Ha ndle)
              > : > : Debug.WriteLine (Result)
              > : > :
              > : > : End Sub
              > : > :
              > : > :
              > : >
              > : >
              > :
              > :
              >
              >[/color]


              Comment

              • Robert Jacobson

                #8
                Re: Selectively enabling Visual Styles with SetWindowTheme

                Thanks, Mattias. I changed my declaration but it didn't help. I think the
                problems are more fundanmental.


                "Mattias Sjögren" <mattias.dont.w ant.spam@mvps.o rg> wrote in message
                news:ux69zBjfDH A.3616@TK2MSFTN GP11.phx.gbl...[color=blue]
                > Robert,
                >[color=green]
                > > Private Declare Function SetWindowTheme Lib "uxtheme" ( _
                > > ByVal hWnd As IntPtr, _
                > > ByRef pszSubAppName As String, _
                > > ByRef pszSubIdList As String) _
                > > As Integer[/color]
                >
                > 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.[/color]


                Comment

                • Robert Jacobson

                  #9
                  Re: Selectively enabling Visual Styles with SetWindowTheme

                  Thanks, but unfortunately, it doesn't help. It sounds like it won't work
                  without a manifest or Application.Ena bleVisualStyles . Please let me know if
                  I'm wrong.


                  "Herfried K. Wagner [MVP]" <hirf.nosp@m.ac tivevb.de> wrote in message
                  news:%23Ml5qNjf DHA.3200@tk2msf tngp13.phx.gbl. ..[color=blue]
                  > Hello,
                  >
                  > "Robert Jacobson" <rjacobson_at_o ddpost_com@nosp am.com> schrieb:[color=green]
                  > > 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[/color]
                  >
                  > I would use this declare (untested):
                  >
                  > \\\
                  > Private Declare Unicode Function SetWindowTheme Lib "uxtheme.dl l" ( _
                  > 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
                  >
                  >[/color]


                  Comment

                  • Herfried K. Wagner [MVP]

                    #10
                    Re: Selectively enabling Visual Styles with SetWindowTheme

                    Hello,

                    "Robert Jacobson" <rjacobson_at_o ddpost_com@nosp am.com> schrieb:[color=blue]
                    > Thanks, but unfortunately, it doesn't help. It sounds like
                    > it won't work without a manifest or Application.Ena bleVisualStyles .
                    > Please let me know if I'm wrong.[/color]

                    You will still need an application manifest.

                    --
                    Herfried K. Wagner
                    MVP · VB Classic, VB.NET
                    Die Website von H. Wagner zu .NET, Visual Basic .NET, Classic Visual Basic, Webentwicklung und mehr.



                    Comment

                    • Tom Spink

                      #11
                      Re: Selectively enabling Visual Styles with SetWindowTheme

                      I looked at the IL for Application.Ena bleVisualStyles , 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" <rjacobson_at_o ddpost_com@nosp am.com> wrote in message
                      news:u9H7bajfDH A.3284@tk2msftn gp13.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 InitCommonContr ols 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.Ena bleVisualStyles or a manifest?
                      :
                      : My only other hope is a real kludge -- first call
                      : Application.Ena bleVisualStyles (to get the Version 6 reference), then call
                      : SetThemeAppProp erties 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" <thomas.spink@n tlworld.com> wrote in message
                      : news:%23b96gyif DHA.2408@TK2MSF TNGP09.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" <rjacobson_at_o ddpost_com@nosp am.com> wrote in message
                      : > news:ePa#drifDH A.3024@tk2msftn gp13.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" <thomas.spink@n tlworld.com> wrote in message
                      : > : news:u$SrEbifDH A.3464@TK2MSFTN GP11.phx.gbl...
                      : > : > : Private Declare Function ActivateWindowT heme 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)
                      : > : >
                      : > : > ActivateWindowT heme(Button1.Ha ndle, "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" <rjacobson_at_o ddpost_com@nosp am.com> wrote in
                      : message
                      : > : > news:#9G7MUifDH A.696@TK2MSFTNG P09.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.Ena bleVisualStyles does
                      the
                      : > : > trick.
                      : > : > : (EnableVisualSt yles 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:
                      : > : > :
                      : > : >
                      : > :
                      : >
                      :

                      : > : >
                      : > :
                      : >
                      :
                      p%3A%2F%2Fwww%2 Eactivevb%2Ede% 2Ftutorials%2Ft ut%5Fxpstyles%2 Fxpstyles%2Ehtm l
                      : > : > : (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 ActivateWindowT heme 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 DeactivateWindo wTheme Lib "uxtheme"
                      Alias
                      : > : > : "SetWindowTheme " ( _
                      : > : > : ByVal hWnd As IntPtr, _
                      : > : > : Optional ByRef pszSubAppName As String = " ", _
                      : > : > : Optional ByRef pszSubIdList As String = " ") _
                      : > : > : As Integer
                      : > : > :
                      : > : > : Private Declare Sub InitCommonContr ols Lib "comctl32" ()
                      : > : > :
                      : > : > : #Region " Windows Form Designer generated code "
                      : > : > :
                      : > : > : Public Sub New()
                      : > : > : MyBase.New()
                      : > : > :
                      : > : > : 'This call is required by the Windows Form Designer.
                      : > : > : InitializeCompo nent()
                      : > : > :
                      : > : > : 'Add any initialization after the InitializeCompo nent() call
                      : > : > : Call InitCommonContr ols()
                      : > : > : Dim Result As Integer = ActivateWindowT heme(Button1.Ha ndle)
                      : > : > : Debug.WriteLine (Result)
                      : > : > :
                      : > : > : End Sub
                      : > : > :
                      : > : > :
                      : > : >
                      : > : >
                      : > :
                      : > :
                      : >
                      : >
                      :
                      :


                      Comment

                      Working...