Jump to content

Recommended Posts

Posted (edited)

I want to create simple picture viewer  (use Direction keys (left right) to next image), but can't run.

What happen with this program?!!! :  :    Thanks everyone!!!!

#include <GUIConstants.au3>

Dim $Pick[5], $pics = 4

$Form1 = GUICreate("NextImage", 414, 305, 246, 194)
$Pick[1]= GUICtrlCreatePic(@ScriptDir&"\pic\Desert.jpg", 8, 8, 393, 233)
$Pick[2]= GUICtrlCreatePic(@ScriptDir&"\pic\Jellyfish.jpg", 8, 8, 393, 233)
GUICtrlSetState( -1, $GUI_HIDE)
$Pick[3]= GUICtrlCreatePic(@ScriptDir&"\pic\Tulips.jpg", 8, 8, 393, 233)
GUICtrlSetState( -1, $GUI_HIDE)
$Pick[4]= GUICtrlCreatePic(@ScriptDir&"\pic\Lighthouse.jpg", 8, 8, 393, 233)
GUICtrlSetState( -1, $GUI_HIDE)
$notice = GUICtrlCreateLabel("Picture #1", 20, 258, 100, 30)
GUICtrlSetFont( -1, 15, 700)
$Back= GUICtrlCreateButton("Back", 160, 256, 97, 41)
$Next = GUICtrlCreateButton("Next", 264, 256, 97, 41)

HotKeySet("{RIGHT}" , "RIGHT()")
HotKeySet("{LEFT}" , "LEFT()")

GUISetState(@SW_SHOW)



While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = -3
        ExitLoop

    Case $msg = $Back
        $set = -1
        get_pic($set)
        
    Case $msg = $Next
        $set = 1
        get_pic($set)

Case  HotKeySet("{down}")
        $set = -1
        get_pic($set)
        



    Case Else
    EndSelect
WEnd
Exit




Func get_pic($t)
    For $x = 1 to $pics
        $State = GUICtrlGetState($pick[$x])
        If $State = 80 Then
        If $x = 1 And $t = -1 Then Return
        If $x = $pics And $t = 1 Then Return
        Guictrlsetstate($Pick[$x], $GUI_HIDE)
        Guictrlsetstate($Pick[$x + $set], $GUI_SHOW)
        GUICtrlSetData($notice, "Picture #" & $x + $set)
        Return
        EndIf
    Next
EndFunc


Func LEFT()
$set = -1
    get_pic($set)
EndFunc

Func RIGHT()
$set = 1
    get_pic($set)
EndFunc
Edited by peggy
Posted

hello peggy, welcome to AutoIt and to the forum!

  On 11/19/2014 at 6:18 AM, peggy said:

What happen with this program?

 

you tell us. what exactly does not work? do you get any error messages? have you checked @error or the return values of your function calls?

but that's for next time. for now, your issues are:

1) syntax of HotKeySet() - the name of the function needs not the brackets. like this:

HotKeySet("{RIGHT}" , "RIGHT")
HotKeySet("{LEFT}" , "LEFT")

2) the variable $set is used globally, but is not declared as such, so any function treats it as a different variable. add this at the top of your script:

Global $set

you may have other issues as well, but start by fixing these and see how it goes.

Signature - my forum contributions:

  Reveal hidden contents

 

Posted

Thank you ,orbs!!!

I tried to modify hothey and plus $ set at the top of my script, when I use  right key is OK,but use left key,this program can't run. 

Thank you for your help!

My code right know is:

#include <GUIConstants.au3>

Dim $Pick[5], $pics = 4
Global  $set
$Form1 = GUICreate("NextImage", 414, 305, 246, 194)
$Pick[1]= GUICtrlCreatePic(@ScriptDir&"\pic\Desert.jpg", 8, 8, 393, 233)
$Pick[2]= GUICtrlCreatePic(@ScriptDir&"\pic\Jellyfish.jpg", 8, 8, 393, 233)
GUICtrlSetState( -1, $GUI_HIDE)
$Pick[3]= GUICtrlCreatePic(@ScriptDir&"\pic\Tulips.jpg", 8, 8, 393, 233)
GUICtrlSetState( -1, $GUI_HIDE)
$Pick[4]= GUICtrlCreatePic(@ScriptDir&"\pic\Lighthouse.jpg", 8, 8, 393, 233)
GUICtrlSetState( -1, $GUI_HIDE)
$notice = GUICtrlCreateLabel("Picture #1", 20, 258, 100, 30)
GUICtrlSetFont( -1, 15, 700)

$Back= GUICtrlCreateButton("Back", 160, 256, 97, 41)
$Next = HotKeySet("{RIGHT}" , "RIGHT")

GUISetState(@SW_SHOW)



While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = -3
        ExitLoop

    Case $msg = $Back
        $set = -1
        get_pic($set)
    Case $msg = $Next
        $set = 1
        get_pic($set)
 Case Else
    EndSelect
WEnd
Exit

Func get_pic($t)
    For $x = 1 to $pics
        $State = GUICtrlGetState($pick[$x])
        If $State = 80 Then
        If $x = 1 And $t = -1 Then Return
        If $x = $pics And $t = 1 Then Return
        Guictrlsetstate($Pick[$x], $GUI_HIDE)
        Guictrlsetstate($Pick[$x + $set], $GUI_SHOW)
        GUICtrlSetData($notice, "Picture #" & $x + $set)
        Return
        EndIf
    Next
EndFunc

Func LEFT()
MsgBox(1,'title',$Back)
 $msg = $Back
EndFunc

Func RIGHT()
  $msg = $Next
EndFunc
Posted (edited)

It's not the solution for your issue, but you can use GUISetAccelerators instead of HotKeySet

#include <File.au3>
#include <GUIConstants.au3>


Global $sPicPath = "C:\Windows\Web\Wallpaper\Architecture"
Global $aPics = _FileListToArray($sPicPath, "*.jpg", 1, True)
If NOT IsArray($aPics) Then Exit MsgBox(16, "Error", "No picture found in " & $sPicPath)

Global $iCurrent = 1

GUICreate("Picture Viewer", 820, 700)
GUISetBkColor(0)

Global $ID_Pic = GUICtrlCreatePic($aPics[1], 10, 10, 800, 600)
Global $ID_Previous = GUICtrlCreateButton("Previous", 50, 620, 200, 30)
Global $ID_Next = GUICtrlCreateButton("Next", 570, 620, 200, 30)
GUICtrlSetFont($ID_Previous, 15, 700)
GUICtrlSetFont($ID_Next, 15, 700)


Local $aAccelKeys[2][2] = [["{LEFT}", $ID_Previous],["{RIGHT}", $ID_Next]]
GUISetAccelerators($aAccelKeys)

GUICtrlSetState($ID_Previous, $GUI_DISABLE)

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case -3
            Exit
        Case $ID_Previous
            If $iCurrent > 1 Then _Previous()
        Case $ID_Next
            If $iCurrent < UBound($aPics) - 1  Then _Next()
    EndSwitch
    
    
    Sleep(10)
WEnd

Func _Previous()
    $iCurrent -= 1
    If $iCurrent = 1 Then GUICtrlSetState($ID_Previous, $GUI_DISABLE)
    GUICtrlSetState($ID_Next, $GUI_ENABLE)
    GUICtrlSetImage($ID_Pic, $aPics[$iCurrent])
EndFunc

Func _Next()
    $iCurrent += 1
    If $iCurrent = UBound($aPics) - 1 Then GUICtrlSetState($ID_Next, $GUI_DISABLE)
    GUICtrlSetState($ID_Previous, $GUI_ENABLE)
    GUICtrlSetImage($ID_Pic, $aPics[$iCurrent])
EndFunc

Oups, edited...

Edited by jguinch
Posted

peggy, you messed-up a part of the code. you started with this:

$Back= GUICtrlCreateButton("Back", 160, 256, 97, 41)
$Next = GUICtrlCreateButton("Next", 264, 256, 97, 41)

HotKeySet("{RIGHT}" , "RIGHT()")
HotKeySet("{LEFT}" , "LEFT()")

which i recommended to remove the brackets and change into this:

$Back= GUICtrlCreateButton("Back", 160, 256, 97, 41)
$Next = GUICtrlCreateButton("Next", 264, 256, 97, 41)

HotKeySet("{RIGHT}" , "RIGHT")
HotKeySet("{LEFT}" , "LEFT") 

but now you have this:

$Back= GUICtrlCreateButton("Back", 160, 256, 97, 41)
$Next = HotKeySet("{RIGHT}" , "RIGHT") 

:huh2:

Signature - my forum contributions:

  Reveal hidden contents

 

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...