Jump to content

WallpaperSet with Windows 10


jimg
 Share

Recommended Posts

I have been using Wallpaperset for several years successfully with Windows XP and Windows 7, but after migrating to Windows 10, it quit working.  No error messages - just doesn't do anything. The Win10 background context menu no longer has "set as background", which is probably the root of the problem.  Any suggestions?  

#include <WinAPI.au3>
#include <File.au3>
#include <GDIPlus.au3>
#include <INet.au3>
#Region WallpaperSet()


    While 1
        $data = _INetGetSource("http://photography.nationalgeographic.com/photography/photo-of-the-day/?source=NavPhoPOD")
        $ptr = StringInStr($data, '<div class="primary_photo">')
        $data = StringTrimLeft($data, $ptr + 20)
        $ptr = StringInStr($data, 'images.n')
        $data = StringTrimLeft($data, $ptr - 1)
        $ptr = StringInStr($data, '"')
        $img = StringLeft($data, $ptr - 1)
        $img = "http://" & $img
        ;msgbox("",0,$img)
        $ptr = StringInStr($data, 'alt=')
        $alt = StringTrimLeft($data, $ptr + 4)
        $ptr = StringInStr($alt, '" />')
        $alt = StringLeft($alt, $ptr - 1)

        MsgBox(0, "", $alt)
        InetGet($img, "temp.jpg")
        ;msgbox(0,"",@ERROR)
        Global $WALLPAPER_CENTER = 0
        Global $WALLPAPER_TILE = 1
        Global $WALLPAPER_STRETCH = 2
        $status = WallpaperSet("temp.jpg", 2, "temp.bmp")
        ;msgbox(0,"",$status&","&@error)
        Sleep(60000)

        While @HOUR <> 6 Or @MIN <> 0
            Sleep(40000)
        WEnd
    WEnd

    ; ===================================================================
    ; WallpaperSet($sPath, $nStyle = $WALLPAPER_STRETCH, $sConversionPath = "")
    ;
    ; Sets the desktop wallpaper to the specified file.
    ; Parameters:
    ;   $sPath - IN - The path to the wallpaper file. If this file is not a BMP then it will be converted
    ;       to a BMP at either $sConversionPath (if present) or an auto-generated location.
    ;   $nStyle - IN/OPTIONAL - Controls the display of the wallpaper using the $WALLPAPER_* flags.
    ;   $sConversionPath - IN/OPTIONAL - The path to save a BMP wallpaper when one is generated from
    ;       a non-BMP wallpaper.
    ; Returns:
    ;   Success - Returns True.
    ;   Failure - Returns False and sets @error to non-zero.
    ; ===================================================================
    Func WallpaperSet($sPath, $nStyle = $WALLPAPER_STRETCH, $sConversionPath = "")
        ; Ensure the file exists. Allows an empty path which clears the wallpaper.
        If $sPath And Not FileExists($sPath) Then Return SetError(1, 0, False)

        ; Split the path.
        Local $sDrive, $sDir, $sFile, $sExt
        _PathSplit($sPath, $sDrive, $sDir, $sFile, $sExt)

        ; Convert the image to a bitmap.
        If $sPath And $sExt <> ".bmp" Then
            ; Startup GDI Plus.
            If Not _GDIPlus_Startup() Then Return SetError(2, 0, False)

            ; Declare variables that are used inside and outside the loop.
            Local $hImage, $nError, $nExtended

            ; Pseudo-loop so that cleanup will always happen.
            Do
                ; Load the image in it's original format.
                $hImage = _GDIPlus_ImageLoadFromFile($sPath)
                If $hImage = -1 Then
                    $nError = 3
                    ExitLoop
                EndIf

                ; Get the Bitmap converter CLSID.
                Local $sCLSID = _GDIPlus_EncodersGetCLSID("BMP")
                If Not $sCLSID Then
                    $nError = 4
                    ExitLoop
                EndIf

                ; If the conversion path isn't specified generate one from the input file.
                If Not $sConversionPath Then $sConversionPath = _PathMake($sDrive, $sDir, $sFile, ".bmp")

                ; Change the input path to the converted path.
                $sPath = $sConversionPath

                ; Save the output file to the new path.
                If Not _GDIPlus_ImageSaveToFileEx($hImage, $sPath, $sCLSID) Then
                    $nError = 5
                    ExitLoop
                EndIf
            Until True

            ; Release the image.
            _GDIPlus_ImageDispose($hImage)

            ; Shutdown GDI Plus.
            _GDIPlus_Shutdown()

            ; Abort if an error occurred in the loop.
            If $nError Then Return SetError($nError, $nExtended, False)
        EndIf

        ; Constant for the registry key where the wallpaper information is stored.
        Local Const $sRegKey = "HKEY_CURRENT_USER\Control Panel\Desktop"

        ; Tiling and centering/stretching are handled by two separate keys. If
        ; tiling then the style needs set to 0 and tile needs set to 1. Otherwise
        ; tile needs set to 0 and the style needs set to either 0 or 2.
        If $nStyle = $WALLPAPER_TILE Then
            RegWrite($sRegKey, "TileWallPaper", "REG_SZ", 1)
            RegWrite($sRegKey, "WallpaperStyle", "REG_SZ", 0)
        Else
            RegWrite($sRegKey, "TileWallPaper", "REG_SZ", 0)
            RegWrite($sRegKey, "WallpaperStyle", "REG_SZ", $nStyle)
        EndIf

        ; Constants for SystemParametersInfo().
        Local $SPI_SETDESKWALLPAPER = 20
        Local $SPIF_UPDATEINIFILE = 1
        Local $SPIF_SENDCHANGE = 2

        ; Create a structure to hold the path string.
        Local $vPath = DllStructCreate("wchar[" & StringLen($sPath) + 1 & "]")
        DllStructSetData($vPath, 1, $sPath)

        ; Update the wallpaper.
        Local $bResult = _WinAPI_SystemParametersInfo($SPI_SETDESKWALLPAPER, 0, DllStructGetPtr($vPath), BitOR($SPIF_UPDATEINIFILE, $SPIF_SENDCHANGE))

        ; Ensure the update was successful. If not set @error to a unique value.
        If Not $bResult Then Return SetError(6, 0, $bResult)
        Return $bResult
    EndFunc   ;==>WallpaperSet
#EndRegion WallpaperSet()

 

Edited by Melba23
Added code tags
Link to comment
Share on other sites

Once you've downloaded the pic, you can use this code to set it as wallpaper:

;===============================================================================
#interface "IActiveDesktop"
Global Const $sCLSID_ActiveDesktop = "{75048700-EF1F-11D0-9888-006097DEACF9}"
Global Const $sIID_IActiveDesktop = "{F490EB00-1240-11D1-9888-006097DEACF9}"
Global Const $tagIActiveDesktop = _
        "ApplyChanges hresult(dword);" & _
        "GetWallpaper hresult(wstr;uint;dword);" & _
        "SetWallpaper hresult(wstr;dword);" & _
        "GetWallpaperOptions hresult(struct*;dword);" & _
        "SetWallpaperOptions hresult(struct*;dword);" & _
        "GetPattern hresult(wstr;uint;dword);" & _
        "SetPattern hresult(wstr;dword);" & _
        "GetDesktopItemOptions hresult(struct*;dword);" & _
        "SetDesktopItemOptions hresult(struct*;dword);" & _
        "AddDesktopItem hresult(struct*;dword);" & _
        "AddDesktopItemWithUI hresult(hwnd;struct*;dword);" & _
        "ModifyDesktopItem hresult(struct*;dword);" & _
        "RemoveDesktopItem hresult(struct*;dword);" & _
        "GetDesktopItemCount hresult(int*;dword);" & _
        "GetDesktopItem hresult(int;struct*;dword);" & _
        "GetDesktopItemByID hresult(ulong_ptr;struct*;dword);" & _
        "GenerateDesktopItemHtml hresult(wstr;struct*;dword);" & _
        "AddUrl hresult(hwnd;wstr;struct*;dword);" & _
        "GetDesktopItemBySource hresult(wstr;struct*;dword);"
;===============================================================================

Global Const $AD_APPLY_ALL = 0x00000007

;;;;;;;;;;;;;;;;;;; Example ;;;;;;;;;;;;;;;;;;;;;;;;;;;
$oActiveDesktop = ObjCreateInterface($sCLSID_ActiveDesktop, $sIID_IActiveDesktop, $tagIActiveDesktop)

$sFile = FileOpenDialog("Select New Wallpaper", "", "Images (*.jpg;*.bmp;*.png;*.gif;*.whatever)") ; whatever
If $sFile Then
    $oActiveDesktop.SetWallpaper($sFile, 0)
    $oActiveDesktop.ApplyChanges($AD_APPLY_ALL)
EndIf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

 

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

  • Moderators

jimg,

A forum member of your long standing should know that we prefer people to use code tags when posting code - as the new forum update has changed the "user experience" a fair amount, you might like to refresh your memory here on how to use them.

M23

 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

jimg,

No problem - just a friendly nudge.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • 5 months later...
  • 4 years later...
  • Developers
5 minutes ago, mrstarc said:

@Iczer I have the same question?

Which part about posting your question in ONE place was unclear to you?

 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...