Jump to content

Convert mouse into crosshair


 Share

Recommended Posts

Hi there,

I'm trying whole day to create a giant crosshair all over my screen which is in fact the mouse so if the mouse moves the crosshair needs to move to, I wanted to create a cursor but Windows supports up to 32x32 pixels :blink: Anyone has another approach and can give me a little help in the right direction?

Rawox

Link to comment
Share on other sites

Hi there,

I'm trying whole day to create a giant crosshair all over my screen which is in fact the mouse so if the mouse moves the crosshair needs to move to, I wanted to create a cursor but Windows supports up to 32x32 pixels :blink: Anyone has another approach and can give me a little help in the right direction?

Rawox

you could just have an image centered on your mouse position, and just move the image based on your mouse location
Link to comment
Share on other sites

You can do it with GUI's :blink: Check out my CrossHairs (FullScreen) UDF. While the example creates an invisible cursor inside the full-screen crosshairs, I do have a function to change the system cursors to a mini-crosshair as well - use the function _MouseReplaceAllCursors() instead of _MouseHideAllCursors.

Link to comment
Share on other sites

Thanks both cameronsdad and Ascend4nt, I think I'm gonna do it with GUI's. I'll check out the CrossHairs UDF. I can't use mouse cursor because Windows doesn't support cursors bigger than 32x32 pixels :blink:' You'll hear from me ;) Rawox

UPDATE:

Well, I've tried a few things and I'm so far right now:

Only problem right now is that it does also capture the 'zoom window' and the crosshair, is there a way to have them not captured?

;#NoTrayIcon
#include <_CrossHairs.au3>
#include <_MouseCursorFuncs.au3>
#include <GDIPlus.au3>
#include <ScreenCapture.au3>
#include <WinAPI.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>

Global $bHKPressed=False, $bPropertyHKPressed=False, $iResolutionchangeMsg=0
Global $hBMP, $hGUI1, $hGUI2, $hBitmap, $hGraphic1, $hGraphic2
Dim $MagWidth = 20, $MagHeight = 20, $MagZoom = 2
Dim $aNewMousePos

_XHairInit(1,1)
_XHairSetDisplayProps(1,1,0x000000)

HotKeySet ( "{ESC}", "_exitProg" )
OnAutoItExitRegister ( "_exitProg" )
GUIRegisterMsg(0x007E,"_Resolutionchanged")

_MouseHideAllCursors()

$hGUI2 = GUICreate ("Zoomer", $MagWidth * $MagZoom + 2, $MagHeight * $MagZoom + 2, -1, -1, $WS_POPUP)
GUISetBkColor ( 0x000000 )
GUISetState()

_GDIPlus_Startup()

While 1
    $MousePos = MouseGetPos ( )
    $hBMP = _ScreenCapture_Capture("", $MousePos[0], $MousePos[1], $MousePos[0]+$MagWidth, $MousePos[1]+$MagHeight, False)
    ; Initialize GDI+ library and load image
    $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBMP)
    ; Draw 2x zoomed image
    $hGraphic2 = _GDIPlus_GraphicsCreateFromHWND($hGUI2)
    _GDIPlus_GraphicsDrawImageRectRect($hGraphic2, $hBitmap, 0, 0, $MagWidth, $MagHeight, 1, 1, $MagWidth * $MagZoom, $MagHeight * $MagZoom)
    WinMove ( "Zoomer", "", $MousePos[0] + 20, $MousePos[1] + 20)

    If $iResolutionchangeMsg>=4 Then
        _XHairSetDisplayProps()
        $iResolutionchangeMsg=0
    EndIf
    $aNewMousePos=MouseGetPos()
    _XHairShow($aNewMousePos[0],$aNewMousePos[1])
    Sleep(5)
WEnd

Func _Resolutionchanged($hWnd,$iMsg,$wParam,$lParam)
    $iResolutionchangeMsg+=1
    Return 'GUI_RUNDEFMSG'
EndFunc

Func _exitProg()
    GUIRegisterMsg(0x007E,"")   ;   WM_DISPLAYCHANGE 0x007E
    _XHairUnInit()
    _MouseRestoreAllCursors()
    _GDIPlus_GraphicsDispose($hGraphic2)
    _GDIPlus_ImageDispose($hBitmap)
    _WinAPI_DeleteObject($hBmp)
    _GDIPlus_Shutdown()
    Exit
EndFunc
Edited by Rawox
Link to comment
Share on other sites

Move your Zoom window around so it doesn't get captured. As for the crosshairs being captured, that won't be a problem if you use regular GDI32 functions (rather than GDIPlus). There's some code on here somewhere on doing a zoom window with just GDI..

Of course, any partially-transparent window won't be captured in that case. If thats not a problem, do it with GDI32. If you *do* need transparency, well, you can't have the crosshairs without them being captured (unless you want to hide/show them each time you grab the screen).

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