CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    Join Date
    Jul 2003
    Posts
    135

    How do I programmatically change Windows Themes in XP?

    I wrote a small app we use on our computer to keep them running optimally and do some utility things (delete temp files, defrag drives, clean registry, backup my docs to the server, etc). One of the options I ahve in there is "Reset Windows to Defaults" and the objective was to setup windows how we normally would set them up before we give them to our users. So if a user messes with all his/her settings we can click this button and reset it all back. So far it resets IE settings, changes Window Explorer views, puts all the default icons on the desktop and turns off desktop cleanup, etc.

    Well one of the last things I want to do is change to the default Windows XP theme and apply it. After a lot of searching the internet I found this:

    Code:
        <DllImport("UxTheme.DLL", BestFitMapping:=False, CallingConvention:=CallingConvention.Winapi, CharSet:=CharSet.Unicode, EntryPoint:="#65")> _
    Shared Function SetSystemVisualStyle(ByVal pszFilename As String, ByVal pszColor As String, ByVal pszSize As String, ByVal dwReserved As Integer) As Integer
        End Function
    Then it can be called in your code with something like this:

    SetSystemVisualStyle("C:\WINDOWS\resources\Themes\Luna\Luna.msstyles", "NormalColor", "NormalSize", 0)

    It does reset colors and stuff back to the theme. The problem is if a user has "Windows Classic" set and this is run it does apply the theme.....mostly. Things like dialog boxes stay in classic while the menu structure and desktop go the XP style. If you go into display properties it still shows "Windows Classic" but under Appearance it shows "Windows XP" which leads me to believe even though this function is for themes its actually just applying the appearance and not actually setting the theme.

    Anyone know how to actually change and apply the theme?

  2. #2
    Join Date
    Jul 2003
    Posts
    135

    Re: How do I programmatically change Windows Themes in XP?

    Nevermind...have to call the function with a 1 at the end and not 0. That and update some other registry keys afterward. Either way it's working now.

  3. #3
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: How do I programmatically change Windows Themes in XP?

    Thanx for sharing!

    I know this thread is solved, but you could also have a look at this article :

    http://www.codeguru.com/vb/gen/vb_mi...php/c14319__1/

    Just for interest sake

  4. #4
    Join Date
    Aug 2009
    Posts
    1

    Re: How do I programmatically change Windows Themes in XP?

    Quote Originally Posted by CrystalAnnoysMe View Post
    Nevermind...have to call the function with a 1 at the end and not 0. That and update some other registry keys afterward. Either way it's working now.
    Hello,

    I am trying to do the same thing. Would you be willing to post your code, or indicate what additional registry keys to set?

    Thanks & regards,

    -John

  5. #5
    Join Date
    Dec 2008
    Posts
    114

    Re: How do I programmatically change Windows Themes in XP?

    Quote Originally Posted by HanneSThEGreaT View Post
    I know this thread is solved, but you could also have a look at this article :
    http://www.codeguru.com/vb/gen/vb_mi...php/c14319__1/
    Just for interest sake
    Very bad 'article'...
    The registry don't absolutely need to be updated.

  6. #6
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: How do I programmatically change Windows Themes in XP?

    Did you happen to catch the author of that 'bad' article?
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  7. #7
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Angry Re: How do I programmatically change Windows Themes in XP?

    Quote Originally Posted by carl666 View Post
    Very bad 'article'...
    The registry don't absolutely need to be updated.
    Hmm.... Strange that the article has got 4 stars and the author of the article ( me ) has got a 4.64 rating out of 5, for all his ( my ) 25 articles..

    Anyways, I'm not here to argue the quality of my article(s). I know I'm not the sharpest guy around

    All I want to ask is why exactly do you say it is a very bad article, is it about the registry ¿

    All the members & guests would like to know , because theyr'e here to learn. If you have a better way to do any of the topics covered in that article, please share it with us.

    PS... Have you written any articles before ¿

  8. #8
    Join Date
    Jul 2003
    Posts
    135

    Re: How do I programmatically change Windows Themes in XP?

    Code:
    Imports System.Runtime.InteropServices
    Module GeneralFunctions
        <DllImport("UxTheme.DLL", BestFitMapping:=False, CallingConvention:=CallingConvention.Winapi, CharSet:=CharSet.Unicode, EntryPoint:="#65")> _
    Friend Function SetSystemVisualStyle(ByVal pszFilename As String, ByVal pszColor As String, ByVal pszSize As String, ByVal dwReserved As Integer) As Integer
        End Function
    End Module
    Then in my code I call the function first and then update the registry so it shows up as modified when someone looks at it:
    Code:
    SetSystemVisualStyle("C:\WINDOWS\resources\Themes\Luna\Luna.msstyles", "NormalColor", "NormalSize", 1)
    WriteRegistryValue(Registry.CurrentUser, "Control Panel\Desktop", "Wallpaper", "C:\WINDOWS\Web\Wallpaper\Bliss.bmp", RegistryValueKind.String)
    WriteRegistryValue(Registry.CurrentUser, "Control Panel\Desktop", "WallpaperStyle", "2", RegistryValueKind.String)
    WriteRegistryValue(Registry.CurrentUser, "Software\Microsoft\Internet Explorer\Desktop\General", "Wallpaper", "C:\WINDOWS\Web\Wallpaper\Bliss.bmp", RegistryValueKind.String)
    WriteRegistryValue(Registry.CurrentUser, "Software\Microsoft\Internet Explorer\Desktop\General", "WallpaperStyle", "2", RegistryValueKind.ExpandString)
    WriteRegistryValue(Registry.CurrentUser, "Software\Microsoft\Windows\CurrentVersion\Themes\LastTheme", "DisplayName of Modified", "Windows XP (Auto Modified)", RegistryValueKind.String)
    DeleteRegistryValue(Registry.CurrentUser, "Software\Microsoft\Windows\CurrentVersion\Themes\LastTheme", "ThemeFile")
    WriteRegistryValue(Registry.CurrentUser, "Software\Microsoft\Windows\CurrentVersion\Themes\LastTheme", "Wallpaper", "%SystemRoot%\Web\Wallpaper\Bliss.bmp", RegistryValueKind.ExpandString)
    Not going to post my registry functions, you should be able to figure them out. Works very well for what I want.

    -Allan

  9. #9
    Join Date
    Jun 2004
    Location
    NH
    Posts
    678

    Re: How do I programmatically change Windows Themes in XP?

    why exactly do you say it is a very bad article, is it about the registry
    Yea, some people are prejudicial, like that.

    They think:
    Oh, it must be bad, because it's changing my registry.
    In fact most API's relating to windows settings indeed change the registry too.

    As you get better, and more expert at VB, you will find that all of your code could be used for bad purposes.
    What better reason, to use it for good purposes. For example allowing users to control their themes.

    That would be bad......Not
    Last edited by TT(n); August 27th, 2009 at 02:10 AM.

  10. #10
    Join Date
    Feb 2000
    Location
    OH - USA
    Posts
    1,892

    Arrow Re: How do I programmatically change Windows Themes in XP?

    Hans,

    I'm pretty sure the reader did not go beyond the first page, and that's not your fault, it's CG for having tiny page numbers at the bottom.

    I think you do a great job explaining how all of that mess is organized in the registry.

    If available, an API should always be used over a direct registry modification. So maybe you could improve your article by presenting a side-by-side comparison of the API's on [Page 2], and what registry values they modify.

    However, that's a lot of research, and probably not necessary.

    Hope you're well.
    Good Luck,
    Craig - CRG IT Solutions - Microsoft Gold Partner

    -My posts after 08/2015 = .NET 4.x and Visual Studio 2015
    -My posts after 11/2011 = .NET 4.x and Visual Studio 2012
    -My posts after 02/2010 = .NET 4.0 and Visual Studio 2010
    -My posts after 12/2007 = .NET 3.5 and Visual Studio 2008
    -My posts after 04/2007 = .NET 3.0 and Visual Studio 2005
    -My posts before 04/2007 = .NET 1.1/2.0

    *I do not follow all threads, so if you have a secondary question, message me.

  11. #11
    Join Date
    Jun 2004
    Location
    NH
    Posts
    678

    Re: How do I programmatically change Windows Themes in XP?

    If available, an API should always be used over a direct registry modification
    Exactly, I agree with that for the reasoning:
    The registry is a widely general tool, that in a sense could cause harm to any number of things.
    Therefore it is lumped up with all of the other potentially harmful uses, by anti-virus programs, security settings, and people alike.

    It's sort of a case of regicial profiling. lol

    In my critique of the article/program, the only thing I saw missing, was the GetCurrentTheme API.
    It makes sense that this should be in there for sure.
    That way when the theme list is populated, the current them visible and selected.
    This by no means, makes the article bad.


    _
    Last edited by TT(n); August 27th, 2009 at 02:17 AM.

  12. #12
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: How do I programmatically change Windows Themes in XP?

    Hey guys!

    Wow, thanx for your great reponses! I'll have a look at the available APIs, unfortunately just pressed for time

    Good seeing you again Craig! Long time no see

  13. #13
    Join Date
    Aug 2010
    Posts
    13

    Exclamation Re: How do I programmatically change Windows Themes in XP?

    Hello Folks,

    I am working on the same application that changes the Windows themes. I have two questions
    1. My WriteRegistryValue() is not working. I cant find its references, although I thought it to be Microsoft.Win32.

    2. My theme is not changing... I dont know what is the problem?

    Need urgent help fellows

  14. #14
    Join Date
    Jul 2003
    Posts
    135

    Re: How do I programmatically change Windows Themes in XP?

    Quote Originally Posted by farrukh_javeid View Post
    Hello Folks,

    I am working on the same application that changes the Windows themes. I have two questions
    1. My WriteRegistryValue() is not working. I cant find its references, although I thought it to be Microsoft.Win32.

    2. My theme is not changing... I dont know what is the problem?

    Need urgent help fellows
    1) Are you using my code sample above? If so then no it probably isn't working....the WriteRegistryValue() I have above is my own function for writting registry settings.

    2) Fixing the above will fix the theme being set issue.

  15. #15
    Join Date
    Aug 2010
    Posts
    13

    Re: How do I programmatically change Windows Themes in XP?

    Thanks for the quick response .
    I need to ask if you have used the function Registry.SetValue()? If yes, in what shape the parameters might be.
    Sorry, I am new to visual basic .net

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured