Jump to content
Sign in to follow this  
Meerecat

Problem with _ResourceSetImageToCtrl

Recommended Posts

Meerecat

Hello

I use _ResourceSetImageToCtrl to insert an image in a GUI. This works great. My problem is under certain circumstances it doesn't work.

I use this in my _main() gui. When I call the _encrypt() or _decrypt() function in my script and go straight back the image shows. However if I actually complete the encrypt or decrypt the image then dissapears from the main function.

Here is my _main() code:

Func _main()
    GUIDelete()
    $prompt = GUICreate("Meerecat File Guard", 288, 287)
    GUISetBkColor(0xFFFFFF)
    $MainMenu = GUICtrlCreateMenu("&Main Menu")
    $encrypt_menu = GUICtrlCreateMenuItem("&Encrypt File", $MainMenu)
    $decrypt_menu = GUICtrlCreateMenuItem("&Decrypt File", $MainMenu)
    $exit_menu = GUICtrlCreateMenuItem("E&xit", $MainMenu)
    $HelpMenu = GUICtrlCreateMenu("&Help")
    $contact_menu = GUICtrlCreateMenuItem("&Contact Us", $HelpMenu)
    $about_menu = GUICtrlCreateMenuItem("&About", $HelpMenu)
    GUICtrlCreatePic("meerecat.jpg", 8, 58, 113, 150)
    _ResourceSetImageToCtrl($pic1, "MEERECAT_JPG_1") ; set JPG image to picture control from resource
    $Label2 = GUICtrlCreateLabel("Meerecat File Guard", 66, 8, 155, 23)
    GUICtrlSetFont(-1, 12, 800, 0, "Leelawadee")
    $encrypt = GUICtrlCreateButton("Encrypt File", 155, 86, 100, 30)
    GUICtrlSetFont(-1, 10, 800, 0, "Leelawadee")
    $decrypt = GUICtrlCreateButton("Decrypt File", 155, 135, 100, 30)
    GUICtrlSetFont(-1, 10, 800, 0, "Leelawadee")
    GUISetState(@SW_SHOW)

    While 1
        $aMsg = GUIGetMsg(1) ; Use advanced parameter to get array
        Switch $aMsg[1] ; check which GUI sent the message
            Case $prompt
                Switch $aMsg[0]
            Case $GUI_EVENT_CLOSE
                Exit
            Case $encrypt
                _encrypt()
            Case $decrypt
                _decrypt()
            Case $encrypt_menu
                _encrypt()
            Case $decrypt_menu
                _decrypt()
            Case $contact_menu
                ShellExecute("http://www.meerecat-itservices.co.uk/contact-us")
            Case $exit_menu
                Exit
            Case $about_menu
                GUICtrlSetState($about_menu, $GUI_DISABLE)
                _about()
            EndSwitch
        Case $about_gui
            Switch $aMsg[0]
                Case $GUI_EVENT_CLOSE ; If we get the CLOSE message from this GUI - we just delete the GUI <<<<<<<<<<<<<<<
                GUIDelete($about_gui)
                GUICtrlSetState($about_menu, $GUI_ENABLE)

    EndSwitch
    EndSwitch
    WEnd
EndFunc   ;==>_main

And my _encrypt() code:

Func _encrypt()
    GUIDelete()
    $hWnd = GUICreate("Meerecat File Guard", 288, 287)
    GUISetBkColor(0xFFFFFF)
    $MainMenu = GUICtrlCreateMenu("&Main Menu")
    $encrypt_menu = GUICtrlCreateMenuItem("Encrypt File", $MainMenu)
    $decrypt_menu = GUICtrlCreateMenuItem("Decrypt File", $MainMenu)
    $exit_menu = GUICtrlCreateMenuItem("Exit", $MainMenu)
    $HelpMenu = GUICtrlCreateMenu("&Help")
    $contact_menu = GUICtrlCreateMenuItem("Contact Us", $HelpMenu)
    $about_menu = GUICtrlCreateMenuItem("About", $HelpMenu)
    $Label2 = GUICtrlCreateLabel("Meerecat File Guard", 66, 8, 155, 23)
    GUICtrlSetFont(-1, 12, 800, 0, "Leelawadee")
    $Label3 = GUICtrlCreateLabel("Meerecat IT Services  ©2011", 376, 224, 145, 17)
    GUICtrlSetFont(-1, 6, 400, 0, "MS Sans Serif")
    $back = GUICtrlCreateButton("Back", 155, 231, 100, 30)
    GUICtrlSetFont(-1, 10, 800, 0, "Leelawadee")
    $InFileLabel = GUICtrlCreateLabel("Input File", 8, 56, 56, 19)
    GUICtrlSetFont(-1, 10, 400, 0, "Leelawadee")
    $InFileInput = GUICtrlCreateInput("", 8, 72, 225, 21)
    $OutFileLabel = GUICtrlCreateLabel("Output File", 8, 110, 67, 19)
    GUICtrlSetFont(-1, 10, 400, 0, "Leelawadee")
    $OutFileInput = GUICtrlCreateInput("", 8, 123, 225, 21)
    $InFileButton = GUICtrlCreateButton(". . .", 240, 72, 30, 25)
    $OutFileButton = GUICtrlCreateButton(". . .", 240, 123, 30, 25)
    $PasswordLabel = GUICtrlCreateLabel("Encryption Password", 8, 159, 125, 19)
    GUICtrlSetFont(-1, 10, 400, 0, "Leelawadee")
    $PasswordInput = GUICtrlCreateInput("", 7, 175, 225, 21)
    $EncryptButton = GUICtrlCreateButton("Encrypt", 35, 230, 100, 30)
    GUICtrlSetFont(-1, 10, 800, 0, "Leelawadee")

    If ($CmdLine[0] > 0) Then ;Used to prefill input areas
        GUICtrlSetData($InFileInput, $CmdLine[1])
        GUICtrlSetData($OutFileInput, $CmdLine[1] & $Extension)
    EndIf
    GUISetState(@SW_SHOW)



    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $back
                _main()
            Case $encrypt_menu
                _encrypt()
            Case $decrypt_menu
                _decrypt()
            Case $contact_menu
                ShellExecute("http://www.meerecat-itservices.co.uk/contact-us")
            Case $exit_menu
                Exit
            Case $about_menu
                _about()
            Case $InFileButton
                $file = FileOpenDialog("Input File", "", "All files (*.*;)")
                If $file <> "" Then
                    GUICtrlSetData($InFileInput, $file)
                    GUICtrlSetData($OutFileInput, $file & $Extension)
                EndIf
            Case $OutFileButton
                $file = FileSaveDialog("Output file", "", "Any file (*.*;)")
                If $file <> "" Then GUICtrlSetData($OutFileInput, $file)

            Case $EncryptButton
                $infile = GUICtrlRead($InFileInput)
                If Not FileExists($infile) Then
                    MsgBox(16, "Error", "Input file doesn't exists!")
                    ContinueLoop
                EndIf


                $outfile = GUICtrlRead($OutFileInput)
                If $outfile = "" Then
                    MsgBox(16, "Error", "Please input a output file")
                    ContinueLoop
                EndIf


                $password = GUICtrlRead($PasswordInput)
                If $password = "" Then
                    MsgBox(16, "Error", "Please input a password")
                    ContinueLoop
                EndIf

                AdlibRegister("Update", 333)
                $success = _Crypt_EncryptFile($infile, $outfile, $password, $CALG_RC4)
                If $success Then
                    MsgBox(0, "Success", "Operation succeeded")
                    _main()
                Else
                    Switch @error
                        Case 1
                            MsgBox(16, "Fail", "Failed to create key")
                        Case 2
                            MsgBox(16, "Fail", "Couldn't open source file")
                        Case 3
                            MsgBox(16, "Fail", "Couldn't open destination file")
                        Case 4 Or 5
                            MsgBox(16, "Fail", "Encryption error")
                    EndSwitch
                EndIf

                AdlibUnRegister("Update")
                WinSetTitle($hWnd, "", "File Encrypter")
        EndSwitch
    WEnd
EndFunc   ;==>_encrypt

Just in case it's a problem somewhere else in the code, I've attached the full au3 file. Many thanks for any help.

LeeMeerecat File Guard.au3


Lack of planning on your part does not constitute an emergency on my part.-The biggest idiot can ask questions the smartest man cannot answer.

Share this post


Link to post
Share on other sites
Meerecat

Any suggestions?

Much obliged, Lee


Lack of planning on your part does not constitute an emergency on my part.-The biggest idiot can ask questions the smartest man cannot answer.

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  

×