Is there anyway to set tyhe windows destop background from a program.

There must be some way since both IE and Paint allow you to do it.

Perhaps its a simple API function however I can't seem to find it.

Anyone know?

Thanks.
Posted on 2001-08-11 18:03:18 by Eóin
Im taking a total guess here, but maybe its some variable in the registry that points to a picture.
Posted on 2001-08-11 18:23:38 by ChimpFace9000
Variable in the registry is a very likely thing. Except that *just*
updating the reg value will not refresh the desktop window.... a little
more will probably be needed. I should think there's an API - and I think
that I have seen it some time ago in a masm32 app...
Posted on 2001-08-11 20:21:35 by f0dder
H?h? this is my first reply actually helping someone ( I hope ) haha :)

here it is ....

in order to set the wallpaper, use the
Win32 SystemParametersInfo() function, like this:


SystemParametersInfo(SPI_SETDESKWALLPAPER,0, "yourwallpaper.bmp",SPIF_UPDATEINIFILE );

You can also tile the wallpaper .... just go to

HKCU\Control Panel\Desktop\

and add the string TileWallpaper and set it to true ( 1 )

H?h? if you want direct update use the LazyWrite method .... but be aware, setting the LazyWrite property to false has the effect of forcing an immediate update to the registry ( this is what we want to do... no ?? ). it can cause an unnacceptable performance hit if you have many updates to perform.

I hope my first reply help :)

Have fun and enjoy !
Posted on 2001-08-11 21:13:42 by JP?
oups what I didn't say but it's pretty obvious that you must change de path to your wallpaper before calling the SPI ! :)

Easy, go to HKCU\Control Panel\Dektop\

and the string is called Wallpaper :)


Once you will have called SPI_SetDeskWallpaper the desktop's content will be forced to refresh :0

all your problems are solved !


Have fun
Posted on 2001-08-11 21:25:55 by JP?
Thank You very much, I guess its time to start playing around with a new app.
Posted on 2001-08-12 05:19:05 by Eóin
This is the one I used.

SUB Paint_Proc(hWin as LONG,hDC as LONG)

PaintDesktop hDC

END SUB

Regards,

hutch@pbq.com.au
Posted on 2001-08-12 05:29:53 by hutch--
Yeah Hutch, you're right .... actually you can " draw " on the desktop ... these are the steps required

1. Create a new canvas
2. Get its handle or I think you can use GetDC(GetDesktopWindow())
3. You draw !!
4. Release the dektop canvas ( Release DC )

and before your app exit, don't forget to free the memory !!!


Amusez-vous !
Posted on 2001-08-12 10:51:23 by JP?
JP, those changes will be temporary, won't they? :)
Posted on 2001-08-12 11:13:52 by f0dder
Yeah f0dder :) They will .... it's another possibility ..... don't know ... maybe Zadkiel want to do a random background changer in that case I would do a program that is resident in memory and draw over the desktop ..... it's also faster ( for what I have tested ) :)



Salut
Posted on 2001-08-12 11:51:02 by JP?
Thank you all for your replies, for an upcoming app I needed to be able to draw to the desktop so you just sloved another problem for me.

The app I'm writing now is a small program which runs at startup and sets the background image to one from an internal list.

I stiil have to implement a form of looping and a neat method of randomising the list and it'll be finished. Still for a few hours work its coming along.

If anyone wants it I'll make to open source freeware, the best kind.
Posted on 2001-08-12 20:57:29 by Eóin
I wrote a faily decient random function a while ago (based on statical methods i learned in a university course...) It has a very long repeating pattern.. I tested it with "random" x, y pixel cordinates and a "random" color. I used direct X and painted the screen randomly to see its pattern...

If it patterened anyway.. it sucked...
If a overall color developed (other than an off gray) it sucked... (since grey is a sum of equally likely average values in RGB..)

The test was quite good and passed my above tests...

Here is the macro i made out of it...

RAND32 MACRO base:REQ

; Random number generator based on the Real time clock
; and the Park, Miller random number algorithm
;
; Coded by NaN for WIN32ASM
; May 5, 2001
; rev 2.


push ecx
push edx

ifndef __RAND_BY_NAN__
__RAND_BY_NAN__ equ 1

.data?
NaNRand dd ?
.code

db 0fh,31h
shr eax, 2
add eax, 1
mov NaNRand, eax
endif

mov eax, NaNRand
mov edx,0
mov ecx, 127773 ;q
div ecx ; eax == floor( seed / q)
; edx == remainder
SWAP eax, edx
push edx
mov ecx, 16807
mul ecx ; eax = mul of remainder * a
pop edx ; edx == floor of seed/q

SWAP eax, edx
push edx
mov ecx, 2836
mul ecx
pop edx ; edx == mull of rem * a
; eax == mull of seed/q * r

sub edx, eax
mov eax, edx
mov NaNRand, eax ; save next seed
mov ecx, base
mov edx, 0
div ecx
mov eax, edx
pop edx
pop ecx
ENDM


Hope it helps...

PS: I would love to see the source.. as i know virtually nothing about registries... :) (( I had my computer say "registry corrupt, you must reinstall windows" before.. I've been terrified of meddling with this area because of it.. ~~ Irony was i knew nothing about windows programming at the time.. ))

NaN
Posted on 2001-08-12 21:15:51 by NaN
According to me the Registry is one a of the worst idea microsoft had ... Keeping separate INI files is better ..... The registry always grow and grow annnnnnnnnnnnd it grows .. then it corrupts and Windows becomes slow .... just note the difference of speed on the same machine with a fresh install of windows ...

I use different app for the maintenance of the Registry but none of them can maintain it in a clean state

it always grow !



NaN .... have fun messing with the Registry ( back'em up before :) )

Jp
Posted on 2001-08-12 21:49:21 by JP?
JP, I used to feel the same way as you do (and sort of still do, I guess).
It's so much nicer to have separate configuration files, because it's
faster to change a few settings (compared to open regedit, find
the key, etc).

But there's a few problems :(. First of all, getting per-user settings
is a bit more work. Not really hard to do, but you suddenly end up
with a lot of INI files and extra code :).

Next, under win2k (and probably NT as well), in a "workplace" situation,
your application will NOT be running with administrator rights, and
the program files directory most likely can't be written to. Haven't
seen this myself yet (usually run as admin privileges on my win2k box),
but for the commercial app I'm working on, we were asked to use
the registry because of this :/
Posted on 2001-08-13 00:18:50 by f0dder
Damn! Everything was going grand, I thought I had the program working up to a sufficient stage when I realised I hadn't tried it with jpegs, well lo and behold it doesn't work.

Is there a way around this? I tried setting the backgroung image to a jpg through windows and then using my program to give windows a new file address, but this didn't work.

PS I don't actually know how to set the folder path through the registry as was mentioned (So NAN I'm sure theres nothing in this program that you don't already know). As it stands I cheated and put all the images in the same folder but I'd like to know how this should be done.
Posted on 2001-08-13 15:43:39 by Eóin
To use jpegs (or gifs, or anything but bmp really) as background,
active desktop must be enabled. Dunno how to do that programatically,
and I dunno if the rules to change the background image/page is
different with active desktop.

Might be better to use som jpg->bmp conversion code? This would
make your app also work on older (win95, nt4) machines.
Posted on 2001-08-13 17:08:06 by f0dder
From Win32 tips/tricks



- How can i change Wallpaper ?

.data
NewPic db "c:\windows\blah.bmp",0
invoke SystemParametersInfo, SPI_SETDESKWALLPAPER, NULL, addr NewPic, SPIF_UPDATEINIFILE

Posted on 2001-08-20 12:36:18 by latigo
lo

i have win98 second edition and this is a section from my Win.ini:


Wallpaper=(None)
TileWallpaper=0
WallpaperStyle=2
Pattern=(None)

whats the point in this as, as you say, its all stored in the registry?

and i agree, .ini's are a lot better than the registry.
i have to format all my PC's at least every year to get them back on their feet again.

skud.
Posted on 2001-08-20 13:44:33 by skud
As far as I know, windows doesn't provide any API's for loading JPG files. You'll have to find some sample code to load a jpeg file yourself, or get a freeware dll to load JPEG's. I believe Intel has a DLL coded in ASM (but no source :( ), just check their website.
Posted on 2001-08-21 12:47:09 by Qweerdy

As far as I know, windows doesn't provide any API's for loading JPG files. You'll have to find some sample code to load a jpeg file yourself, or get a freeware dll to load JPEG's. I believe Intel has a DLL coded in ASM (but no source :( ), just check their website.


you are right, it can be download from Iczelion's site or u can use this link http://win32asm.rxsp.com/files/senfijl.zip:alright:
thers also ImageVu, which shows how to use NishitaView library, it can display *.BMP; *.DIB; *.GIF; *.JIF; *.JPG; *.JPEG; *.PCX; *.RLE; *.TGA images
http://win32asm.rxsp.com/files/ImageVu.zip
Posted on 2001-08-21 15:10:42 by NEMO