RobRod Posted January 13, 2014 Share Posted January 13, 2014 (edited) Hi all, I wrote a script (actually I found it on the internets and changed it to my needs) that makes a partial screenshot of the active window. That's it, the app just does a screenshot and saves it as .jpg on the working directory. However after the .jpg is saved, the exe shuts down without any error or warning. Anyone can tell me why is that? The dll is needed to make the screenshot. I'm kinda new to autoit, so I tried to comment everything "exit" related (put a ; in front), but the app still shuts down after taking one screenshot. EDIT: code here expandcollapse popup; ------------------------------------------------------------------------------ ; ; AutoIt Version: 3.1.1.101 ; Language: Deutsch ; Platform: Win2k / XP ; Author: Pastl ; ; Script Function: ScreenShot - Tool ; ; ; ------------------------------------------------------------------------------ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; #Include <Constants.au3> #include <GUIConstants.au3> #NoTrayIcon ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;AutoItSetOption("MustDeclareVars", 1) AutoItSetOption("MouseCoordMode", 1) ;AutoItSetOption("PixelCoordMode", 0) ;AutoItSetOption("RunErrorsFatal", 0) ;AutoItSetOption("TrayIconDebug", 1) ;AutoItSetOption("WinTitleMatchMode", 4) Opt("TrayMenuMode",1) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;HotKeySet("{F1}", "DesktopScreenShot") HotKeySet("{F2}", "ActiveWindowScreenShot") ;HotKeySet("{F3}", "AuswahlScreenShot") HotKeySet("{ESC}", "_Exit") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Make Tray menu: ; Erstellen des Tray-Menu's: ; -------------------------------- $info = TrayCreateItem("Über") $hilfe = TrayCreateItem("Hilfe") TrayCreateItem("") $exit = TrayCreateItem("Exit") TraySetState() ;~ TrayTip("ScreenShot-Tool:", "zum Erstellen von Windows ScreenShots.", 5, 1) While 1 $msg = TrayGetMsg() Select Case $msg = 0 ContinueLoop Case $msg = $info MsgBox(64, "Info:", "Windows SreenShot-Tool" &@Lf& "Version: 1.0.0" &@Lf& "erstellt mit AutoIt 3" &@Lf& "" &@Lf& "© 2006 by Pastl", 15) Case $msg = $hilfe Msgbox(64, "Info:", "{F1} erstellt einen ScreenShot des kompletten Desktops." &@Lf& "{F2} erstellt einen Screenshot des aktiven Fensters." &@Lf& "{F3} erstellt einen Screenshot des gewählten Bereiches." &@Lf& "-------------------------------------------------------------" &@lf& "{Esc} beendet das Programm.", 10) Case $msg = $exit _Exit() EndSelect WEnd Exit ; Screenshot of active Window: ; Screenshot des aktiven Fensters: ; ---------------------------------------- Func ActiveWindowScreenShot() ;SoundPlay(@ScriptDir & "klick.wav", 1) ;If Not FileExists ("screenshots") Then DirCreate ("screenshots") Local $Cwin1 = WinGetHandle("") Local $Cwin2 = WinGetPos($Cwin1) Local $Quality = 100 ;If $Quality = -1 Then ; Local $SaveAs = ".bmp" ;Else Local $SaveAs = ".jpg" ;EndIf Local $CaptureDirectory = "Picture_" Local $CaptureFile = @YEAR & "-" & @MDAY & "-" & @MON & "_" & @HOUR & "." & @MIN &"." & @SEC & $SaveAs DllCall("captdll.dll", "int", "CaptureRegion", "str", $CaptureDirectory & $CaptureFile, "int", $Cwin2[0] + 8, "int", $Cwin2[1] + 50, "int", 640, "int", 480, "int", $Quality) If @error Then MsgBox(262160,"Fehler","Es wurde kein Screenshot erstellt!",4) ; nach $Capturefile, "int,", ... ; 1. Wert = Einrückung von links ; 2. Wert = Einrückung von oben ; 3. Wert = Breite des Screenshots ; 4. Wert = Höhe des Screenshots EndFunc ; Exit program: ; Programm beenden: ;------------------------ Func _Exit() ;SoundPlay(@ScriptDir & "Exit.wav", 1) Exit EndFunc Func _IsPressed($s_hexKey, $v_dll = 'user32.dll') ; $hexKey must be the value of one of the keys. ; _Is_Key_Pressed will return 0 if the key is not pressed, 1 if it is. Local $a_R = DllCall($v_dll, "int", "GetAsyncKeyState", "int", '0x' & $s_hexKey) If Not @error And BitAND($a_R[0], 0x8000) = 0x8000 Then Return 1 Return 0 EndFunc test.au3captdll.dll Edited January 13, 2014 by RobRod Link to comment Share on other sites More sharing options...
l3ill Posted January 13, 2014 Share Posted January 13, 2014 Hi RobRod, Welcome to the forum! Please post your code as explained in my signature. :-) Bill My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
RobRod Posted January 13, 2014 Author Share Posted January 13, 2014 Done, sorry. Link to comment Share on other sites More sharing options...
Danp2 Posted January 13, 2014 Share Posted January 13, 2014 Try running the code in Scite and posting the output window results here. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
l3ill Posted January 13, 2014 Share Posted January 13, 2014 Hi Again, I would like to make a suggestion; it seems to me you want to learn AutoIT from playing around with this code, and that is fine. But You may have more fun and more success starting from "scratch" with the example from the Help File. It is much shorter and easier to understand than what you have there and essentially will do the same thing after adding a few small tweaks. _ScreenCapture_CaptureWnd IMHO it is easier to start small and work to big than the other way around... Bill My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
bogQ Posted January 13, 2014 Share Posted January 13, 2014 (edited) autoit 3.1.1.101 ? thats like from 2006 just to b on safe side do you have >captdll.dll on your computer? and your picture is saved? and no errors or msgboxes popup what does your scite console output say? l3ill is correct, there are GDI funcs that shud replace that, so open help file and start testing to adapt your code Edited January 13, 2014 by bogQ TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost. Link to comment Share on other sites More sharing options...
RobRod Posted January 15, 2014 Author Share Posted January 15, 2014 (edited) I'm not new to programming, so I don't see a reason to start from scratch if I'm able to analyze the script I found. With Scite Output you mean if I just use "Compile Script"? Here we go >"C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /ShowGui /in "C:\Users\me\Desktop\SCtest\autoit\selbst\test.au3" +>10:18:21 Starting AutoIt3Wrapper v.2.1.4.0 SciTE v.3.3.7.0 ; Keyboard:00000407 OS:WIN_7/Service Pack 1 CPU:X64 OS:X64 Environment(Language:0407 Keyboard:00000407 OS:WIN_7/Service Pack 1 CPU:X64 OS:X64) -> No changes made.. >Running AU3Check (1.54.22.0) from:C:\Program Files (x86)\AutoIt3 +>10:18:24 AU3Check ended.rc:0 >Running:(3.3.8.1):C:\Program Files (x86)\AutoIt3\aut2exe\aut2exe.exe /in "C:\Users\me\Desktop\SCtest\autoit\selbst\test.au3" /out "C:\Users\me\AppData\Local\AutoIt v3\Aut2exe\~AU3mldqaap.exe" /nopack /comp 2 +>10:18:25 Aut2exe.exe ended.C:\Users\me\AppData\Local\AutoIt v3\Aut2exe\~AU3mldqaap.exe. rc:0 +>10:18:25 Created program:C:\Users\me\Desktop\SCtest\autoit\selbst\test.exe >Exit code: 0 Time: 4.508 I have AutoIt v3.3.8.1. I have a captdll.dll (I included it in the opening post). It feels like im 99 % there to get it working. There are no error messages or pop ups. The Image is saved, yes. And after this first Image is saved, the exe just shuts down. That one Image looks fine tho. Edited January 15, 2014 by RobRod Link to comment Share on other sites More sharing options...
l3ill Posted January 15, 2014 Share Posted January 15, 2014 (edited) Hi Again, please forgive my assumption The console read out bogQ was referring to is the one that happens when running the code from SciTE, not compiling... And I still think you would be better off installing the newest version of Autoit and using the updated functions. just my $ 0.02 cya, Bill Edited January 15, 2014 by l3ill My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
bogQ Posted January 15, 2014 Share Posted January 15, 2014 (edited) The reason i was askingfor no errors or msgboxes popup whas to determan what is happening coz that code shud result in a crash with crash error box and your saying that nothing happends and that it save your pic and exit, checking do you have dll on correct place in correct dir is just to b shure coz @error will not work in case of crash. what does your scite console output say, im asking that to realize what version of autoit are you using (script was obiasly writen for old 3.1.1.101) and to check if any other errors turned up along the way, and yes i wanted to write "output while you run script from scite" and not compile rly sry i did not wrote it correctly on upper post . if i remamber correctly "int:cdecl" shud b called for return type on new autoit versions in this case, cdecl whas probably defolt for older version 3.1.1.101 but your using new ver. of autoit now and youl probalby need to update it. pls tell us did changin your return type parametar from "int" to "int:cdecl" in DllCall solved your problem. edit: edited a lot of times to fix some of my grammar problems (i probably have more of them there but i hope you understand me ) Edited January 15, 2014 by bogQ TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost. Link to comment Share on other sites More sharing options...
l3ill Posted January 15, 2014 Share Posted January 15, 2014 Here is basically what you have described...working. Probably will not work with 3.3.8.1 though. #include <ScreenCapture.au3> HotKeySet("+!d", "_screenCap") ; Shift-Alt-d HotKeySet("{ESC}", "Terminate") While 1 Sleep(1000) WEnd Func _screenCap() Local $hWnd = WinGetHandle("[ACTIVE]") _ScreenCapture_CaptureWnd(@ScriptDir & "\activeWin.jpg", $hWnd) ;screenshot of active window _ScreenCapture_CaptureWnd(@ScriptDir & "\activeWinPart.jpg", $hWnd, 0, 0, 50, 50, True) ;screenshot 50pxX50px top left active window _WinAPI_DeleteObject($hWnd) EndFunc ;==>_screenCap Func Terminate() Exit EndFunc ;==>Terminate My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
RobRod Posted February 6, 2014 Author Share Posted February 6, 2014 (edited) Thank you everyone for the input. I3ill, I gave your script a try, before I work on my own script again... And it's working like a charm. Well done! So there is actually no need to spent anymore time on my old script . Edited February 6, 2014 by RobRod 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