Jump to content

Covert TO AU3 Version"CLSID_ActiveDesktop"


Go to solution Solved by trancexx,

Recommended Posts

Posted (edited)

procedure SetWP(wp:string);


var

  hObj: IUnknown;

  ADesktop: IActiveDesktop;

begin

 begin

  hObj := CreateComObject(CLSID_ActiveDesktop);

  ADesktop := hObj as IActiveDesktop;

  ADesktop.SetWallpaper(PWideChar(WideString(wp)), 0);

  ADesktop.ApplyChanges(AD_APPLY_ALL or AD_APPLY_FORCE);

 end;

end;

Above is a delphi version Tool that that changes the wallpaper.but I don't know delphi well.could someone help me to convert it to AU3 version?

MSDN reference http://msdn.microsoft.com/en-us/library/bb776830%28v=vs.85%29.aspx

Edited by czyt

董小姐,你微笑的时候很美,就像安河桥下,清澈的水...

Posted (edited)

That would be to use ObjCreateInterface.

But I'm pretty sure you can do it easier by calling SystemParametersInfo WinAPI function with SPI_SETDESKWALLPAPER. But don't take my word for it.

Edited by trancexx

♡♡♡

.

eMyvnE

Posted (edited)

I searched a little bit, but I don't know how to convert COMPPOS to a known autoit struct type.

Global Const $AD_APPLY_SAVE = 0x00000001
Global Const $AD_APPLY_HTMLGEN = 0x00000002
Global Const $AD_APPLY_REFRESH = 0x00000004
Global Const $AD_APPLY_ALL = BitOR($AD_APPLY_SAVE, $AD_APPLY_HTMLGEN, $AD_APPLY_REFRESH)
Global Const $AD_APPLY_FORCE = 0x00000008

;random values here
$MAX_PATH = 256
$INTERNET_MAX_URL_LENGTH = 256
 
Global Const $tagCOMPONENT = "DWORD dwSize; DWORD dwID; int iComponentType; BOOL fChecked; BOOL fDirty; BOOL fNoScroll;" & _
      "COMPPOS cpPos; WCHAR wszFriendlyName[" & $MAX_PATH & "]; WCHAR wszSource[" & $INTERNET_MAX_URL_LENGTH & "];" & _
      "WCHAR wszSubscribedURL[" & $INTERNET_MAX_URL_LENGTH & "]; DWORD dwCurItemState; COMPSTATEINFO csiOriginal; COMPSTATEINFO csiRestored"
 
Func SetWP($wp)
   Local $ADesktop = ObjCreateInterface("{75048700-EF1F-11D0-9888-006097DEACF9}", "{F490EB00-1240-11D1-9888-006097DEACF9}", $tagCOMPONENT)
 
   $ADesktop.SetWallpaper($wp, 0)
   $ADesktop.ApplyChanges(BitOR($AD_APPLY_ALL, $AD_APPLY_FORCE))
EndFunc
Br, FireFox. Edited by FireFox
Posted

That would be to use ObjCreateInterface.

But I'm pretty sure you can do it easier by calling SystemParametersInfo WinAPI function with SPI_SETDESKWALLPAPER. But don't take my word for it.

I know the WinAPI function,but It can only set  a bmp file as wallpaper.

董小姐,你微笑的时候很美,就像安河桥下,清澈的水...

  • Solution
Posted (edited)

I know the WinAPI function,but It can only set  a bmp file as wallpaper.

In that case it would be something like this:

;===============================================================================
#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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
In that example you see declarations for CLSID, IID and Interface tag. That would normally go in some (standard) UDF and the code would be much more similar in size as delphi's. But unfortunatly AutoIt doesn't have those UDFs. Edited by trancexx

♡♡♡

.

eMyvnE

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
  • Recently Browsing   0 members

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