Sign in to follow this  
Followers 0
taietel

Capture mouse selection

11 posts in this topic

I'm trying to capture mouse selection, but I have few problems:

1. how can I draw a rectangle on mouse movement (in the script I did it from drawing lines) and change the transparency of the selected area?

2. if I press primary mouse button and drag down-right, then release it, the image is saved BUT if i drag in other direction, I get no selection. I think the problem is from line 63...

The script so far:

#NoTrayIcon
#AutoIt3Wrapper_AU3Check_Parameters= -w 1 -w 2 -w 3 -w 4 -w 6
#Tidy_Parameters=/tc 0 /rel /sfc
#Include <GUIConstantsEx.au3>
#include <ScreenCapture.au3>
#include <GDIPlus.au3>
#include <StaticConstants.au3>
#Include <WindowsConstants.au3>
#Include <WinAPIEx.au3>

Opt('MouseCoordMode', 2)
Opt('MustDeclareVars', 1)

Global $hwnd, $tRECT, $X, $Y, $Width, $Height, $Pos1, $Pos2, $Pos3, $hRect
$tRECT = _WinAPI_GetWorkArea(); thanks to Yashied(WinAPIEx.au3 = WinAPI Extended UDF Library for AutoIt3)
$Width = DllStructGetData($tRECT, 'Right') - DllStructGetData($tRECT, 'Left')
$Height = DllStructGetData($tRECT, 'Bottom') - DllStructGetData($tRECT, 'Top')
$X = DllStructGetData($tRECT, 'Left')
$Y = DllStructGetData($tRECT, 'Top')
Start()
Func Start()
$hwnd = GUICreate('', $Width, $Height, $X, $Y, $WS_POPUP, $WS_EX_TOPMOST)
GUISetBkColor(0, $hwnd)
WinSetTrans($hwnd, '', 70)
GUISetState()
ToolTip("Select region (the image will be saved in the current directory) or" & @CRLF & "                                               Press ESC to exit", @DesktopWidth/2-150, 0, "",0,4)
While 1
    Sleep(10)
    Global $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $GUI_EVENT_PRIMARYDOWN
            $Pos1 = MouseGetPos()
            _CaptureMouseSel(@ScriptDir & "\imagine.tif", 1.5)
            Exit
    EndSwitch
WEnd
EndFunc
Func _CaptureMouseSel($sOutImage="", $scale = 1)
    Local $hDC = _WinAPI_GetWindowDC(0) ; DC of entire screen (desktop)
    Local $hPen = _WinAPI_CreatePen($PS_SOLID, 1, 0x0000FF)
    Local $obj_orig = _WinAPI_SelectObject($hDC, $hPen)
    While 1
        Sleep(10)
    Local $Msgm = GUIGetMsg()
    Switch $Msgm
        Case $GUI_EVENT_MOUSEMOVE
            _WinAPI_RedrawWindow(_WinAPI_GetDesktopWindow(), 0, 0, $RDW_INVALIDATE + $RDW_ALLCHILDREN)
            Sleep(60)
            $Pos2=MouseGetPos()
            _WinAPI_DrawLine($hDC, $Pos1[0], $Pos1[1], $Pos2[0], $Pos1[1]) ; horizontal top line
            _WinAPI_DrawLine($hDC, $Pos1[0], $Pos1[1], $Pos1[0], $Pos2[1]) ; vertical left line
            _WinAPI_DrawLine($hDC, $Pos1[0], $Pos2[1], $Pos2[0], $Pos2[1]) ; horizontal bottom line
            _WinAPI_DrawLine($hDC, $Pos2[0], $Pos1[1], $Pos2[0], $Pos2[1]) ; vertical right line
        Case $GUI_EVENT_PRIMARYUP
            _WinAPI_RedrawWindow(_WinAPI_GetDesktopWindow(), 0, 0, $RDW_INVALIDATE + $RDW_ALLCHILDREN)
            _WinAPI_SelectObject($hDC, $obj_orig)
            _WinAPI_DeleteObject($hPen)
            _WinAPI_ReleaseDC(0, $hDC)
            $Pos3 = MouseGetPos();get the last position of the mouse
            Sleep(60)
            Local $hRect = _ScreenCapture_Capture("", $Pos1[0], $Pos1[1], $Pos3[0], $Pos3[1])
            Local $Ext = StringUpper(StringMid($sOutImage, StringInStr($sOutImage, ".", 0, -1) + 1))
            ; Initialize GDI+ library
            _GDIPlus_Startup ()
            Local $hImage2 = _GDIPlus_BitmapCreateFromHBITMAP($hRect)
            Local $hWnd2 = _WinAPI_GetDesktopWindow()
            Local $hDC2 = _WinAPI_GetDC($hWnd2)
            Local $varw = ($Pos3[0]-$Pos1[0])*$scale
            Local $varh = ($Pos3[1]-$Pos1[1])*$scale
            Local $hBMP = _WinAPI_CreateCompatibleBitmap($hDC2, $varw, $varh)
            _WinAPI_ReleaseDC($hWnd2, $hDC2)
            Local $hImage1 = _GDIPlus_BitmapCreateFromHBITMAP($hBMP)
            Local $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage1)
            _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage2, 0, 0, $varw, $varh)
            Local $CLSID = _GDIPlus_EncodersGetCLSID($Ext)
            ; Set image parameters
            Local $tParams = _GDIPlus_ParamInit(2)
            Local $tData = DllStructCreate("int ColorDepth;int Compression")
            DllStructSetData($tData, "ColorDepth", 24)
            DllStructSetData($tData, "Compression", 6)
            _GDIPlus_ParamAdd($tParams, $GDIP_EPGCOLORDEPTH, 1, $GDIP_EPTLONG, DllStructGetPtr($tData, "ColorDepth"))
            _GDIPlus_ParamAdd($tParams, $GDIP_EPGCOMPRESSION, 1, $GDIP_EPTLONG, DllStructGetPtr($tData, "Compression"))
            Local $pParams
            If IsDllStruct($tParams) Then $pParams = DllStructGetPtr($tParams)
            ; Save image and then cleanup
            _GDIPlus_ImageSaveToFileEx($hImage1, $sOutImage, $CLSID, $pParams)
            _GDIPlus_ImageDispose($hImage1)
            _GDIPlus_ImageDispose($hImage2)
            _GDIPlus_GraphicsDispose($hGraphic)
            _WinAPI_DeleteObject($hRect)
            _WinAPI_DeleteObject($hBMP)
            _GDIPlus_Shutdown()
            ShellExecute(@ScriptDir & "\imagine.tif")
            ExitLoop
    EndSwitch
    WEnd
EndFunc

Thank you in advance!

P.S. Please excuse my English... Posted Image

M.Iancu

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Just recently coded this while playing around with GUI styles, should be easy to combine with screencapture :blink:...

#cs ----------------------------------------------------------------------------

    AutoIt Version: 3.3.6.1
    Author:         KaFu

    Script Function:
    Drag GUI

#ce ----------------------------------------------------------------------------

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Winapi.au3>
#include <Misc.au3>

Opt("GUIOnEventMode", 1)

HotKeySet("{ESC}", "_Exit")

While 1
    Sleep(10)
    If _IsPressed("01") Then
        While _IsPressed("01")
            Sleep(10)
        WEnd
        _CreateDragGui()
    EndIf
WEnd


Func _CreateDragGui()
    $aPosMouseInitial = MouseGetPos()
    $gui_Drag = GUICreate("GuiDrag", 100, 100, $aPosMouseInitial[0], $aPosMouseInitial[1], $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_LAYERED,$WS_EX_TOPMOST))

    MouseMove($aPosMouseInitial[0]+100, $aPosMouseInitial[1]+100,0)

    GUICtrlCreateLabel("", 0, 0, 100, 1)
    GUICtrlSetBkColor(-1, 0xff0000)
    GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKHEIGHT)

    GUICtrlCreateLabel("", 0, 0, 1, 100)
    GUICtrlSetBkColor(-1, 0xff0000)
    GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKWIDTH)

    GUICtrlCreateLabel("", 0,99,100,1)
    GUICtrlSetBkColor(-1, 0xff0000)
    GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKBOTTOM + $GUI_DOCKHEIGHT)

    GUICtrlCreateLabel("", 99,0,1,100)
    GUICtrlSetBkColor(-1, 0xff0000)
    GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKWIDTH)

    GUISetBkColor(0xABCDEF)
    GUISetState(@SW_SHOW)
    _WinAPI_SetLayeredWindowAttributes($gui_Drag, 0xABCDEF, 255)

    While 1
        Sleep(10)
        $aPosMouse = MouseGetPos()
        Select
            Case ($aPosMouse[0] >= $aPosMouseInitial[0]) AND ($aPosMouse[1] >= $aPosMouseInitial[1])
                WinMove($gui_Drag, "", $aPosMouseInitial[0], $aPosMouseInitial[1], $aPosMouse[0] - $aPosMouseInitial[0], $aPosMouse[1] - $aPosMouseInitial[1])
            Case ($aPosMouse[0] < $aPosMouseInitial[0]) AND ($aPosMouse[1] >= $aPosMouseInitial[1])
                WinMove($gui_Drag, "", $aPosMouse[0], $aPosMouseInitial[1], $aPosMouseInitial[0] - $aPosMouse[0], $aPosMouse[1] - $aPosMouseInitial[1])
            Case ($aPosMouse[0] >= $aPosMouseInitial[0]) AND ($aPosMouse[1] < $aPosMouseInitial[1])
                WinMove($gui_Drag, "", $aPosMouseInitial[0], $aPosMouse[1], $aPosMouse[0] - $aPosMouseInitial[0], $aPosMouseInitial[1] - $aPosMouse[1])
            Case ($aPosMouse[0] < $aPosMouseInitial[0]) AND ($aPosMouse[1] < $aPosMouseInitial[1])
                WinMove($gui_Drag, "", $aPosMouse[0], $aPosMouse[1], $aPosMouseInitial[0] - $aPosMouse[0], $aPosMouseInitial[1] - $aPosMouse[1])
        EndSelect

        If _IsPressed("01") Then
            $aPosWin = WinGetPos($gui_Drag)
            MsgBox(0, "", $aPosWin[0] & "x" & $aPosWin[1] & @CRLF & $aPosWin[2] & "x" & $aPosWin[3])
            ExitLoop
        EndIf
    WEnd
    GUIDelete()
EndFunc   ;==>_CreateDragGui


Func _Exit()
    Exit
EndFunc   ;==>_Exit
Edited by KaFu

Share this post


Link to post
Share on other sites

taietel,

If you want another way to do it: :blink:

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <ScreenCapture.au3>
#Include <Misc.au3>

Global $iX1, $iY1, $iX2, $iY2, $aPos, $sMsg, $sBMP_Path

; Create GUI
$hMain_GUI = GUICreate("Select Rectangle", 240, 50)

$hRect_Button   = GUICtrlCreateButton("Mark Area",  10, 10, 80, 30)
$hCancel_Button = GUICtrlCreateButton("Cancel",    150, 10, 80, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $hCancel_Button
            FileDelete(@ScriptDir & "\Rect.bmp")
            Exit
        Case $hRect_Button
            GUISetState(@SW_HIDE, $hMain_GUI)
            Mark_Rect()
            ; Capture selected area
            $sBMP_Path = @ScriptDir & "\Rect.bmp"
            _ScreenCapture_Capture($sBMP_Path, $iX1, $iY1, $iX2, $iY2, False)
            GUISetState(@SW_SHOW, $hMain_GUI)
            ; Display image
            $hBitmap_GUI = GUICreate("Selected Rectangle", $iX2 - $iX1 + 1, $iY2 - $iY1 + 1, 100, 100)
            $hPic = GUICtrlCreatePic(@ScriptDir & "\Rect.bmp", 0, 0, $iX2 - $iX1 + 1, $iY2 - $iY1 + 1)
            GUISetState()

    EndSwitch

WEnd

; -------------

Func Mark_Rect()

    Local $aMouse_Pos, $hMask, $hMaster_Mask, $iTemp
    Local $UserDLL = DllOpen("user32.dll")

    Global $hRectangle_GUI = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)
    _GUICreateInvRect($hRectangle_GUI, 0, 0, 1, 1)
    GUISetBkColor(0)
    WinSetTrans($hRectangle_GUI, "", 50)
    GUISetState(@SW_SHOW, $hRectangle_GUI)
    GUISetCursor(3, 1, $hRectangle_GUI)

    ; Wait until mouse button pressed
    While Not _IsPressed("01", $UserDLL)
        Sleep(10)
    WEnd

    ; Get first mouse position
    $aMouse_Pos = MouseGetPos()
    $iX1 = $aMouse_Pos[0]
    $iY1 = $aMouse_Pos[1]

    ; Draw rectangle while mouse button pressed
    While _IsPressed("01", $UserDLL)

        $aMouse_Pos = MouseGetPos()

        ; Set in correct order if required
        If $aMouse_Pos[0] < $iX1 Then
            $iX_Pos = $aMouse_Pos[0]
            $iWidth = $iX1 - $aMouse_Pos[0]
        Else
            $iX_Pos = $iX1
            $iWidth = $aMouse_Pos[0] - $iX1
        EndIf
        If $aMouse_Pos[1] < $iY1 Then
            $iY_Pos = $aMouse_Pos[1]
            $iHeight = $iY1 - $aMouse_Pos[1]
        Else
            $iY_Pos = $iY1
            $iHeight = $aMouse_Pos[1] - $iY1
        EndIf

        _GUICreateInvRect($hRectangle_GUI, $iX_Pos, $iY_Pos, $iWidth, $iHeight)

        Sleep(10)

    WEnd

    ; Get second mouse position
    $iX2 = $aMouse_Pos[0]
    $iY2 = $aMouse_Pos[1]

    ; Set in correct order if required
    If $iX2 < $iX1 Then
        $iTemp = $iX1
        $iX1 = $iX2
        $iX2 = $iTemp
    EndIf
    If $iY2 < $iY1 Then
        $iTemp = $iY1
        $iY1 = $iY2
        $iY2 = $iTemp
    EndIf

    GUIDelete($hRectangle_GUI)
    DllClose($UserDLL)

EndFunc   ;==>Mark_Rect

Func _GUICreateInvRect($hWnd, $iX, $iY, $iW, $iH)

    $hMask_1 = _WinAPI_CreateRectRgn(0, 0, @DesktopWidth, $iY)
    $hMask_2 = _WinAPI_CreateRectRgn(0, 0, $iX, @DesktopHeight)
    $hMask_3 = _WinAPI_CreateRectRgn($iX + $iW, 0, @DesktopWidth, @DesktopHeight)
    $hMask_4 = _WinAPI_CreateRectRgn(0, $iY + $iH, @DesktopWidth, @DesktopHeight)

    _WinAPI_CombineRgn($hMask_1, $hMask_1, $hMask_2, 2)
    _WinAPI_CombineRgn($hMask_1, $hMask_1, $hMask_3, 2)
    _WinAPI_CombineRgn($hMask_1, $hMask_1, $hMask_4, 2)

    _WinAPI_DeleteObject($hMask_2)
    _WinAPI_DeleteObject($hMask_3)
    _WinAPI_DeleteObject($hMask_4)

    _WinAPI_SetWindowRgn($hWnd, $hMask_1, 1)

EndFunc

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

I'm trying to do some kind of snipping tool for tesseract.

Had that idea... *check, check*... in may 2009 :P... tried to do that with Seangriffins Tesseract (Screen OCR) UDF but wasn't quite that good at that time so I put it on the "projects for the future" pile ;)... I would love to see a working implementation :blink:...

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

KaFu, I've added the capture feature:

#cs ----------------------------------------------------------------------------

    AutoIt Version: 3.3.6.1
    Author:         KaFu

    Script Function:
    Drag GUI

#ce ----------------------------------------------------------------------------

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#include <GDIPlus.au3>
#include <ScreenCapture.au3>
#include <WinAPI.au3>


Opt("GUIOnEventMode", 1)

HotKeySet("{ESC}", "_Exit")

While 1
    Sleep(10)
    If _IsPressed("01") Then
        While _IsPressed("01")
            Sleep(10)
        WEnd
        _CreateDragGui()
        ExitLoop
    EndIf
WEnd


Func _CreateDragGui()
    $aPosMouseInitial = MouseGetPos()
    $gui_Drag = GUICreate("GuiDrag", 100, 100, $aPosMouseInitial[0], $aPosMouseInitial[1], $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_LAYERED,$WS_EX_TOPMOST))

    MouseMove($aPosMouseInitial[0]+100, $aPosMouseInitial[1]+100,0)

    GUICtrlCreateLabel("", 0, 0, 100, 1)
    GUICtrlSetBkColor(-1, 0xff0000)
    GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKHEIGHT)

    GUICtrlCreateLabel("", 0, 0, 1, 100)
    GUICtrlSetBkColor(-1, 0xff0000)
    GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKWIDTH)

    GUICtrlCreateLabel("", 0,99,100,1)
    GUICtrlSetBkColor(-1, 0xff0000)
    GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKBOTTOM + $GUI_DOCKHEIGHT)

    GUICtrlCreateLabel("", 99,0,1,100)
    GUICtrlSetBkColor(-1, 0xff0000)
    GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKWIDTH)

    GUISetBkColor(0xABCDEF)
    GUISetState(@SW_SHOW)
    _WinAPI_SetLayeredWindowAttributes($gui_Drag, 0x0000FF, 100)

    While 1
        Sleep(10)
        $aPosMouse = MouseGetPos()
        Select
            Case ($aPosMouse[0] >= $aPosMouseInitial[0]) AND ($aPosMouse[1] >= $aPosMouseInitial[1])
                WinMove($gui_Drag, "", $aPosMouseInitial[0], $aPosMouseInitial[1], $aPosMouse[0] - $aPosMouseInitial[0], $aPosMouse[1] - $aPosMouseInitial[1])
            Case ($aPosMouse[0] < $aPosMouseInitial[0]) AND ($aPosMouse[1] >= $aPosMouseInitial[1])
                WinMove($gui_Drag, "", $aPosMouse[0], $aPosMouseInitial[1], $aPosMouseInitial[0] - $aPosMouse[0], $aPosMouse[1] - $aPosMouseInitial[1])
            Case ($aPosMouse[0] >= $aPosMouseInitial[0]) AND ($aPosMouse[1] < $aPosMouseInitial[1])
                WinMove($gui_Drag, "", $aPosMouseInitial[0], $aPosMouse[1], $aPosMouse[0] - $aPosMouseInitial[0], $aPosMouseInitial[1] - $aPosMouse[1])
            Case ($aPosMouse[0] < $aPosMouseInitial[0]) AND ($aPosMouse[1] < $aPosMouseInitial[1])
                WinMove($gui_Drag, "", $aPosMouse[0], $aPosMouse[1], $aPosMouseInitial[0] - $aPosMouse[0], $aPosMouseInitial[1] - $aPosMouse[1])
        EndSelect

        If _IsPressed("01") Then
            $aPosWin = WinGetPos($gui_Drag)
            ConsoleWrite($aPosWin[0] & "x" & $aPosWin[1] & @CRLF & $aPosWin[2] & "x" & $aPosWin[3] & @CRLF)
            _CaptureSelection(@ScriptDir & "\captura2tiff.tif",2, $aPosWin[0], $aPosWin[1], $aPosWin[2]+$aPosWin[0], $aPosWin[3]+$aPosWin[1])
            ExitLoop
        EndIf
    WEnd
    GUIDelete()
EndFunc   ;==>_CreateDragGui

Func _CaptureSelection($sOutImage = "", $scale = 1, $X1=0, $Y1=0, $X2=-1, $Y2=-1)
    Local $hWnd, $hDC, $hBMP, $hImage1, $hGraphic, $CLSID, $tParams, $pParams, $tData, $i = 0, $hImage2
    Local $Ext = StringUpper(StringMid($sOutImage, StringInStr($sOutImage, ".", 0, -1) + 1))
    ; Capture portion of the screen:
    $hBitmap2 = _ScreenCapture_Capture("", $X1, $Y1, $X2, $Y2, False)
    _GDIPlus_Startup()
    $hImage2 = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap2)
    $hWnd = _WinAPI_GetDesktopWindow()
    $hDC = _WinAPI_GetDC($hWnd)
    $hBMP = _WinAPI_CreateCompatibleBitmap($hDC, @DesktopWidth * $scale, @DesktopHeight * $scale)
    _WinAPI_ReleaseDC($hWnd, $hDC)
    $hImage1 = _GDIPlus_BitmapCreateFromHBITMAP($hBMP)
    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage1)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage2, 0, 0, @DesktopWidth * $scale, @DesktopHeight * $scale)
    $CLSID = _GDIPlus_EncodersGetCLSID($Ext)
    ; Set TIFF parameters
    $tParams = _GDIPlus_ParamInit(2)
    $tData = DllStructCreate("int ColorDepth;int Compression")
    DllStructSetData($tData, "ColorDepth", 24)
    DllStructSetData($tData, "Compression", $GDIP_EVTCOMPRESSIONNONE)
    _GDIPlus_ParamAdd($tParams, $GDIP_EPGCOLORDEPTH, 1, $GDIP_EPTLONG, DllStructGetPtr($tData, "ColorDepth"))
    _GDIPlus_ParamAdd($tParams, $GDIP_EPGCOMPRESSION, 1, $GDIP_EPTLONG, DllStructGetPtr($tData, "Compression"))
    If IsDllStruct($tParams) Then $pParams = DllStructGetPtr($tParams)
    ; Save TIFF and cleanup
    _GDIPlus_ImageSaveToFileEx($hImage1, $sOutImage, $CLSID, $pParams)
    _GDIPlus_ImageDispose($hImage1)
    _GDIPlus_ImageDispose($hImage2)
    _GDIPlus_GraphicsDispose($hGraphic)
    _WinAPI_DeleteObject($hBMP)
    _GDIPlus_Shutdown()
    Sleep(1000)
EndFunc   ;==>_CaptureSelection
Func _Exit()
    Exit
EndFunc   ;==>_Exit

I've tested the resulted tiff image with tesseract and it works great!

tesseract.exe captura2tiff.tif output

Melba, many thanks for the reply! I will test the script and get back as soon as I can. Posted Image

[EDIT] Melba, I've tested your script and ... Posted Image is there an icon for speechless? Posted Image

Edited by taietel

Share this post


Link to post
Share on other sites

Usually I edit my replies but now I don't because I need to THANK YOU BOTH for your help. Not only for now, but for all the answers you gave in this great forum, from which I've learned a lot (and still do).

(I bet you hear this all the time Posted Image)

Share this post


Link to post
Share on other sites

taietel,

My pleasure! :blink: And thank you for taking the time to say it.

M23

P.S. And I am sure I speak for KaFu as well!


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

Might as well add my UDF to the list of mouse-selection thingamabobs :blink:

Rubber-Band Boxes using GUI's (_GUIBox)

Share this post


Link to post
Share on other sites

here is my version of a snipping-function:

#include <StaticConstants.au3>
#include <EditConstants.au3>
#include <ComboConstants.au3>
#include <GuiConstants.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <Process.au3>
#Include <Misc.au3>
#include <Constants.au3>
#Include <GuiButton.au3>
#Include <Clipboard.au3>
#Include <ScreenCapture.au3>
#include <GDIPlus.au3>
#include <file.au3>
$fastx = _WinAPI_GetSystemMetrics(78)
$fasty = _WinAPI_GetSystemMetrics(79)
_area()

func _area()
    $var = WinList()
    For $i = 1 to $var[0][0]
        If $var[$i][0] <> "" AND $var[$i][0] <> "start" AND IsVisible($var[$i][1]) Then WinSetState ($var[$i][0], "", @SW_DISABLE  )
    Next
    $GUI_2 = GUICreate("", 1, 1, -1, -1, 0x80000000 + 0x00800000, 0x00000008)
    GUISetBkColor(0x0c6eec)
    WinSetTrans($GUI_2, "", 130)
    local $s_left = "", $s_top = "", $s_width = "", $s_height = "", $mgp[2]
    Local $hGUI = GUICreate("", $fastx+50, $fasty+50, -15, -25, -1, 0x00000080)
    GUISetBkColor(0xffffff)
    WinSetTrans($hGUI, "", 40)
    WinSetOnTop($hGUI, "", 1)
    GUISetCursor(3)
    GUISetState(@SW_SHOW, $hGUI)
    While Not _IsPressed(01)
        $mgp = MouseGetPos()
        Sleep(50)
    WEnd
    WinMove($GUI_2, "", $mgp[0], $mgp[1], 1, 1)
    GUISetState(@SW_SHOW, $GUI_2)
    While _IsPressed(01)
        $mgp_2 = MouseGetPos()
        If $mgp_2[0] > $mgp[0] And $mgp_2[1] > $mgp[1] Then
            local $s_left = $mgp[0], $s_top = $mgp[1], $s_width = $mgp_2[0] - $mgp[0], $s_height = $mgp_2[1] - $mgp[1]
        ElseIf $mgp_2[0] > $mgp[0] And $mgp_2[1] < $mgp[1] Then
            Local $s_left = $mgp[0], $s_top = $mgp_2[1], $s_width = $mgp_2[0] - $mgp[0], $s_height = $mgp[1] - $mgp_2[1]
        ElseIf $mgp_2[0] < $mgp[0] And $mgp_2[1] > $mgp[1] Then
            Local $s_left = $mgp_2[0], $s_top = $mgp[1], $s_width = $mgp[0] - $mgp_2[0], $s_height = $mgp_2[1] - $mgp[1]
        ElseIf $mgp_2[0] < $mgp[0] And $mgp_2[1] < $mgp[1] Then
            Local $s_left = $mgp_2[0], $s_top = $mgp_2[1], $s_width = $mgp[0] - $mgp_2[0], $s_height = $mgp[1] - $mgp_2[1]
        EndIf
        WinMove($GUI_2, "", $s_left, $s_top, $s_width, $s_height)
        WinSetOnTop($hGUI, "", 1)
        ToolTip($s_width & "x" & $s_height)
        sleep(50)
    WEnd
    ToolTip("")
    GLOBAL $s_left = $s_left, $s_top = $s_top, $s_width = $s_width, $s_height = $s_height
    GUIDelete($hGUI)
    $var = WinList()
    For $i = 1 to $var[0][0]
        If $var[$i][0] <> "" AND IsVisible($var[$i][1]) Then WinSetState ($var[$i][0], "", @SW_ENABLE  )
    Next
    GUIDelete($GUI_2)
    $hBitmap = _ScreenCapture_Capture(@ScriptDir & "\test.jpg", $s_left, $s_top, $s_left+$s_width, $s_top+$s_height, false)
    msgbox(0,"",@ScriptDir & "\test.jpg")
endfunc

Func IsVisible($handle)
    If BitAnd(WinGetState($handle), 2) Then
        Return 1
    Else
        Return 0
    EndIf
EndFunc

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  
Followers 0