Page 1 of 1

Apply Win7 Theme programatically

Posted: Fri Aug 12, 2011 1:35 pm
by IdeasVacuum
I have an interesting issue. My app is a DLL add-on for another (monster app). Various checks and preparation files have to be processed first, so I have a 'launcher' app that performs those tasks and then runs the monster.

Now, the monster uses it's own forms framework (for cross-platform purposes). The framework however is not 100% compatible with the GUI whistles and bells delivered by Win7, and so it is necessary to run it with the Win7 'Basic' Theme set.

I need my launcher app to switch the Theme programmatically - does anyone know how to do it?

Re: Apply Win7 Theme programatically

Posted: Wed Aug 17, 2011 4:05 pm
by RASHAD
Hi

Code: Select all


Procedure.s GetWindowsDirectory()
  Path.s=Space(500)
  GetWindowsDirectory_(@Path,500)
  ProcedureReturn Path
EndProcedure

Userd$ = GetHomeDirectory()

Wind$ = GetWindowsDirectory()
 
 OpenWindow(0, 0, 0, 100, 100, "OpenGL",#PB_Window_Invisible)
; 
;RunProgram("rundll32.exe", Chr(32)+Wind$+"\system32\shell32.dll,Control_RunDLL "+Wind$+"\system32\desk.cpl desk,@Themes /Action:OpenTheme /file:"+Chr(34)+Wind$+"\Resources\Themes\architecture.theme"+Chr(34),"",#PB_Program_Wait)

;RunProgram(Userd$+"\AppData\Local\Microsoft\Windows\Themes\RASHAD.theme")      ;For User Themes

RunProgram(Wind$+"\Resources\Ease of Access Themes\classic.theme")              ;For Basic Themes

;RunProgram(Wind$+"\Resources\Themes\characters.theme")                         ;For Aero Themes

  Repeat
    hwnd = FindWindow_("CabinetWClass", "Personalization")
  Until hWnd
  Delay(500)
SendMessage_(hwnd, #WM_CLOSE, 0, 0)
End



Re: Apply Win7 Theme programatically

Posted: Wed Aug 17, 2011 9:52 pm
by IdeasVacuum
Hi Rashad

I nearly got there, the killer is the Windows pop-up, solved by you thus:

Code: Select all

  Repeat
  hwnd = FindWindow_("CabinetWClass", "Personalization")
  Until hWnd
  Delay(500)
SendMessage_(hwnd, #WM_CLOSE, 0, 0)
I really dislike changing the User's theme but there is no choice.

Re: Apply Win7 Theme programatically

Posted: Wed Aug 17, 2011 10:38 pm
by RASHAD
Good
Adding some flavor

Code: Select all

#SPI_GETDESKWALLPAPER = 115

Path.s = Space(500) 
GetWindowsDirectory_(@Path,512)

FileName.s = Space(512)  
SystemParametersInfo_(#SPI_GETDESKWALLPAPER, Len( FileName ),FileName ,0)

OpenWindow(0, 0, 0, 100, 100, "OpenGL",#PB_Window_Invisible)
; 
;RunProgram(GetHomeDirectory() + "\AppData\Local\Microsoft\Windows\Themes\RASHAD.theme")      ;For User Themes

RunProgram(Path + "\Resources\Ease of Access Themes\classic.theme")                         ;For Basic Themes

;RunProgram(Path + "\Resources\Themes\characters.theme")                                     ;For Aero Themes

  Repeat
    hwnd = FindWindow_("CabinetWClass", "Personalization")
  Until hWnd
  Delay(500)
  SendMessage_(hwnd, #WM_CLOSE, 0, 0)
  SystemParametersInfo_(#SPI_SETDESKWALLPAPER, 0, FileName, #SPIF_UPDATEINIFILE | #SPIF_SENDWININICHANGE)
End


Re: Apply Win7 Theme programatically

Posted: Wed Aug 17, 2011 10:48 pm
by IdeasVacuum
8) Is there a safe way of finding the currently active theme? If so, the User's theme could be restored when the monster is shut-down....

Re: Apply Win7 Theme programatically

Posted: Wed Aug 17, 2011 10:58 pm
by RASHAD
I think you can


http://msdn.microsoft.com/en-us/library/bb773402.aspx


Or

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\CurrentTheme

Code: Select all

Path.s = Space(512) 
GetWindowsDirectory_(@Path,512)

Procedure.l QueryValueEx(lhkey.i, szValueName.s)
  Define.i cch, lrc, lType, lValue
  Shared vValue.s
  cch    = 255
  sValue.s = Space(255)
  lrc    = RegQueryValueEx_(lhkey, szValueName, 0, @lType, @sValue, @cch)
  If lrc = 0
    vValue = Left(sValue, cch - 1)
  Else
    vValue = "Empty"
  EndIf
  ProcedureReturn lrc
EndProcedure

lTopLevelKey = #HKEY_CURRENT_USER
sRemMachName.s = ""
sKeyName.s = "SOFTWARE\Microsoft\Windows\CurrentVersion\Themes"
sValueName.s = "CurrentTheme"

lRetVal = RegConnectRegistry_(sRemMachName, lTopLevelKey, @lHKeyhandle)
lRetVal = RegOpenKeyEx_(lHKeyhandle, sKeyName, 0, #KEY_READ, @lhkey)
lRetVal = QueryValueEx(lhkey, sValueName)
RegCloseKey_(lhkey)

If lRetVal = 0
  CurrentTheme$ = vValue
  Debug CurrentTheme$
  ;MessageRequester("Theme Name", vValue, #MB_ICONINFORMATION)
Else
  msg.s = "An Error occured, Return value = " + Str(lRetVal)
  MessageRequester("Error", msg, #MB_ICONERROR)
EndIf

OpenWindow(0, 0, 0, 100, 100, "OpenGL",#PB_Window_Invisible)

RunProgram(GetHomeDirectory() + "\AppData\Local\Microsoft\Windows\Themes\RASHAD.theme")      ;For User Themes

;RunProgram(Path + "\Resources\Ease of Access Themes\classic.theme")                         ;For Basic Themes

;RunProgram(Path + "\Resources\Themes\characters.theme")                                     ;For Aero Themes

  Repeat
    hwnd = FindWindow_("CabinetWClass", "Personalization")
  Until hWnd
  Delay(500)
  SendMessage_(hwnd, #WM_CLOSE, 0, 0)
End


Re: Apply Win7 Theme programatically

Posted: Thu Aug 18, 2011 3:42 pm
by IdeasVacuum
Hi Rashad

Thanks for that, I'll have a play with GetCurrentThemeName, which looks to be just the ticket :D