Jump to content

Creating a Crosshair or Dot in the middle of the screen?


Recommended Posts

You could also simply create a gif file with a crosshair and then load it in a transparent GUI:

Example:

#include <WindowsConstants.au3>

$x = @DesktopWidth/2 - 68/2
$y = @DesktopHeight/2 - 68/2

GUICreate("", 68, 68, $x, $y, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))
GUICtrlCreatePic("crosshair.gif",0,0,68,68)
GUISetState()

While 1
    Sleep(25)
WEnd

Regards

EDIT: added a gif file.

This works great, thank you! I was just wondering if there's a way to use an alpha-blended .png instead of a .gif, and a way to make it always on top, even for fullscreen applications?
Link to comment
Share on other sites

here

; *** Start added by AutoIt3Wrapper ***
#include <Constants.au3>
; *** End added by AutoIt3Wrapper ***
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Add_Constants=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WINAPI.au3>
#include <sendmessage.au3>

;Global Const $LWA_ALPHA = 0x2
;Global Const $LWA_COLORKEY = 0x1

HotKeySet("ESC", "_Exit")
$x = @DesktopWidth/2-40
$y = @DesktopHeight/2-40
$hGUI = GUICreate("CROSSHAIR", 40, 40, $x, $y, bitor($WS_POPUP, $WS_CLIPSIBLINGS), bitor($WS_EX_LAYERED, $WS_EX_TOPMOST))
$hwnd = WinGetHandle("CROSSHAIR")
WinSetOnTop("CROSSHAIR","", 1)
WinSetOnTop("COD4","", 0)
GUISetBkColor(0xABCDEF)

GUICtrlCreatePic("ver.jpg", 20,0, 1, 40)
GUICtrlCreatePic("hor.jpg", 0,20, 40, 1)
_WinAPI_SetLayeredWindowAttributes($hGUI, 0xABCDEF, 250)

GUISetState()

While 1
$hwnd2 = WinGetHandle("COD4")
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    sleep(50)
    $x = @DesktopWidth/2-40
$y = @DesktopHeight/2-40
_WinAPI_SetWindowPos($hWnd, bitor($HWND_TOP,$HWND_TOPMOST ) ,$x,$y, 40, 40, $SWP_SHOWWINDOW)


WEnd

Func _Exit()
    Exit
EndFunc

Func _WinAPI_SetLayeredWindowAttributes($hwnd, $i_transcolor, $Transparency = 255, $dwFlages = 0x03, $isColorRef = False)
; #############################################
; You are NOT ALLOWED to remove the following lines
; Function Name: _WinAPI_SetLayeredWindowAttributes
; Author(s): Prog@ndy
; #############################################
    If $dwFlages = Default Or $dwFlages = "" Or $dwFlages < 0 Then $dwFlages = 0x03

    If Not $isColorRef Then
        $i_transcolor = Hex(String($i_transcolor), 6)
        $i_transcolor = Execute('0x00' & StringMid($i_transcolor, 5, 2) & StringMid($i_transcolor, 3, 2) & StringMid($i_transcolor, 1, 2))
    EndIf
    Local $Ret = DllCall("user32.dll", "int", "SetLayeredWindowAttributes", "hwnd", $hwnd, "long", $i_transcolor, "byte", $Transparency, "long", $dwFlages)
    Select
        Case @error
            Return SetError(@error, 0, 0)
        Case $Ret[0] = 0
            Return SetError(4, _WinAPI_GetLastError(), 0)
        Case Else
            Return 1
    EndSelect
EndFunc  ;==>_WinAPI_SetLayeredWindowAttributes

need the attached images, and i dunno COD4 title, so you will need to put it wherever the code says COD4, this should work.

post-51495-12588659322167_thumb.jpg

post-51495-12588659362583_thumb.jpg

[center][/center][center]=][u][/u][/center][center][/center]

Link to comment
Share on other sites

  • 4 months later...

here

; *** Start added by AutoIt3Wrapper ***
#include <Constants.au3>
; *** End added by AutoIt3Wrapper ***
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Add_Constants=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WINAPI.au3>
#include <sendmessage.au3>

;Global Const $LWA_ALPHA = 0x2
;Global Const $LWA_COLORKEY = 0x1

HotKeySet("ESC", "_Exit")
$x = @DesktopWidth/2-40
$y = @DesktopHeight/2-40
$hGUI = GUICreate("CROSSHAIR", 40, 40, $x, $y, bitor($WS_POPUP, $WS_CLIPSIBLINGS), bitor($WS_EX_LAYERED, $WS_EX_TOPMOST))
$hwnd = WinGetHandle("CROSSHAIR")
WinSetOnTop("CROSSHAIR","", 1)
WinSetOnTop("COD4","", 0)
GUISetBkColor(0xABCDEF)

GUICtrlCreatePic("ver.jpg", 20,0, 1, 40)
GUICtrlCreatePic("hor.jpg", 0,20, 40, 1)
_WinAPI_SetLayeredWindowAttributes($hGUI, 0xABCDEF, 250)

GUISetState()

While 1
$hwnd2 = WinGetHandle("COD4")
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    sleep(50)
    $x = @DesktopWidth/2-40
$y = @DesktopHeight/2-40
_WinAPI_SetWindowPos($hWnd, bitor($HWND_TOP,$HWND_TOPMOST ) ,$x,$y, 40, 40, $SWP_SHOWWINDOW)


WEnd

Func _Exit()
    Exit
EndFunc

Func _WinAPI_SetLayeredWindowAttributes($hwnd, $i_transcolor, $Transparency = 255, $dwFlages = 0x03, $isColorRef = False)
; #############################################
; You are NOT ALLOWED to remove the following lines
; Function Name: _WinAPI_SetLayeredWindowAttributes
; Author(s): Prog@ndy
; #############################################
    If $dwFlages = Default Or $dwFlages = "" Or $dwFlages < 0 Then $dwFlages = 0x03

    If Not $isColorRef Then
        $i_transcolor = Hex(String($i_transcolor), 6)
        $i_transcolor = Execute('0x00' & StringMid($i_transcolor, 5, 2) & StringMid($i_transcolor, 3, 2) & StringMid($i_transcolor, 1, 2))
    EndIf
    Local $Ret = DllCall("user32.dll", "int", "SetLayeredWindowAttributes", "hwnd", $hwnd, "long", $i_transcolor, "byte", $Transparency, "long", $dwFlages)
    Select
        Case @error
            Return SetError(@error, 0, 0)
        Case $Ret[0] = 0
            Return SetError(4, _WinAPI_GetLastError(), 0)
        Case Else
            Return 1
    EndSelect
EndFunc  ;==>_WinAPI_SetLayeredWindowAttributes

need the attached images, and i dunno COD4 title, so you will need to put it wherever the code says COD4, this should work.

Works nicely, but only if the game is running windowed, when running fullscreen the crosshairs disappears, any trick to get it working fullscreen ?

Link to comment
Share on other sites

  • 4 years later...

You could also simply create a gif file with a crosshair and then load it in a transparent GUI:

Example:

 

#include <WindowsConstants.au3>

$x = @DesktopWidth/2 - 68/2
$y = @DesktopHeight/2 - 68/2

GUICreate("", 68, 68, $x, $y, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))
GUICtrlCreatePic("crosshair.gif",0,0,68,68)
GUISetState()

While 1
    Sleep(25)
WEnd

Regards

EDIT: added a gif file.

 

How do I do this? I don't know how to make or run a GUI file and also i don't know how to combine the GUI and GIF

Link to comment
Share on other sites

How do I do this? I don't know how to make or run a GUI file and also i don't know how to combine the GUI and GIF

 

Perhaps you should check the date of the last reply on this thread, and I'm wondering how come this thread was never locked considering the fact that its discussing games..

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...