Jump to content

Useing _ScreenCapture_Capture and $fCursor=True


ofLight
 Share

Recommended Posts

When I use _ScreenCapture_Capture in the following manner(example below) the cursor is only captured in the region of the screen if its within the top 100 or so pixels of the total Desktop area (Top-Left).

Move the mouse around the screen and u see the Displayed Image with no Cursor, but move the mouse to the top-left corner of the screen and the cursor is displayed, as intended. Any suggestions on what i messed up would be greatly appreciated. :D

#include <GDIPlus.au3>
#include <ScreenCapture.au3>
#include <WinAPI.au3>
#include <GuiConstantsEx.au3>
#include <GUIConstants.au3>
#include <Misc.au3>
HotKeySet("{ESC}","QuitIt")
Opt("MustDeclareVars", 1)

Global $hBMP, $hGUI1, $hBitmap, $hGraphic1, $mousepos

$hGUI1 = GUICreate("Magnifier", 100, 100, -1,   -1)
GUISetState()

While 1
$mousepos = MouseGetPos()
$hBMP = _ScreenCapture_Capture("", $mousepos[0]-50,$mousepos[1]-50,$mousepos[0]+50,$mousepos[1]+50,TRUE)

; Initialize GDI+ library and load image
_GDIPlus_Startup()
$hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBMP)

; Draw 100x100 around the mouse pointer
$hGraphic1 = _GDIPlus_GraphicsCreateFromHWND($hGUI1)
_GDIPlus_GraphicsDrawImage($hGraphic1, $hBitmap, 0, 0)

_GDIPlus_GraphicsDispose($hGraphic1)
_GDIPlus_ImageDispose($hBitmap)
_WinAPI_DeleteObject($hBmp)
_GDIPlus_Shutdown()
If GUIGetMsg() == $GUI_EVENT_CLOSE Then QuitIt()
WEnd

Func QuitIt()
    Exit
EndFunc

There is always a butthead in the crowd, no matter how hard one tries to keep them out.......Volly

Link to comment
Share on other sites

Hi,

It's not anything your doing wrong.

You'd need to modify the _ScreenCapture_Capture() function a little to get it to do what you want. (Not Recomended)

Or

Paint your own cursor on the Zoom window.

Since the Cursor would always be smack bang in the middle of the zoom window it wouldn't be that hard to do.

Here's a very sloppy example of what I mean.

#include <GUIConstants.au3>
#include <GDIPlus.au3>
#include <ScreenCapture.au3>
#include <WinAPI.au3>

HotKeySet("{ESC}","QuitIt")
Opt("MustDeclareVars", 1)

Global $hGUI1, $Drag, $MGP1, $MGP2, $msg

$hGUI1 = GUICreate("Magnifier", 100, 100, -1, -1, $WS_POPUPWINDOW, $WS_EX_TOPMOST)
$Drag = GUICtrlCreateLabel("", 0, 0, 100, 100, -1, $GUI_WS_EX_PARENTDRAG)
GUISetState()

$MGP1 = MouseGetPos()

_GDIPlus_Startup()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            QuitIt()
        Case Else
            $MGP2 = MouseGetPos()
            If $MGP1[0] <> $MGP2[0] Or $MGP1[1] <> $MGP2[1] Then
                Local $hBMP, $hBitmap, $hGraphic1, $hCDC, $aCur, $hIcon, $PosX, $PosY
                $hBMP = _ScreenCapture_Capture("", $MGP2[0]-50,$MGP2[1]-50,$MGP2[0]+50,$MGP2[1]+50, False)
                $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBMP)
                $hGraphic1 = _GDIPlus_GraphicsCreateFromHWND($hGUI1)
                _GDIPlus_GraphicsDrawImage($hGraphic1, $hBitmap, 0, 0)
                _GDIPlus_GraphicsDispose($hGraphic1)
                _GDIPlus_ImageDispose($hBitmap)
                _WinAPI_DeleteObject($hBmp)
                $hCDC = _WinAPI_GetWindowDC($hGUI1)
                $aCur = _WinAPI_GetCursorInfo()
                If $aCur[0] And $aCur[1] Then
                    $hIcon = _WinAPI_CopyIcon($aCur[2])
                    $PosX = ((_WinAPI_GetClientWidth($hGUI1) /2) - (_WinAPI_GetSystemMetrics($SM_CXCURSOR)/4)) - 1
                    $PosY = ((_WinAPI_GetClientHeight($hGUI1) /2) - (_WinAPI_GetSystemMetrics($SM_CYCURSOR)/4)) - 1
                    _WinAPI_DrawIcon($hCDC, $PosX, $PosY, $hIcon)
                    _WinAPI_DestroyIcon($hIcon)
                EndIf
                _WinAPI_ReleaseDC($hGUI1, $hCDC)
                $MGP1 = $MGP2
            EndIf
    EndSwitch
WEnd

Func QuitIt()
    _GDIPlus_Shutdown()
    Exit
EndFunc

Cheers

Edited by smashly
Link to comment
Share on other sites

Hay Smashly thanks for the Help, your solution worked exactly as i needed it to.

Anyone know how to take the output from that directly to a bitmap file, instead of outputting to a window?

I would also like to know this, I could use it in several situations. I am guessing we would need to spit the $hIcon handle out to some sorta bitmap translator? Anyone know of any UDF's or DLL's that may do this?

There is always a butthead in the crowd, no matter how hard one tries to keep them out.......Volly

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...