Jump to content



Photo

CrossHairs (full-screen)


  • Please log in to reply
6 replies to this topic

#1 Ascend4nt

Ascend4nt

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 1,072 posts

Posted 24 March 2010 - 07:42 PM

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:
AutoIt         
#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, 14 September 2011 - 02:08 AM.






#2 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,512 posts

Posted 24 March 2010 - 07:58 PM

Nice example, Ascend4nt, and I am glad to see you again. Thanks for sharing.

#3 Ascend4nt

Ascend4nt

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 1,072 posts

Posted 24 March 2010 - 11:43 PM

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

#4 playlet

playlet

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 459 posts

Posted 25 March 2010 - 02:03 AM

I like it very much. *****

Thanks, Ascend4nt!

Playlet

#5 Ascend4nt

Ascend4nt

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 1,072 posts

Posted 26 March 2010 - 04:22 AM

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.


#6 KaFu

KaFu

    Hey, it's just me, KhaFoo...

  • MVPs
  • 3,162 posts

Posted 26 March 2010 - 07:00 AM

Awesome code as always m8 :(...

Seems like a must to me to combine this with your_GUIBox() UDF...

#7 Ascend4nt

Ascend4nt

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 1,072 posts

Posted 26 March 2010 - 04:24 PM

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 :(




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users