Sign in to follow this  
Followers 0
failedtocompile

Button Function navigate next file in directory (help please)

7 posts in this topic

Hi guys,

Anyone able to point me in the right direction on what function i could use for when a button is pressed in an autoit created gui that it will display the file in the gui.

Pretty much a need a next button and a previous button and the files will be image files. Just a warning I am nervers around arrays so speak slowley :graduated:

I have a basic layout shown below:

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiToolTip.au3>
#include <constants.au3>

$Wallpaper = "Path to directory" ;(iniread)
$Currentfile = "Current image file that is displayed in gui"
$GUI = GUICreate("", 500, 375, Default, Default, $WS_POPUPWINDOW)
$GuiPIC = GUICtrlCreatePic($Wallpaper, 0, 0, 500, 375, $WS_EX_TRANSPARENT)
$Label1 = GUICtrlCreateLabel("Set This Image as Wallpaper", 192, 344, 140, 17)
GUICtrlSetColor(-1, 0xff0000)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetCursor(-1, 0)
$Label2 = GUICtrlCreateLabel("Previous Image", 16, 344, 77, 17)
GUICtrlSetColor(-1, 0xff0000)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetCursor(-1, 0)
$Label3 = GUICtrlCreateLabel("Next Image", 416, 344, 58, 17)
GUICtrlSetColor(-1, 0xff0000)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetCursor(-1, 0)
GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $Label1
            MsgBox(0, "", "Set Wallpaper function")
            _SetWallpaper()
        Case $msg = $Label2
            MsgBox(0, "", "test")
    EndSelect
WEnd

Func _SetWallpaper()
RegWrite ("HKEY_CURRENT_USER\Control Panel\Desktop", "ConvertedWallpaper", "Reg_SZ", $Wallpaper)
RegWrite("HKCU\Control Panel\Desktop", "Wallpaper", "REG_SZ", $Wallpaper)
RegWrite("HKEY_CURRENT_USER\Control Panel\Desktop", "WallpaperStyle", "REG_SZ", "2")
sleep(30)
Run("RunDll32.exe USER32.DLL,UpdatePerUserSystemParameters ,1 ,True") ;Refreshes users desktop
sleep(30)
Run("RunDll32.exe USER32.DLL,UpdatePerUserSystemParameters ,1 ,True") Refreshes users desktop
    EndFunc
    

Func _Next()
    
EndFunc


Func _Previous()
    
    EndFunc

#cs
; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
;GUICTRLSETIMAGE()
#CE

thanks in advance

Share this post


Link to post
Share on other sites



I would use _FileListToArray($sPath [, $sFilter = "*" [, $iFlag = 0]]) to fill an array. The next / previous button then increment / decrement the index.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Hi guys,

Anyone able to point me in the right direction on what function i could use for when a button is pressed in an autoit created gui that it will display the file in the gui.

Pretty much a need a next button and a previous button and the files will be image files. Just a warning I am nervers around arrays so speak slowley :graduated:

I have a basic layout shown below:

thanks in advance

Something like this ? Posted Image

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiToolTip.au3>
#include <constants.au3>
#include <Math.au3>
#include <File.au3>
#Include <GDIPlus.au3>

Global $_I=1
Global $WallpaperDirectory = @WindowsDir & '\Web\Wallpaper' ; choose a directory
Global $WallpaperArray = _FileListToArray ( $WallpaperDirectory )
Global $GUI = GUICreate("", 500, 375, Default, Default, $WS_POPUPWINDOW)
Global $GuiCtrlPic = GUICtrlCreatePic($WallpaperDirectory & '\' & $WallpaperArray[1], 0, 0, 500, 375, $WS_EX_TRANSPARENT)

$Label1 = GUICtrlCreateLabel("Set This Image as Wallpaper", 182, 344, 140, 17)
GUICtrlSetColor(-1, 0xff0000)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetCursor(-1, 0)
$Label2 = GUICtrlCreateLabel("Previous Image", 16, 344, 77, 17)
GUICtrlSetColor(-1, 0xff0000)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetCursor(-1, 0)
$Label3 = GUICtrlCreateLabel("Next Image", 416, 344, 58, 17)
GUICtrlSetColor(-1, 0xff0000)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetCursor(-1, 0)
GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $Label1
            _SetWallpaper ( $WallpaperDirectory & '\' & $WallpaperArray[$_I] )
        Case $msg = $Label2
            _Previous ( )
        Case $msg = $Label3
            _Next ( )
    EndSelect
WEnd

Func _Next ( )
    $_I=$_I+1
    $_I = _Max ( _Min ( $_I, UBound ( $WallpaperArray ) -1 ), 1 )
    ConsoleWrite (  $_I & " next : " & $WallpaperDirectory & '\' & $WallpaperArray[$_I] & @Crlf )
    GUICtrlSetImage ( $GuiCtrlPic, $WallpaperDirectory & '\' & $WallpaperArray[$_I] )
EndFunc

Func _Previous ( )
    $_I=$_I-1
    $_I = _Max ( _Min ( $_I, UBound ( $WallpaperArray ) -1 ), 1 )   
    ConsoleWrite (  $_I & " previous : " & $WallpaperDirectory & '\' & $WallpaperArray[$_I] & @Crlf )   
    GUICtrlSetImage ( $GuiCtrlPic, $WallpaperDirectory & '\' & $WallpaperArray[$_I] )
EndFunc

Func _SetWallPaper ( $_WallPaperPath )
    If Not FileExists ( $_WallPaperPath ) Then Return       
    $_StringReplace = StringReplace ( $_WallPaperPath, ".jpg", ".bmp" )
    If @extended Then
        _GDIPlus_Startup ( )
        $_ImageLoad = _GDIPlus_ImageLoadFromFile ( $_WallPaperPath )
        $_CLSID = _GDIPlus_EncodersGetCLSID ( "BMP" )
        _GDIPlus_ImageSaveToFileEx ( $_ImageLoad, $_StringReplace, $_CLSID )
        _GDIPlus_ShutDown ( )
        $_WallPaperPath = $_StringReplace
    EndIf
    RegWrite ( "HKEY_CURRENT_USER\\Control Panel\\Desktop", "TileWallPaper", "REG_SZ", 0 )
    RegWrite ( "HKEY_CURRENT_USER\\Control Panel\\Desktop", "WallpaperStyle", "REG_SZ", 2 )
    DllCall ( "user32.dll", "int", "SystemParametersInfo", "int", 20, "int", 0, "str", $_WallPaperPath, "int", BitOR ( 1, 2 ) )
EndFunc ;==> _SetWallPaper ( )

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

I would use _FileListToArray($sPath [, $sFilter = "*" [, $iFlag = 0]]) to fill an array. The next / previous button then increment / decrement the index.

Thanks for your response Water,

But how would i Read from each index in the array, I have looked at _FileWriteFromArray but not sure how I can formulate it so it knew what index it was up to so when previous button is pressed it would descend back through the index and vice versa when pressing Next Button.

So if i was at image 5 of 20 images and i press previous it would display image 4.

I am a complete Beginner with Arrays I had a look at the Wiki but was unable to find how to navigate through a created array and siaplying a single record.

Thanks in advance

Share this post


Link to post
Share on other sites

This should work:

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiToolTip.au3>
#include <constants.au3>
#include <file.au3>

$Wallpaper = "C:\temp" ;(iniread)
Global $iPicIndex = 3
$aPics = _FileListToArray($Wallpaper, "*.jpg", 1)
If @error <> 0 Then
    MsgBox(16, "Wallpaper Selection", "No Wallpapers available")
    Exit
EndIf
$Currentfile = "Current image file that is displayed in gui"
$GUI = GUICreate("", 500, 375, Default, Default, $WS_POPUPWINDOW)
$GuiPIC = GUICtrlCreatePic($aPics[$iPicIndex], 0, 0, 500, 375, $WS_EX_TRANSPARENT) ; Display first picture
$Label1 = GUICtrlCreateLabel("Set This Image as Wallpaper", 192, 344, 140, 17)
GUICtrlSetColor(-1, 0xff0000)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetCursor(-1, 0)
$Label2 = GUICtrlCreateLabel("Previous Image", 16, 344, 77, 17)
GUICtrlSetColor(-1, 0xff0000)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetCursor(-1, 0)
$Label3 = GUICtrlCreateLabel("Next Image", 416, 344, 58, 17)
GUICtrlSetColor(-1, 0xff0000)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetCursor(-1, 0)
GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $Label1
            MsgBox(0, "", "Set Wallpaper function")
            _SetWallpaper()
        Case $msg = $Label2
            If $iPicIndex > 1 Then $iPicIndex = $iPicIndex - 1
            GUICtrlSetImage($GuiPIC, $aPics[$iPicIndex]) ; Display selected picture
        Case $msg = $Label3
            If $iPicIndex < Number($aPics[0])-1 Then $iPicIndex = $iPicIndex + 1
            GUICtrlSetImage($GuiPIC, $aPics[$iPicIndex]) ; Display selected picture
    EndSelect
WEnd

Func _SetWallpaper()
    RegWrite("HKEY_CURRENT_USER\Control Panel\Desktop", "ConvertedWallpaper", "Reg_SZ", $Wallpaper)
    RegWrite("HKCU\Control Panel\Desktop", "Wallpaper", "REG_SZ", $Wallpaper)
    RegWrite("HKEY_CURRENT_USER\Control Panel\Desktop", "WallpaperStyle", "REG_SZ", "2")
    Sleep(30)
    Run("RunDll32.exe USER32.DLL,UpdatePerUserSystemParameters ,1 ,True") ;Refreshes users desktop
    Sleep(30)
    Run("RunDll32.exe USER32.DLL,UpdatePerUserSystemParameters ,1 ,True") ; Refreshes users desktop
EndFunc   ;==>_SetWallpaper

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Something like this ? Posted Image

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiToolTip.au3>
#include <constants.au3>
#include <Math.au3>
#include <File.au3>
#Include <GDIPlus.au3>

Global $_I=1
Global $WallpaperDirectory = @WindowsDir & '\Web\Wallpaper' ; choose a directory
Global $WallpaperArray = _FileListToArray ( $WallpaperDirectory )
Global $GUI = GUICreate("", 500, 375, Default, Default, $WS_POPUPWINDOW)
Global $GuiCtrlPic = GUICtrlCreatePic($WallpaperDirectory & '\' & $WallpaperArray[1], 0, 0, 500, 375, $WS_EX_TRANSPARENT)

$Label1 = GUICtrlCreateLabel("Set This Image as Wallpaper", 182, 344, 140, 17)
GUICtrlSetColor(-1, 0xff0000)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetCursor(-1, 0)
$Label2 = GUICtrlCreateLabel("Previous Image", 16, 344, 77, 17)
GUICtrlSetColor(-1, 0xff0000)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetCursor(-1, 0)
$Label3 = GUICtrlCreateLabel("Next Image", 416, 344, 58, 17)
GUICtrlSetColor(-1, 0xff0000)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetCursor(-1, 0)
GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $Label1
            _SetWallpaper ( $WallpaperDirectory & '\' & $WallpaperArray[$_I] )
        Case $msg = $Label2
            _Previous ( )
        Case $msg = $Label3
            _Next ( )
    EndSelect
WEnd

Func _Next ( )
    $_I=$_I+1
    $_I = _Max ( _Min ( $_I, UBound ( $WallpaperArray ) -1 ), 1 )
    ConsoleWrite (  $_I & " next : " & $WallpaperDirectory & '\' & $WallpaperArray[$_I] & @Crlf )
    GUICtrlSetImage ( $GuiCtrlPic, $WallpaperDirectory & '\' & $WallpaperArray[$_I] )
EndFunc

Func _Previous ( )
    $_I=$_I-1
    $_I = _Max ( _Min ( $_I, UBound ( $WallpaperArray ) -1 ), 1 )   
    ConsoleWrite (  $_I & " previous : " & $WallpaperDirectory & '\' & $WallpaperArray[$_I] & @Crlf )   
    GUICtrlSetImage ( $GuiCtrlPic, $WallpaperDirectory & '\' & $WallpaperArray[$_I] )
EndFunc

Func _SetWallPaper ( $_WallPaperPath )
    If Not FileExists ( $_WallPaperPath ) Then Return       
    $_StringReplace = StringReplace ( $_WallPaperPath, ".jpg", ".bmp" )
    If @extended Then
        _GDIPlus_Startup ( )
        $_ImageLoad = _GDIPlus_ImageLoadFromFile ( $_WallPaperPath )
        $_CLSID = _GDIPlus_EncodersGetCLSID ( "BMP" )
        _GDIPlus_ImageSaveToFileEx ( $_ImageLoad, $_StringReplace, $_CLSID )
        _GDIPlus_ShutDown ( )
        $_WallPaperPath = $_StringReplace
    EndIf
    RegWrite ( "HKEY_CURRENT_USER\\Control Panel\\Desktop", "TileWallPaper", "REG_SZ", 0 )
    RegWrite ( "HKEY_CURRENT_USER\\Control Panel\\Desktop", "WallpaperStyle", "REG_SZ", 2 )
    DllCall ( "user32.dll", "int", "SystemParametersInfo", "int", 20, "int", 0, "str", $_WallPaperPath, "int", BitOR ( 1, 2 ) )
EndFunc ;==> _SetWallPaper ( )

Gewiz wakillon,

That is exactly what i was looking for, and I think I wouldnt of come to such a neat clean script for weeks.

thank you so much.

Regards

FTC

Share this post


Link to post
Share on other sites

Gewiz wakillon,

That is exactly what i was looking for, and I think I wouldnt of come to such a neat clean script for weeks.

thank you so much.

Regards

FTC

Glad to help you ! Posted Image


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

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