Registry Object

For questions about using Classic.

Post » Sat Sep 25, 2010 7:17 am

I'm trying to set a wallpaper image using the Registry object, but first I want to save the location of the user's current wallpaper so it can be set back after the game is closed.

So I do...

Start of layout ->
Open Key (Root = HKEY_CURRENT_USER, Value = '\Control Panel\desktop')
Set global variable to Registry.ReadValue('Registry.OpenKey')

That syntax probably isn't exact but I'm sure you'll see what I mean when you try it. My problem so far is that whenever I try to put in that value for the key to open, I get a message saying that the private variable or registry key '\Control Panel\desktop' doesn't exist and it asks if I want to set it, which brings up window to create a private variable if you say yes.

I've tried it as

\Control Panel\desktop\wallpaper

..pretty much every permeation I can think of those.

Do registry keys have a format extension I should be using?
Is the registry object broken (in the .84 build?)
Is there something wrong with how I'm typing the key?
Posts: 114
Reputation: 1,553

Post » Sat Sep 25, 2010 10:55 am

This works:

+ System: Start of layout
-> Registry: Open key "Control Panel\Desktop" under root HKEY_CURRENT_USER
-> Text: Set text to Registry.ReadString("WallPaper")

Strings in Construct use double quotes. Single quotes are only for variable names.
Posts: 5,554
Reputation: 85,321

Post » Sat Sep 25, 2010 2:35 pm

Thanks, I knew that about the strings/variables.. I was just being stupid and thinking it was supposed to be a variable. That works perfectly, though I still need to use python to update the desktop to the new background. For those interested, here it is...

//You need to use the ctypes module, already in python after 2.5
[code:3i234jv2]+ System: Start of layout
-> System: Run Script ("import ctypes")[/code:3i234jv2]

//Code from ROJO, thank you very much!
[code:3i234jv2]-> Registry: Open key "Control Panel\Desktop\" under root HKEY_CURRENT_USER
-> System: Set global variable 'OldWallPaper' to Registry.ReadString("Wallpaper")[/code:3i234jv2]

//Insert your path. It can be something other than BMP,
//I've read otherwise while researching but it worked for me.
[code:3i234jv2]-> Registry: Write string "C:\Users\UserName\Documents\Backgrounds\BG_Name.bmp" to item "WallPaper"[/code:3i234jv2]

//Set the parameters to be called when updating the desktop
[code:3i234jv2]-> System: Run Script ("SPI_SETDESKWALLPAPER = 20")
-> System: Run Script ("SPIF_SENDWININICHANGE = 20")
-> System: Run Script ("SPIF_UPDATEINIFILE = 0")[/code:3i234jv2]

//The actual call to update the desktop.
//Notice that I break the quotes up around the global variable and use the & to add more.
//You either need to do that you get an error because its looking for a file path there.
[code:3i234jv2]-> System: Run Script ("ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, " & global('NewWallPaper') & " , SPIF_UPDATEINIFILE or SPIF_SENDWININICHANGE)")

//All of the above was done under Start of Layout.
//When the program closes, reset the path and update desktop again.

[code:3i234jv2]+ System: End of application
-> Registry: Write string global('OldWallPaper') to item "WallPaper"
-> System: Run Script ("ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, " & global('NewWallPaper') & " , SPIF_UPDATEINIFILE or SPIF_SENDWININICHANGE)")[/code:3i234jv2]

This doesn't alter settings for how the background is shown, I'll add that later today and repost.
Posts: 114
Reputation: 1,553

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 0 guests