Jump to content

Recommended Posts

Posted (edited)

CrossHairs (Full-Screen)

This UDF utilizes GUI manipulation to simulate full-screen crosshairs.

Posted Image

Example code is included. An additional UDF is bundled in the package: _MouseCursorFuncs (not a full-featured UDF, just one with functions I use now and then).

Note that this would be better controlled using a Mouse Event Handler.

*edits 3/26/2010:

  • Added a new function to alter the properties of the Crosshairs (_XHairSetDisplayProps) - better than destroying/recreating the Crosshairs!
  • Updated the example to show how the new function can be used. It also shows a way to deal with Screen-resolution changes.
Example code:

#include <_CrossHairs.au3>
#include <_MouseCursorFuncs.au3>
; ===============================================================================================================================
; <TestCrossHairs.au3>
;
; Simple test of _Crosshairs UDF. Employs the _MouseCursorFuncs UDF as well
;
; Author: Ascend4nt
; ===============================================================================================================================

;#NoTrayIcon
AutoItSetOption("TrayAutoPause",0)

; ===============================================================================================================================
; GLOBAL VARIABLES
; ===============================================================================================================================

Global $bHKPressed=False,$bPropertyHKPressed=False,$iResolutionchangeMsg=0

; ===============================================================================================================================
; HOTKEY FUNCTIONS
; ===============================================================================================================================

; ESC Key Pressed:

Func _HotKeyPressed()
    $bHKPressed=True
EndFunc

; ALT-P Pressed:

Func _ChangeXHairProperties()
    ; 'Grow' the crosshairs and set them to Red, or alternately shrink them and set them to whitish
    If Not $bPropertyHKPressed Then
        _XHairSetDisplayProps(25,25,0xFF0000)
    Else
        _XHairSetDisplayProps(8,8,0xF0F0F0)
    EndIf
    $bPropertyHKPressed=Not $bPropertyHKPressed
EndFunc


; ===============================================================================================================================
; WINDOWS MESSAGE HANDLER FUNCTIONS
; ===============================================================================================================================


; ===============================================================================================================================
; Func _Resolutionchanged($hWnd,$iMsg,$wParam,$lParam)
;
; Note this registers multiple-monitor settings changes too, but will only report on the primary monitor's resolution
;   This is why we would need to call _WinAPI_GetSystemMetrics() to get the Virtual width/height
; ===============================================================================================================================

Func _Resolutionchanged($hWnd,$iMsg,$wParam,$lParam)
    $iResolutionchangeMsg+=1
    Return 'GUI_RUNDEFMSG'      ; From <GUIConstantsEx.au3> Global Const $GUI_RUNDEFMSG = 'GUI_RUNDEFMSG'
EndFunc


; ===================================================================================================================
;   START MAIN CODE
; ===================================================================================================================

Dim $aNewMousePos

; Create the crosshairs (but don't make them visible yet)
_XHairInit(11,11)

HotKeySet("{ESC}","_HotKeyPressed")
; Alt-p switches between two alternate CrossHair properties
HotKeySet("!p","_ChangeXHairProperties")

; ----------------------------------------------------------------------------------------------------|
; Register Display-Mode changes to our function.
;   NOTE that a GUI (*any* GUI) MUST be created or else the WM_DISPLAYCHANGE message won't be received
;    Luckily, we've just created four GUI's using _XHairInit() and don't need to create any further
;   ALSO note that this is called for *every* GUI that is created (for *just* X-Hairs, thats 4 calls)
; ----------------------------------------------------------------------------------------------------|
GUIRegisterMsg(0x007E,"_Resolutionchanged") ;   WM_DISPLAYCHANGE 0x007E

_MouseHideAllCursors()
;~ _MouseReplaceAllCursors()    ; Alternatively replace all cursors with custom crosshair

While Not $bHKPressed
    ; 4 Messages are sent, 1 for each GUI created
    If $iResolutionchangeMsg>=4 Then
        ; Call with no arguments so that it will retain old properties but adjust to new resolution
        _XHairSetDisplayProps()
        $iResolutionchangeMsg=0
    EndIf
    $aNewMousePos=MouseGetPos()
    _XHairShow($aNewMousePos[0],$aNewMousePos[1])
    Sleep(5)
WEnd
; Unregister Display Mode change function
GUIRegisterMsg(0x007E,"")   ;   WM_DISPLAYCHANGE 0x007E
; Destroy Crosshairs
_XHairUnInit()
; And restore all system cursors back to normal
_MouseRestoreAllCursors()

Download the ZIP from my site

Ascend4nt's AutoIT Code License agreement:

While I provide this source code freely, if you do use the code in your projects, all I ask is that:

  • If you provide source, keep the header as I have put it, OR, if you expand it, then at least acknowledge me as the original author, and any other authors I credit
  • If the program is released, acknowledge me in your credits (it doesn't have to state which functions came from me, though again if the source is provided - see #1)
  • The source on it's own (as opposed to part of a project) can not be posted unless a link to the page(s) where the code were retrieved from is provided and a message stating that the latest updates will be available on the page(s) linked to.
  • Pieces of the code can however be discussed on the threads where Ascend4nt has posted the code without worrying about further linking.
Edited by Ascend4nt
Posted

Thx Yashied, its good to be back around this great group of people again :(

Posted

Thanks playlet :(

I just updated the code and example. Here's the changes:

*edits 3/26/2010:

  • Added a new function to alter the properties of the Crosshairs (_XHairSetDisplayProps) - better than destroying/recreating the Crosshairs!
  • Updated the example to show how the new function can be used. It also shows a way to deal with Screen-resolution changes.
Posted

Thanks KaFu, and you are absolutely correct - this plus the GUIBox UDF makes selecting areas pretty easy. Of course, with a screen-magnify UDF it would be even better. Hmm.. who do I know that has one of those :(

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
×
×
  • Create New...