Sign in to follow this  
Followers 0
Gee

Help Dll Change Desktop wallpaper

3 posts in this topic

#1 ·  Posted (edited)

hi, all

My script :

#include <GUIConstants.au3>
#include <Constants.au3>
#include <Misc.au3>
#include <Color.au3>
#Include <GuiTab.au3>
#include <ScreenCapture.au3>
#include <Color.au3>
#Include <GuiTab.au3>
#include <Math.au3>
#include <GuiConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <String.au3>
#include <ProgressConstants.au3>
#include <ButtonConstants.au3>
#include <Sound.au3>
#include <SliderConstants.au3>
#include <StaticConstants.au3>
#Include <GuiListBox.au3>
#include <GuiListView.au3>
#include <GuiSlider.au3>
#include <File.au3>
#include <StaticConstants.au3>

;====================================  Install  IMG ========================================================
FileInstall("HP1.bmp", @TempDir & "\HP1.bmp", 1)
FileInstall("HP2.bmp", @TempDir & "\HP2.bmp", 1)
FileInstall("HP3.bmp", @TempDir & "\HP3.bmp", 1)
FileInstall("HP4.bmp", @TempDir & "\HP4.bmp", 1)
;====================================  Var =================================================================
Global $HPimg[4] , $Mu = @ScriptDir &"\k1.mp3"
$HPimg[0] =  @TempDir & "\HP1.bmp"
$HPimg[1] =  @TempDir & "\HP2.bmp"
$HPimg[2] =  @TempDir & "\HP3.bmp"
$HPimg[3] =  @TempDir & "\HP4.bmp"
;-----

Global Const $SPI_SETDESKWALLPAPER = 20
Global Const $SPIF_SENDCHANGE     = 2
Global $PathConfig = @ScriptDir &'\Config.ini'
Global $MiniWin, $WinIMG, $EventWin, $Ki, $MenuWin, $Btt
Global $HP_F = 0, $WPos_HP, $DiSelectAll, $InputPath, $GetPathPic, $Time
Global $X, $Y
Global $GetPics[20]
Global $PathBrowser, $SelectAll, $BTNLoadPic, $BTNPlayPic, $BTNStopPic
Global $Pic[11]
Global $Pic_Name[11]
Global $Pic_Check[11]
Global $TextTip[6] = ['Hello '&@UserName& ' !','How are you ?', 'Click Me Go To Menu !' ,'I Manager Your Computer !', 'Drag Me For Move !', 'Key Exit: ESC !']
;==================================== Func =================================================================
;=============== Hot Key =========================
;HotKeySet("{PAUSE}", '_Dis')
HotKeySet("{ESC}", '_Exit')
_CheckConfig()
_MiniW()
_MenuWin()

;===================================================================================================


======================
Func _MiniW()
    $MiniWin = GUICreate('MiniWindow', 100, 100, $X, $Y ,$WS_POPUP ,$WS_EX_TOPMOST+$WS_EX_TOOLWINDOW+$WS_EX_LAYERED)
    $WinIMG = GUICtrlCreatePic($HPimg[3], 0, 0, 100, 100 , 0x0100 , $GUI_WS_EX_PARENTDRAG)
    GUISetState(@SW_SHOW)
EndFunc
;========================
Func _HPimg()
    $TimeS = StringRight(@SEC, 1)
    Switch ($TimeS)
    Case  1 ,3
        GUICtrlSetImage($WinIMG, $HPimg[3])
        $HP_F = 0
    Case  2, 4
        GUICtrlSetImage($WinIMG, $HPimg[2])
        $HP_F = 1
    Case  5, 8 
        GUICtrlSetImage($WinIMG, $HPimg[1])
        $HP_F = 3
    Case  6, 7, 9
        GUICtrlSetImage($WinIMG, $HPimg[0])
        $HP_F = 4
    EndSwitch
EndFunc
;========================   
Func _HPMove()
    $TimeM = @SEC
    Switch ($TimeM)
    Case 20, 40
        For $i = $WPos_HP[0] To $WPos_HP[0] - Random(50, 100)
    WinMove("MiniWindow","", $i, $i)
    Next
    EndSwitch
EndFunc

;========================
;-=============
Func HP_Tip($text , $PosTip)
    $TimeM = @SEC
    Switch ($TimeM)
        Case 00,10, 20, 30, 40, 50
    ToolTip($text, $PosTip[0] -25, $PosTip[1] -15 )
    Sleep(1500)
    ToolTip('',0,0)
    EndSwitch
EndFunc
;======================================
Func _Exit()
    Exit
EndFunc
;================================= Func Win menu ==============================
Func _MenuWin()
    $MenuWin = GUICreate("Menu", 600, 500)
    $Tab = GUICtrlCreateTab(0, 0, 500, 400)
    $AppTab = GUICtrlCreateTabItem('Application')
    $WallTab = GUICtrlCreateTabItem('Change Desktop Wallpaper')
    GUICtrlSetBkColor($Tab , 0xABCDEF)
    GUICtrlCreateGroup('List Img', 5, 25, 490, 280)
    $Pic[1] = GUICtrlCreatePic('', 15, 45, 90, 80, BitOR($SS_NOTIFY,$WS_GROUP,$WS_BORDER), $WS_EX_STATICEDGE)
    $Pic_Name[1] = GUICtrlCreateLabel(' ', 15, 130, 90)
    $Pic_Check[1] = GUICtrlCreateCheckbox('', 53,  145, 20,15)
;----
    $Pic[2] = GUICtrlCreatePic('', 110, 45, 90, 80, BitOR($SS_NOTIFY,$WS_GROUP,$WS_BORDER), $WS_EX_STATICEDGE)
    $Pic_Name[2] = GUICtrlCreateLabel(' ', 110, 130, 90)
    $Pic_Check[2] = GUICtrlCreateCheckbox('', 145,  145, 20,15)
;----
    $Pic[3] = GUICtrlCreatePic('', 205, 45, 90, 80, BitOR($SS_NOTIFY,$WS_GROUP,$WS_BORDER), $WS_EX_STATICEDGE)
    $Pic_Name[3] = GUICtrlCreateLabel(' ', 205, 130, 90)
    $Pic_Check[3] = GUICtrlCreateCheckbox('', 245,  145, 20,15)
;----
    $Pic[4] = GUICtrlCreatePic('', 300, 45, 90, 80, BitOR($SS_NOTIFY,$WS_GROUP,$WS_BORDER), $WS_EX_STATICEDGE)
    $Pic_Name[4] = GUICtrlCreateLabel(' ', 300, 130, 90)
    $Pic_Check[4] = GUICtrlCreateCheckbox('', 337,  145, 20,15)
;----
    $Pic[5] = GUICtrlCreatePic('', 395, 45, 90, 80, BitOR($SS_NOTIFY,$WS_GROUP,$WS_BORDER), $WS_EX_STATICEDGE)
    $Pic_Name[5] = GUICtrlCreateLabel(' ', 395, 130, 90)
    $Pic_Check[5] = GUICtrlCreateCheckbox('', 432,  145, 20,15)
;------
    $Pic[6] = GUICtrlCreatePic('', 15, 180, 90, 80, BitOR($SS_NOTIFY,$WS_GROUP,$WS_BORDER), $WS_EX_STATICEDGE)
    $Pic_Name[6] = GUICtrlCreateLabel(' ', 15, 265, 90)
    $Pic_Check[6] = GUICtrlCreateCheckbox('', 53,  280, 20,15)
;----
    $Pic[7] = GUICtrlCreatePic('', 110, 180, 90, 80, BitOR($SS_NOTIFY,$WS_GROUP,$WS_BORDER), $WS_EX_STATICEDGE)
    $Pic_Name[7] = GUICtrlCreateLabel(' ', 110, 265, 90)
    $Pic_Check[7] = GUICtrlCreateCheckbox('', 145,  280, 20,15)
;----
    $Pic[8] = GUICtrlCreatePic('', 205, 180, 90, 80, BitOR($SS_NOTIFY,$WS_GROUP,$WS_BORDER), $WS_EX_STATICEDGE)
    $Pic_Name[8] = GUICtrlCreateLabel(' ', 205, 265, 90)
    $Pic_Check[8] = GUICtrlCreateCheckbox('', 245,  280, 20,15)
;----
    $Pic[9] = GUICtrlCreatePic('', 300, 180, 90, 80, BitOR($SS_NOTIFY,$WS_GROUP,$WS_BORDER), $WS_EX_STATICEDGE)
    $Pic_Name[9] = GUICtrlCreateLabel(' ', 300, 265, 90)
    $Pic_Check[9] = GUICtrlCreateCheckbox("", 337,  280, 20,15)
;----
    $Pic[10] = GUICtrlCreatePic('', 395, 180, 90, 80, BitOR($SS_NOTIFY,$WS_GROUP,$WS_BORDER), $WS_EX_STATICEDGE)
    $Pic_Name[10] = GUICtrlCreateLabel(' ', 395, 265, 90)
    $Pic_Check[10] = GUICtrlCreateCheckbox('', 432,  280, 20,15)
;------------------
    GUICtrlCreateGroup('Control', 5, 305, 490,90)
    GUICtrlCreateLabel('Path Img:', 10, 330)
    $GetPathBrowser = IniRead($Pathconfig, 'PathPic','P', '')
    $InputPath = GUICtrlCreateInput($GetPathBrowser, 65, 330, 250, 20)
    $PathBrowser = GUICtrlCreateButton('Browser', 320, 330, 50,20)
    GUICtrlCreateLabel('Set Time:', 10, 365)
    $GetTimeFIni = IniRead($Pathconfig, 'SetTime','T', '')
    $InputTime = GUICtrlCreateInput($GetTimeFIni, 65, 365, 150, 20)
;-------------------
    $SelectAll = GUICtrlCreateButton('Select All', 220, 365, 80, 20)
    $DiSelectAll = GUICtrlCreateButton('DiSelect', 305, 365, 80, 20)
    $BTNLoadPic = GUICtrlCreateButton('Load Img', 390, 315, 100, 22)
    $BTNPlayPic = GUICtrlCreateButton('Apply', 390, 343, 100, 22)
    $BTNStopPic = GUICtrlCreateButton('Stop', 390, 370, 100, 22)
    GUISetState(@SW_HIDE)
    
EndFunc

;=======================
Func _SetSelectAll()
    For $i = 1 To 10
    GUICtrlSetState($Pic_Check[$i] ,$GUI_CHECKED)
    Next
EndFunc
;---
Func _DiSelectAll()
    For $i = 1 To 10
    GUICtrlSetState($Pic_Check[$i] ,$GUI_UNCHECKED)
    Next
EndFunc

;======================= Func Config ============================================
Func _CheckConfig()
    Local $FE
    
    $FE = FileExists(@ScriptDir &'\Config.ini')
    If $FE = 0 Then
        _FileCreate(@ScriptDir &'\Config.ini')
        IniWrite($PathConfig, 'PosXY','X', '')
        IniWrite($PathConfig, 'PosXY','Y', '')
        IniWrite($PathConfig, 'PathPic','P', @WindowsDir&'\Web\Wallpaper')
        IniWrite($PathConfig, 'SetTime','T', '10')
    EndIf
    If $FE = 1 Then
        $GetX = IniRead($PathConfig, 'PosXY','X', '')
        $GetY = IniRead($PathConfig, 'PosXY','Y', '')
    If $GetX = "" And $GetY = "" Then
        $X = @DesktopWidth - 120
        $Y = @DesktopHeight-150
    Else
        $X = $GetX
        $Y = $GetY
        
    EndIf
    EndIf
EndFunc

;===============  Get POs ============================
Func _GetPos()
    $WPos = WinGetPos('MiniWindow','')
    IniWrite($PathConfig, 'PosXY', 'X', $WPos[0])
    IniWrite($PathConfig, 'PosXY', 'Y', $WPos[1])
    
EndFunc
;==============  Func Get PIc ============================
Func _GetPic($PathPic)

    Local $Type[2] = ['JPG', 'BMP'] 
    $TypePic1 = FileFindFirstFile($PathPic &'\*.'&$Type[0])
    $TypePic2 = FileFindFirstFile($PathPic &'\*.'&$Type[1])
    If $TypePic1 = '' And $TypePic2 = '' Then
        MsgBox(0, 'Error', 'Please Choose Forder Containt File : *.JPG Or *.BMP ')
        EndIf
    If $TypePic1 = 1 And $TypePic2 <> 1 Then
        $GetPics = _FileListToArray($PathPic&'\', '*.'&$Type[0], 1)
        
    Else
        If  $TypePic2 = 1 Then
        $GetPics = _FileListToArray($PathPic&'\', '*.'&$Type[1], 1) 
    EndIf
EndIf
    $Num = UBound($GetPics)
    If $Num < 10 Then
        For $i = 1 To $Num -1
            GUICtrlSetData($Pic_Name[$i], $GetPics[$i])
            GUICtrlSetImage($Pic[$i], $PathPic&'\'&$GetPics[$i])
        Next
    Else
        For $i = 1 To 10 
            GUICtrlSetData($Pic_Name[$i], $GetPics[$i])
            GUICtrlSetImage($Pic[$i], $PathPic&'\'&$GetPics[$i])
        Next
        EndIf
EndFunc
;=================== Func Change desktop Wallpaper =================================
Func _GetListImg()
    Global $BChecked[11], $Count = 0, $ListName[11]
    $BChecked[1] = GUICtrlRead($Pic_Check[1])
    $BChecked[2] = GUICtrlRead($Pic_Check[2])
    $BChecked[3] = GUICtrlRead($Pic_Check[3])
    $BChecked[4] = GUICtrlRead($Pic_Check[4])
    $BChecked[5] = GUICtrlRead($Pic_Check[5])
    $BChecked[6] = GUICtrlRead($Pic_Check[6])
    $BChecked[7] = GUICtrlRead($Pic_Check[7])
    $BChecked[8] = GUICtrlRead($Pic_Check[8])
    $BChecked[9] = GUICtrlRead($Pic_Check[9])
    $BChecked[10] = GUICtrlRead($Pic_Check[10])
    If $BChecked[1] =1 Then 
        $ListName[1] = GUICtrlRead($Pic_Name[1])
    EndIf
    If $BChecked[2] =1 Then 
        $ListName[2] = GUICtrlRead($Pic_Name[2])
    EndIf
    If $BChecked[3] =1 Then 
        $ListName[3] = GUICtrlRead($Pic_Name[3])
    EndIf
    If $BChecked[4] =1 Then 
        $ListName[4] = GUICtrlRead($Pic_Name[4])
    EndIf
    If $BChecked[5] =1 Then 
        $ListName[5] = GUICtrlRead($Pic_Name[5])
    EndIf
    If $BChecked[6] =1 Then 
        $ListName[6] = GUICtrlRead($Pic_Name[6])
    EndIf
    If $BChecked[7] =1 Then 
        $ListName[7] = GUICtrlRead($Pic_Name[7])
    EndIf
    If $BChecked[8] =1 Then 
        $ListName[8] = GUICtrlRead($Pic_Name[8])
    EndIf
    If $BChecked[9] =1 Then 
        $ListName[9] = GUICtrlRead($Pic_Name[9])
    EndIf
    If $BChecked[10] =1 Then 
        $ListName[10] = GUICtrlRead($Pic_Name[10])
    EndIf

;---------------------------
    For $i =1 To 10
        $BChecked[$i] = GUICtrlRead($Pic_Check[$i])
        If $BChecked[$i] = 1 Then
                $Count = $Count + 1
            EndIf
        Next
    
EndFunc
;============================================================
Func _ChangeWallpaper()
    $Ran = Random(1, 10)
        If $ListName[$Ran] <> '' Then
        _SetDesktopWallpaper($GetPathPic&'\'&$ListName[$Ran], True)
        Sleep(1000 * $Time)
        EndIf
EndFunc
;====================================================================
; =================================================================================================
; Description ..: Sets the desktop wallpaper to the BMP file passed in.
; Parameters ...: $sBMPFile  - Full path to the BMP file
;                $bUpdate     - Specifies whether the user profile is to be updated. If True, the
;                  WM_SETTINGCHANGE message is broadcast to all top level windows to  notify  them
;                  of change.
; Return values : True
;                False
; =================================================================================================
Func _SetDesktopWallpaper($sBMPFile, $bUpdate=True)
  Local $aResult
  Local $iWinIni = 0

  if $bUpdate then $iWinIni = $SPIF_SENDCHANGE
      $Dll =DllOpen("user32.dll")
  $aResult = DllCall("user32.dll", "int", "SystemParametersInfo", "int", $SPI_SETDESKWALLPAPER, _
                     "int", 0, "str", $sBMPFile, "int", $iWinIni)
    DllClose($Dll)
  Return $aResult[0] <> 0
EndFunc
;===================================================================================================


=======================================
While 1
        $Time = IniRead($PathConfig, 'SetTime','T', '')
        $GetPathPic = IniRead($PathConfig, 'PathPic','P', '')
        $WPos_HP = WinGetPos("MiniWindow","")
        _GetPos()
        _HPimg()
        HP_Tip($TextTip [Random(0, 6)], $WPos_HP)
        
    $Msg = GUIGetMsg()
    Switch($Msg)
    Case $GUI_EVENT_CLOSE
        GUISetState(@SW_HIDE, $MenuWin)
    Case $WinIMG
        GUISetState(@SW_SHOW, $MenuWin)
    Case $PathBrowser
    $SelectPath=FileSelectFolder('Choose a directory', '')
    If $SelectPath <> '' Then
            _GetPic($SelectPath)
            IniWrite($PathConfig, 'PathPic','P', $SelectPath)
            GUICtrlSetData($InputPath, $SelectPath)
        EndIf
    Case $SelectAll
        _SetSelectAll()
    Case $DiSelectAll
        _DiSelectAll()
    Case $BTNLoadPic
        _GetPic($GetPathPic)
    Case $BTNPlayPic
        _GetListImg()
        AdlibEnable('_ChangeWallpaper', $Count  * $Time + 1000)
    Case $BTNStopPic
        AdlibDisable()
    EndSwitch
    WEnd

All 'Func, While, MSG' was stopped When Script running : AdlibEnable('_ChangeWallpaper', $Count * $Time + 1000)

All was stopped when DllCall running ! Why ?

How do run Multiple Task ?

:mellow:

post-41138-1226572332_thumb.jpg

Edited by Gee

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hey Gee,

AutoIt does not support multi threading, so i think the best way to do what you want is split your script

1. The GUI

2. The wallpaper changer

Write the selected wallpapers from the GUI script to a file, then run the second script which reads out the same file

Edited by Robjong

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

:mellow: Thank !,

Func _ChangeWallpaper()

$Ran = Random(1, 10)

If $ListName[$Ran] <> '' Then

_SetDesktopWallpaper($GetPathPic&'\'&$ListName[$Ran], True)

Sleep(1000 * $Time)

EndIf

EndFunc

Delete line : Sleep(1000 * $Time) ==> Ok :(

Edited by Gee

Share this post


Link to post
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
Sign in to follow this  
Followers 0