Jump to content

Screen Capture tool


maqleod
 Share

Recommended Posts

Basic tool for taking snapshots of your desktop or any specific window you want.

I wrote it primarily to take screenshots of apps I write.

At some point I'll update it to allow the user to select quality levels and maybe more if I get some good suggestions.

Source:

Screen_Capture.au3

;
;Screen Capture
;v.0.1
;written by Jared Epstein
#include <GUIConstants.au3>
#include <GUIListView.au3>
#include <ScreenCapture.au3>

main()

Func main()
    Local $name = "Screen Capture"
    Dim $handles[50], $titles[50]
    Local $main, $listview, $desktop, $winpid, $winpath, $capture, $msg, $index, $handle
    $main = GUICreate($name, 295, 210)
    $listview = GUICtrlCreateListView("Window Title", 10, 10, 275, 155, BitOR($LVS_SHOWSELALWAYS, $LVS_SINGLESEL), BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_HEADERDRAGDROP))
    $desktop = _WinAPI_GetDesktopWindow ()
    $windows = WinList()
    GUICtrlCreateListViewItem("Desktop", $listview)
    GUICtrlSetImage(-1, "shell32.dll", 35)
    $x = 1
    For $i = 1 To $windows[0][0]
        $winpid = WinGetProcess($windows[$i][0], "")
        If $windows[$i][0] <> "" And IsVisible($windows[$i][1]) Then
            $winpath = _ProcessGetPath($winpid)
            GUICtrlCreateListViewItem($windows[$i][0], $listview)
            GUICtrlSetImage(-1, "shell32.dll", 3)
            GUICtrlSetImage(-1, $winpath, 1)
            $handles[$x] = $windows[$i][1]
            $titles[$x] = $windows[$i][0]
            $x = $x + 1
        EndIf
    Next
    _GUICtrlListView_SetColumnWidth ($listview, 0, $LVSCW_AUTOSIZE)
    $capture = GUICtrlCreateButton("Capture", 110, 175, 75, 25)
    GUISetState()
    Do
        $msg = GUIGetMsg()
        
        If $msg = $capture Then
            $index = _GuiCtrlListView_GetSelectedIndices ($listview)
            If $index = 0 Then
                $handle = $desktop
                $title = "Desktop"
            Else
                $handle = $handles[$index]
                $title = $titles[$index]
            EndIf
            _Capture($main, $handle, $title)
        EndIf
    Until $msg = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>main

Func _Capture($hGui, $hWnd, $sTitle)
    Local $savepath, $image, $errorcheck, $open
    $savepath = FileSaveDialog("Save Screenshot", @HomeDrive, "Images (*.bmp;*.gif;*.jpg;*.png;*.tif)", 18, "", $hGui)
    If @error <> 1 Then
        GUISetState(@SW_HIDE, $hGui)
        If $sTitle <> "Desktop" Then
            WinSetState($sTitle, "", @SW_SHOW)
            WinSetState($sTitle, "", @SW_RESTORE)
        EndIf
        $image = _ScreenCapture_CaptureWnd ("", $hWnd, 0, 0, -1, -1, False)
        $errorcheck = _ScreenCapture_SaveImage ($savepath, $image, True)
        GUISetState(@SW_SHOW, $hGui)
        If $errorcheck = False Then
            _WinAPI_DeleteObject ($image)
        Else
            $open = MsgBox(36, "Open Image?", "Would you like to open the image?")
            If $open = 6 Then
                ShellExecute($savepath)
            Else
            EndIf
        EndIf
    Else
    EndIf
EndFunc   ;==>_Capture

Func _ProcessGetPath($pid)
    If IsString($pid) Then $pid = ProcessExists($pid)
    $Path = DllStructCreate("char[1000]")
    $dll = DllOpen("Kernel32.dll")
    $handle = DllCall($dll, "int", "OpenProcess", "dword", 0x0400 + 0x0010, "int", 0, "dword", $pid)
    $ret = DllCall("Psapi.dll", "long", "GetModuleFileNameEx", "long", $handle[0], "int", 0, "ptr", DllStructGetPtr($Path), "long", DllStructGetSize($Path))
    $ret = DllCall($dll, "int", "CloseHandle", "hwnd", $handle[0])
    DllClose($dll)
    Return DllStructGetData($Path, 1)
EndFunc   ;==>_ProcessGetPath

Func IsVisible($handle)
    If BitAND(WinGetState($handle), 2) Then
        Return 1
    Else
        Return 0
    EndIf
EndFunc   ;==>IsVisible
[u]You can download my projects at:[/u] Pulsar Software
Link to comment
Share on other sites

Thank you for your effort!

I simply tested. But, It doesn't find proper window... How was wrong? :)

not sure, I tested it with many windows on my system, I am running XP SP2, I didn't test it on any other OS. What is your OS and can you describe the behavior in more detail?

[u]You can download my projects at:[/u] Pulsar Software
Link to comment
Share on other sites

Totally missing the point I know but if anyone is looking for a good freeware screen capturing application then you could do a lot worse than this:

http://www.aplusfreeware.com/categories/mm...oneCapture.html

WBD

Link to comment
Share on other sites

Totally missing the point I know but if anyone is looking for a good freeware screen capturing application then you could do a lot worse than this:

http://www.aplusfreeware.com/categories/mm...oneCapture.html

WBD

I don't mean to sound rude, but it may come off that way, but the point of this forum is not to suggest to everyone a freeware app with more features than a script someone posts, it is to share your code with others so that others may learn or comment. If people wanted specifically a screen capture tool, they could easily Google it and I'm sure they do; if people wanted an example of one for which they might use part in one of their scripts, they'll use this forum and might find my post useful, maybe not as well, but at least it's there for others to use. Posting a link like that is purposeless on this forum and is actually quite rude.

Would you want people posting links to programs under anything you've written suggesting its better in one way or another? There are always better programs, all you need do is search. It is fine if you want to post a link to another script on this forum, something that other users might find useful if they find this code in a search, but I really don't see the point of suggesting unsolicited programs without saying anything useful about the script.

[u]You can download my projects at:[/u] Pulsar Software
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...