Desktop background

BlitzMax Forums/BlitzMax Programming/Desktop background

GfK(Posted 2008) [#1]
Is there a way to load the user's desktop background and scale it down to use as an image?

I have a particular need to display the user's desktop in a 'thumbnail' type of view but if they've got loads of windows and stuff open, I don't want those. So I figured I might be able to just find out the path to the image and load it somehow?

Thoughts?


plash(Posted 2008) [#2]
http://msdn.microsoft.com/en-us/library/ms724947.aspx

Look for SPI_GETDESKWALLPAPER.


GfK(Posted 2008) [#3]
I don't know how to do that.


GfK(Posted 2008) [#4]
This returns garbage. What have I done wrong?
Extern "win32"
  Function SystemParametersInfo(uiAction:Int, uiParam:Int, pvParam:String, fWinIni:Int) = "SystemParametersInfoA@16"
End Extern

Const SPI_GETDESKWALLPAPER = $73

Print getwallpaper()
End

Function GetWallpaper:String()
	Local result:String
	SystemParametersInfo(SPI_GETDESKWALLPAPER, 128, result, 0)
        Return result
End Function



plash(Posted 2008) [#5]
This returns garbage. What have I done wrong?
Woah! The output looks like the contents of a executable (when opened in notepad.)

SuperStrict

Framework brl.standardio
Import brl.bank

Extern "win32"
	Function SystemParametersInfo(uiAction:Int, uiParam:Int, pvParam:Byte Ptr, fWinIni:Int) = "SystemParametersInfoA@16"
	
End Extern
Const SPI_GETDESKWALLPAPER:Int = $73


Print GetWallpaper()
End

Function GetWallpaper:String()
  Local tmp_bank:TBank = CreateBank(255), returnvalue:Byte Ptr = BankBuf(tmp_bank)
	
	SystemParametersInfo(SPI_GETDESKWALLPAPER, 128, returnvalue, 0)
	
   Return String.FromCString(returnvalue)
   
End Function


There was a way of getting the value using some form of a string (cstring, wstring, short ptr to string?) but I don't remember what it was, the above works just fine.


Bremer(Posted 2008) [#6]
You can use the same function to change the wallpaper.

Add the following code:

Const SPI_SETDESKWALLPAPER:Int = $14
Function SetWallpaper(path:String)
	SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, path.toCString(), 0)
End Function


and call it like this:

SetWallpaper("E:/abc.bmp")



GfK(Posted 2008) [#7]
Thanks Plash - had a feeling I'd end up having to use a bank.

Its that pvParam that's been confusing me. The documentation etc that I found on the internet implies that it can be a string or a pointer. I assumed that a string would be easiest given that that's what I wanted. I did try it as a CString but that didn't work either.

You should put that in the code archives for future reference.


Yan(Posted 2008) [#8]
The pvParam can, depending on the value of uiAction, point to a number of different variable types and can be used for both input and output.

Plash's version is ever so slighlty incorrect in that the returned string can be any length up to MAX_PATH, which on my system is set to 260 characters for instance. This is generally not gonna be a problem, but no point in setting yourself up for potential problems in the future.

I use something like this...
Strict

?Win32
	Const SPI_GETDESKWALLPAPER = $73

	Extern "win32"	
		Function SystemParametersInfo(uiAction, uiParam, pvParam:Byte Ptr, fWinIni) = "SystemParametersInfoA@16"	
	End Extern
?

Print GetWallPaperPath()

End


Function GetWallPaperPath$()
?Win32
	Local buff@[MAX_PATH]
	
	SystemParametersInfo(SPI_GETDESKWALLPAPER, buff@.length, buff@, Null)
	
	Return String.FromCString(buff@)
?
End Function



GfK(Posted 2008) [#9]
What's the @ do in buff@?


Yan(Posted 2008) [#10]
It's one of the 'shortcut' variable types...
% = Int
%% = Long

@ = Byte
@@ = Short

# = Float
! = Double

$ = String



GfK(Posted 2008) [#11]
Oh. People still use those?

Thx!


Yan(Posted 2008) [#12]
Just the lazy ones. ;o)


GfK(Posted 2008) [#13]
Another thing while this thread is still buoyant.

Is there a way to query whether the background image is tiled, stretched or centered? My google search results have got little result other than I now know how to lay vinyl floor tiles.


Yahfree(Posted 2008) [#14]
>I now know how to lay vinyl floor tiles.

Can you do our bathroom? Though you would have to fly many many miles to get to washington state, USA.


Jokes aside, did you search msdn? http://msdn.microsoft.com/en-us/default.aspx


GfK(Posted 2008) [#15]
Yes, but I don't rightly know what it is I'm looking for.


plash(Posted 2008) [#16]
@Yan: Ahh, I knew there was a simpler way of doing it!