Changer le fond d'écran

Partagez votre expérience de PureBasic avec les autres utilisateurs.
Le Soldat Inconnu
Messages : 4312
Inscription : mer. 28/janv./2004 20:58
Localisation : Clermont ferrand OU Olsztyn
Contact :

Changer le fond d'écran

Message par Le Soldat Inconnu »

attention, qu'il n'y ait pas un petit malin qui s'avise de faire la même chose que mon changeur de fond d'écran :x

mais non, je plaisante :wink:

Code : Tout sélectionner

Procedure SetWallpaper(FileName.s, Style.s)
  ; style = 0 : centrer
  ; style = 2 : étirer
  RegOpenKeyEx_(#HKEY_CURRENT_USER, "Control Panel\Desktop\", #NULL, #KEY_ALL_ACCESS, @hKey)
  RegSetValueEx_(hKey, "WallpaperStyle", #NULL, #REG_SZ, @Style, Len(Style) + 1 )
  Style = "0"
  RegSetValueEx_(hKey, "TileWallpaper", #NULL, #REG_SZ, @Style, Len(Style) + 1 )
  SystemParametersInfo_(#SPI_SETDESKWALLPAPER, 0, FileName, #SPIF_UPDATEINIFILE | #SPIF_SENDWININICHANGE)
EndProcedure

WPFileName.s = OpenFileRequester("Choix de l'image BMP", "*.bmp", "Bitmap Files (*.bmp)|*.bmp|All Files (*.*)|*.*", 1, 0)
If WPFileName <> ""
  SetWallpaper(WPFileName, "2")
EndIf
Je ne suis pas à moitié Polonais mais ma moitié est polonaise ... Vous avez suivi ?

[Intel quad core Q9400 2.66mhz, ATI 4870, 4Go Ram, XP (x86) / 7 (x64)]
Avatar de l’utilisateur
graph100
Messages : 1318
Inscription : sam. 21/mai/2005 17:50

Message par graph100 »

Ton truc ne marche pas avec les jpg :(
AWEAR
Messages : 264
Inscription : ven. 28/oct./2005 8:20
Localisation : Mayotte ( 976 ), Océan Indien, France

Re: Changer le fond d'écran

Message par AWEAR »

Le Soldat Inconnu a écrit :attention, qu'il n'y ait pas un petit malin qui s'avise de faire la même chose que mon changeur de fond d'écran :x
Je me sens visé, alors je te présente mes excuses pour mon poste sur l'autre topic..

Sinon graph100 c'est normal, c'est l'API elle-même qui empêche l'utilisation d'une image autre qu'un bitmap..
La vie est une rose dont il faut accepter les épines, mais la mienne est fannée, arrosée par le goût de mes larmes. (Soprano)
Avatar de l’utilisateur
graph100
Messages : 1318
Inscription : sam. 21/mai/2005 17:50

Message par graph100 »

pourtant on peut mettre une jpg en fond d'ecran !!
AWEAR
Messages : 264
Inscription : ven. 28/oct./2005 8:20
Localisation : Mayotte ( 976 ), Océan Indien, France

Message par AWEAR »

Sauf erreur de ma part, Windows enregistre ton image quelque part avant de la mettre en fond d'écran.
La vie est une rose dont il faut accepter les épines, mais la mienne est fannée, arrosée par le goût de mes larmes. (Soprano)
Gillou
Messages : 373
Inscription : sam. 28/août/2004 17:35
Localisation : Bretagne, 22
Contact :

Message par Gillou »

La même chose avec possibilité de choisir une image jpeg, bmp,..
ProcedureDLL.s GetUserProfileDirectory() ; Retourne l'adresse du répertoire utilisateur
     OpenProcessToken_ ( GetCurrentProcess_ (), $08, @token)
    
    Length.l = 512
    directory$ = Space (Length)
    
     GetUserProfileDirectory_ (token, directory$, @Length)
     ProcedureReturn Left (directory$, Length) + "\"
EndProcedure

ProcedureDLL.s GetWindowsDirectory_BIS() ; Retourne l'adresse de Windows
    windir$ = Space (255) : GetWindowsDirectory_ ( @windir$, 255) : If Right (windir$, 1) <> "\" : windir$ + "\" : EndIf
     ProcedureReturn windir$
EndProcedure

ProcedureDLL SetWallpaper(FileName.s, Image, mode.l, BackgroundColor.l) ; mode=1 Etirer, 2 Centrer, 3 Centrer et agrandir, 4 Mosaïque, 5 Mosaïque et agrandi (si FileName="" , Image sera pris en compte et inversement)
     ; mode=1 Etirer
     ; mode=2 Centrer
     ; mode=3 Centrer et agrandissement proportionnel
     ; mode=4 Mosaïque
     ; mode=5 Mosaïque et agrandissement proportionel
     If FileName
         UseJPEGImageDecoder ()
; UseEC_OLEImageDecoder()
         UsePNGImageDecoder ()
         UseTGAImageDecoder ()
         UseTIFFImageDecoder ()
        idi = LoadImage ( #PB_Any , FileName)
     ElseIf Image
        idi = Image
     EndIf
    
     If IsImage (idi)
        id = ImageID (idi)
        largimag = ImageWidth (idi)
        hautimag = ImageHeight (idi)
        dx = GetSystemMetrics_ ( #SM_CXSCREEN )
        dy = GetSystemMetrics_ ( #SM_CYSCREEN )
        lon = Len ( GetExtensionPart (FileName))
         If IsAdmin() = 1
             If OSVersion () = #PB_OS_Windows_XP Or OSVersion () = #PB_OS_Windows_2000
                photo.s = GetWindowsDirectory_BIS() + "Web\Wallpaper\Fond d'écran.bmp"
             Else
                photo.s = GetWindowsDirectory_BIS() + "Fond d'écran.bmp"
             EndIf
         Else
            photo.s = GetUserProfileDirectory() + "Fond d'écran.bmp"
         EndIf
         If mode = 1
             ResizeImage (idi, dx, dy)
             SaveImage (idi, photo)
         ElseIf mode = 2
            idi2 = CreateImage ( #PB_Any , dx, dy)
             StartDrawing ( ImageOutput (idi2))
                 Box (0, 0, dx, dy, BackgroundColor)
                 DrawImage (Id, (dx - largimag) / 2, (dy - hautimag) / 2)
             StopDrawing ()
             SaveImage (idi2, photo)
         ElseIf mode = 3
            idi2 = CreateImage ( #PB_Any , dx, dy)
             StartDrawing ( ImageOutput (idi2))
                 Box (0, 0, dx, dy, BackgroundColor)
                clarg.f = dx / largimag
                chaut.f = dy / hautimag
                 If clarg > chaut
                     DrawImage (Id, (dx - Round (chaut * largimag, 0)) / 2, 0, Round (chaut * largimag, 0), dy)
                 ElseIf clarg < chaut
                     DrawImage (Id, 0, (dy - Round (clarg * hautimag, 0)) / 2, dx, Round (clarg * hautimag, 0))
                 Else
                     DrawImage (id, 0, 0, dx, dy)
                 EndIf
             StopDrawing ()
             SaveImage (idi2, photo)
             FreeImage (idi2)
         ElseIf mode = 4
            idi2 = CreateImage ( #PB_Any , dx, dy)
             StartDrawing ( ImageOutput (idi2))
                 Box (0, 0, dx, dy, BackgroundColor)
                nc = Round (dx / largimag, 1)
                nl = Round (dy / hautimag, 1)
                 For a = 0 To nc - 1
                     For b = 0 To nl - 1
                         DrawImage (id, a * largimag, b * hautimag)
                     Next
                 Next
             StopDrawing ()
             SaveImage (idi2, photo)
             FreeImage (idi2)
         ElseIf mode = 5
            idi2 = CreateImage ( #PB_Any , dx, dy)
             StartDrawing ( ImageOutput (idi2))
                 Box (0, 0, dx, dy, BackgroundColor)
                clarg.f = dx / largimag
                chaut.f = dy / hautimag
                 If clarg > chaut
                    width = Round (chaut * largimag, 0)
                    height = dy
                 ElseIf clarg < chaut
                    width = dx
                    height = Round (clarg * hautimag, 0)
                 Else
                    width = dx
                    height = dy
                 EndIf
                nc = Round (dx / width, 1)
                nl = Round (dy / height, 1)
                 For a = 0 To nc - 1
                     For b = 0 To nl - 1
                         DrawImage (id, a * width, b * Height, width, height)
                     Next
                 Next
             StopDrawing ()
             SaveImage (idi2, photo)
             FreeImage (idi2)
         EndIf
         If FileName
             FreeImage (idi)
         EndIf
         ProcedureReturn SystemParametersInfo_ ( #SPI_SETDESKWALLPAPER , 0, photo, #SPIF_UPDATEINIFILE | #SPIF_SENDWININICHANGE )
     EndIf
EndProcedure
Backup
Messages : 14526
Inscription : lun. 26/avr./2004 0:40

Message par Backup »

@ soldat inconnu

je viens de telecharger ton changeur de fond d'ecran

j'ai une petite demande

pourrai tu inclure la possibilité de choisir le temps de changement

par exemple changement toute les minutes, ou 30 secondes ou 1 heures ect !! , bref ajouter un chrono :)

j'ai noté un bug chez moi

lorsque je cherche a faire afficher en mode "etiré" a partir de ton soft
j'ai un plantage du soft ! (XP etait lui reglé sur "Centré")

j'ai finalement pu faire afficher en mode étiré en passant par XP
pas par ton soft :)

sinon sympath ce soft :)
lionel_om
Messages : 1500
Inscription : jeu. 25/mars/2004 11:23
Localisation : Sophia Antipolis (Nice)
Contact :

Message par lionel_om »

Webmestre de Basic-univers
Participez à son extension: ajouter vos programmes et partagez vos codes !
Le Soldat Inconnu
Messages : 4312
Inscription : mer. 28/janv./2004 20:58
Localisation : Clermont ferrand OU Olsztyn
Contact :

Message par Le Soldat Inconnu »

Mon, logiciel, c'est juste au démarrage pour ne bouffer aucune ressource :)
Je ne suis pas à moitié Polonais mais ma moitié est polonaise ... Vous avez suivi ?

[Intel quad core Q9400 2.66mhz, ATI 4870, 4Go Ram, XP (x86) / 7 (x64)]
Avatar de l’utilisateur
Thyphoon
Messages : 2706
Inscription : mer. 25/août/2004 6:31
Localisation : Eragny
Contact :

Message par Thyphoon »

Le Soldat Inconnu a écrit :Mon, logiciel, c'est juste au démarrage pour ne bouffer aucune ressource :)
sinon il suffit de faire une tache planifier qui execute le logiciel tout les x... minutes ... :)
Le Soldat Inconnu
Messages : 4312
Inscription : mer. 28/janv./2004 20:58
Localisation : Clermont ferrand OU Olsztyn
Contact :

Message par Le Soldat Inconnu »

Oui aussi, mais bon, je ne l'utilise plus, ce logiciel, donc il n'évolue plus.

Et je suis assez occupée en programmation pour le moment, avec un gros projet pour remplacer mon PopupMenu Editeur
Je ne suis pas à moitié Polonais mais ma moitié est polonaise ... Vous avez suivi ?

[Intel quad core Q9400 2.66mhz, ATI 4870, 4Go Ram, XP (x86) / 7 (x64)]
Répondre