Meerecat Posted June 12, 2011 Share Posted June 12, 2011 With the help of some of the guys on this forum, I have finished my second script. This one is designed for encrypting confidential documents before you email them. Special thanks to Smartee, Mat and MHz. Opinions and Feedback welcomeMeerecat 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. Link to comment Share on other sites More sharing options...
JohnOne Posted June 12, 2011 Share Posted June 12, 2011 Quick look. In all your functions you run the Main function in case of back button I'm not sure if this causes recursion even though you delete the gui (whatever gui that may be. Would it make more sense to just Return from the function, or GUIDelete() and then return in those functions which create GUIs. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Meerecat Posted June 12, 2011 Author Share Posted June 12, 2011 How do I return from a function? I thought I was deleting the gui's. There is only one gui on screen at any one time. I'm not disagreeing with you, I just don't want to misunderstand. I want to learn Many Thanks 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. Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted June 12, 2011 Share Posted June 12, 2011 I'm not sure if this causes recursion even though you delete the gui (whatever gui that may be.I'm not sure what you mean. A function is a function, gui doesn't matter.How do I return from a function?Either let the function end naturally or use the "Return" keyword (as JohnOne said), see helpfile .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
JohnOne Posted June 12, 2011 Share Posted June 12, 2011 (edited) What I mean is, each time a function ends, or its task is complete, it returns to the last function it was called from. When you hit the back button in your case, it sort of calls the function again while the function called from it never ended (if you get me) this is called recursion (I think) Just an example of what I mean using extract from your code. expandcollapse popup_main() Func _main() ;GUIDelete() $Form1 = 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) $Pic1 = GUICtrlCreatePic($IMG_DIR & '\meerecat.jpg', 8, 58, 113, 150) $Label2 = GUICtrlCreateLabel("Meerecat File Guard", 66, 8, 155, 23) GUICtrlSetFont(-1, 12, 800, 0, "Leelawadee") $Pic2 = GUICtrlCreatePic($IMG_DIR & 'meerecat.jpg', 408, 45, 113, 150) $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 $nMsg = GUIGetMsg() Switch $nMsg 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 _about() EndSwitch WEnd EndFunc ;==>_main 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 GUIDelete($hWnd) Return 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") 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 In this case, your main GUI is always there and will never need to be re-drawn , just the called functions gui will be deleted Edited June 12, 2011 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Meerecat Posted June 12, 2011 Author Share Posted June 12, 2011 Thanks JohnOne Currently rewriting (or trying to) both the folder lock and file guard with this in mind 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. Link to comment Share on other sites More sharing options...
n1maS Posted April 21, 2012 Share Posted April 21, 2012 (edited) Nice Work! I'm new to AutoIt!! so tell me how do you do it?! tnx Edited April 21, 2012 by n1maS Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now