Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Crosshair overlay


  • Please log in to reply
22 replies to this topic
evilc
  • Members
  • 340 posts
  • Last active: Oct 27 2015 11:07 PM
  • Joined: 17 Nov 2005
This will add a crosshair over a selected window

See start for instructions / features

You need a transparent GIF to use as the crosshair image. Default size is 9x9 but you can use any size...

; Generic crosshair overlay v1.0
; By [email protected]

; Instructions:
; =============
; Will ONLY work in WINDOWED mode
; 1) Run app to overlay crosshair to and make it active
; 2) Hit WIN+Insert to designate that as app to overlay to
; 3) Crosshair will appear but probably in wrong place
; 4) Use WIN+Arrow keys to move crosshair to right place

; Crosshair will ONLY appear while designated app is active
; Settings saved to INI file so you only have to set up once

; This is NOT a hack, it merely creates a transparent window
; that has "Always on top" property set
; Custom crosshairs can be used, edit ch.gif and edit size vars below

ch_x = 9    ; X size of ch.gif
ch_y = 9    ; Y size of ch.gif

; DO NOT EDIT BELOW HERE UNLESS YOU KNOW WHAT YOU ARE DOING!
; ==========================================================

; Remove .ahk and .exe from filename to get name for INI file
ScriptName := A_ScriptName
StringReplace, ScriptName, ScriptName, .ahk,, All
StringReplace, ScriptName, ScriptName, .exe,, All

; Find position of window on screen
WinGetPos, winx, winy, winw, winh, ahk_class %progclass%

; PosX and PosY hold offset of cursor within window (From centre)
PosX := 0
PosY := 0

; Read vals from INI file
IniRead, PosX, %ScriptName%.ini, Main, PosX, %PosX%
IniRead, PosY, %ScriptName%.ini, Main, PosY, %PosY%
IniRead, progclass, %ScriptName%.ini, Main, progclass, %progclass%

; Calculate offsets
GoSub, offsetch

; Init overlay
Gui, Add, Picture, w%ch_x% h%ch_y% AltSubmit, ch.gif
Gui, Color, FFFFFF
GoSub, showch
Gui +AlwaysOnTop
WinSet, TransColor, White, %A_ScriptName%
Gui -Caption +ToolWindow

; Hide overlay
GoSub, hidech

; MAIN LOOP
SetTimer, tick, 500

; ================================================================================

; HOTKEYS
#Up::
    PosY -= 1
    GoSub, showch
    IniWrite, %PosY%, %ScriptName%.ini, Main, PosY
return

#Down::
    PosY += 1
    GoSub, showch
    IniWrite, %PosY%, %ScriptName%.ini, Main, PosY
return

#Left::
    PosX -= 1
    GoSub, showch
    IniWrite, %PosX%, %ScriptName%.ini, Main, PosX
return

#Right::
    PosX += 1
    GoSub, showch
    IniWrite, %PosX%, %ScriptName%.ini, Main, PosX
return

#Insert::
    WinGetActiveTitle, wint
    WinGetClass, progclass, %wint%
    IniWrite, %progclass%, %ScriptName%.ini, Main, progclass
return


; Shows the crosshair
showch:
    GoSub, offsetch
    Gui, Show, NA x%chx% y%chy%
return

; Hides the crosshair
hidech:
    Gui, Cancel
return

; Calculate offset
offsetch:
    chx := winx + (winw /2) + PosX
    chy := winy + (winh /2) + PosY
return

tick:
    IfWinActive, ahk_class %progclass%
    {
        ; Check to see if window moved
        WinGetPos, winx, winy, winw, winh, ahk_class %progclass%
        ; Draw crosshair
        GoSub, showch
    }
        else
    {
        GoSub, hidech
    }
return


comvox
  • Members
  • 143 posts
  • Last active: Jan 29 2017 06:53 AM
  • Joined: 20 May 2009
This script seems enticing, and it set me to thinking about where something like this might come in useful. And of course, as you point out, one can change the ch.gif as one pleases. Thus it can be modified to overlay things besides crosshairs. Good work, evilc!

Note that there seems to be something that needs correction. An "AltSubmit" seems to be omitted.
The line
Gui, Add, Picture, w%ch_x% h%ch_y%, ch.gif
should be
Gui, Add, Picture, w%ch_x% h%ch_y% AltSubmit, ch.gif
in order to get the transparency effect.

I think it would be useful to have some way to switch the crosshairs on and off, but it's easy to modify this script and add a hotkey to provide that. And I'll probably also modify the speed of moving the crosshairs. The script is easy to read and modify.

evilc
  • Members
  • 340 posts
  • Last active: Oct 27 2015 11:07 PM
  • Joined: 17 Nov 2005
what does the altsumbit do? It works perfectly for me as-is

comvox
  • Members
  • 143 posts
  • Last active: Jan 29 2017 06:53 AM
  • Joined: 20 May 2009

what does the altsumbit do? It works perfectly for me as-is


Hmmm, curious. When I tried the script, I had some problems at first. It wasn't until I added the AltSubmit that I got the crosshairs gif to be transparent. Until then, I had a crosshairs on a opaque square that moved around on top of the larger window.

Authotkey documentation says:

Specifying the word AltSubmit in Options tells the program to use Microsoft's GDIPlus.dll to load the image, which might result in a different appearance for GIF, BMP, and icon images. For example, it would load an ICO/GIF that has a transparent background as a transparent bitmap, which allows the BackgroundTrans option to take effect. If GDIPlus is not available (see next paragraph), AltSubmit is ignored and the image is loaded using the normal method.



evilc
  • Members
  • 340 posts
  • Last active: Oct 27 2015 11:07 PM
  • Joined: 17 Nov 2005
meh, well if it does no harm and could potentially make it better, it belongs I spose.

OP updated.

Thanks

Personally, I don't really see the need to make it move "faster" as you have to calibrate so rarely. Accuracy is paramount IMHO

Relayer
  • Members
  • 122 posts
  • Last active: Jun 22 2015 09:21 PM
  • Joined: 24 Nov 2008
Here's a favorite of mine for painting a crosshair on the screen. It is from http://www.autohotke...pic.php?t=49950

#NoEnv

SetWinDelay 0
Coordmode Mouse, Screen
Restart:
Selecting := False
OldX := -1, OldY := -1

ID1 := Box(2,1,40)
ID2 := Box(3,40,1)

SetTimer Ruler, 10
Return
;KeyWait, RButton, D
RButton::             ;using hotkey instead of waiting for a key keeps the right click from calling other behavior during script
SetTimer Ruler, Off
Return


Escape::
OutOfHere:
ExitApp

Ruler:
   MouseGetPos RulerX, RulerY
   RulerX := RulerX - 5  ;offset the mouse pointer a bit
   RulerY := RulerY - 5
   If (OldX <> RulerX)
	  OldX := RulerX
   If (OldY <> RulerY)
      OldY := RulerY
   WinMove ahk_id %ID1%,, %RulerX%, % RulerY-20    ;create crosshair by moving 1/2 length of segment
   WinMove ahk_id %ID2%,, % RulerX-20, %RulerY%
   ToolTip (R-click to anchor)
Return

Box(n,wide,high)
{
   Gui %n%:Color, 0,0                  ; Black
   Gui %n%:-Caption +ToolWindow +E0x20 ; No title bar, No taskbar button, Transparent for clicks
   Gui %n%: Show, Center W%wide% H%high%      ; Show it
   WinGet ID, ID, A                    ; ...with HWND/handle ID
   Winset AlwaysOnTop,ON,ahk_id %ID%   ; Keep it always on the top
   WinSet Transparent,255,ahk_id %ID%  ; Opaque
   Return ID
}


evilc
  • Members
  • 340 posts
  • Last active: Oct 27 2015 11:07 PM
  • Joined: 17 Nov 2005
Whilst I quite like the idea...
The macro as-is traps the right mouse button. Therefore, I needed to use CTRL-ALT-DEL to get rid of it. Not good.

The tooltip stays in place.


But as a way of showing you how to draw a crosshair without an image... could be useful.

Patagonier
  • Members
  • 10 posts
  • Last active: Aug 05 2017 01:08 PM
  • Joined: 08 Mar 2011
Here's a slight modification of Relayers crosshairs on screen:
* Hotkey to toggle display on/off
* Hotkey to lock/unlock position
* Hotkey to quit program
* does not trap keys or buttons
Maybe/hopefully useful to somebody...

; This script can make crosshairs appear on your screen.
; You may lock their position.
;
; Start script => nothing will happen (unless you change start-up behaviour)
; Use Ctrl-Numeric0         to toggle display of crosshairs
; Use Ctrl-NumericDot       to lock/unlock position of crosshairs
; Use Numeric0 & NumericDot to quit program


; === Start-up stuff
#NoEnv

SetWinDelay 0
Coordmode Mouse, Screen
Restart:
Selecting := False
OldX := -1, OldY := -1
Locked  := False
Visible := False			;<= determine start-up behaviour

; use VirtualScreen here to support multiple monitors
SysGet, VirtualScreenWidth, 78
SysGet, VirtualScreenHeight, 79
ID1 := Box(2,1,VirtualScreenHeight*2)
ID2 := Box(3,VirtualScreenWidth*2,1)

SetTimer Ruler, 10
if (Visible == False) {
    WinHide ahk_id %ID1%,, 
    WinHide ahk_id %ID2%,, 
}
Return


; === Toggle lock of crosshairs
;KeyWait, RButton, D
^NumpadDot::
;RButton::             ;using hotkey instead of waiting for a key keeps the right click from calling other behavior during script
if (Visible == False) {
    WinShow ahk_id %ID1%,, 
    WinShow ahk_id %ID2%,, 
	Visible := True 
}
if (Locked == False) {
	SetTimer Ruler, Off
	Locked := True 
	}
else {
	SetTimer Ruler, 10
	Locked := False 
	}
Return


; === Toggle display of crosshairs
^Numpad0::
if (Visible == True) {
    WinHide ahk_id %ID1%,, 
    WinHide ahk_id %ID2%,, 
    Visible := False
	}
else {
    WinShow ahk_id %ID1%,,
    WinShow ahk_id %ID2%,,
    Visible := True
}
Return


; === Terminate program
Numpad0::Send {Blind}{Numpad0}	; necessary to make Numpad0 work normally
Numpad0 & NumpadDot::
;Escape::
OutOfHere:
ExitApp




; === Subroutines
Ruler:
   MouseGetPos RulerX, RulerY
   ;RulerX := RulerX - 5  ;enable to offset the mouse pointer a bit
   ;RulerY := RulerY - 5
   If (OldX <> RulerX)
     OldX := RulerX
   If (OldY <> RulerY)
      OldY := RulerY
   WinMove ahk_id %ID1%,, %RulerX%, % RulerY-VirtualScreenHeight    ;create crosshair by moving 1/2 length of segment
   WinMove ahk_id %ID2%,, % RulerX-VirtualScreenWidth, %RulerY%
   ;ToolTip (Ctrl-0 to anchor)
Return

Box(n,wide,high)
{
   Gui %n%:Color, 0,0                  ; Black
   Gui %n%:-Caption +ToolWindow +E0x20 ; No title bar, No taskbar button, Transparent for clicks
   Gui %n%: Show, Center W%wide% H%high%      ; Show it
   WinGet ID, ID, A                    ; ...with HWND/handle ID
   Winset AlwaysOnTop,ON,ahk_id %ID%   ; Keep it always on the top
   WinSet Transparent,255,ahk_id %ID%  ; Opaque
   Return ID
}


aaronbewza
  • Members
  • 466 posts
  • Last active: Feb 05 2013 08:40 AM
  • Joined: 20 Feb 2011
First of all, thank you all very much for these awesome crosshairs! They are way too cool and I must totally appropriate it for my own nefarious uses LOL... I have a question though, I hope one or more of you can shed some light on it:)

Can the crosshairs be made to appear on Monitor 1 only? Variables for my screen size are not working. I'm getting screen size of Monitor 1 like this:
   m1w := Mon1Right-Mon1Left ; Right side minus left side = width of monitor 1
   m1h := Mon1Bottom-Mon1Top ; Bottom side minus top side = height of monitor 1
   StringReplace, m1w, m1w, `.000000, All ; Removes decimal points and places remaining from above calculations
   StringReplace, m1h, m1h, `.000000, All
   StringReplace, m1w, m1w, `.500000, All
   StringReplace, m1h, m1h, `.500000, All


and I'd like to add it to this, to make it only work in Monitor 1:
#NoEnv
SetWinDelay 0
Coordmode Mouse, Screen
Selecting := False
OldX := -1, OldY := -1
Locked  := False
Visible := False         ;<= determine start-up behaviour

; use VirtualScreen here to support multiple monitors
; Maybe here is where I need to plant that other code? =============>>>>

SysGet, VirtualScreenWidth, 78
SysGet, VirtualScreenHeight, 79
ID1 := Box(2,1,VirtualScreenHeight*2)
ID2 := Box(3,VirtualScreenWidth*2,1)
SetTimer Ruler, 10
Return

; === Toggle display of crosshairs
F3::
if (Visible == True) {
    WinHide ahk_id %ID1%,,
    WinHide ahk_id %ID2%,,
    Visible := False
   }
else {
    WinShow ahk_id %ID1%,,
    WinShow ahk_id %ID2%,,
    Visible := True
}
Return

 ; Subroutines
 
Ruler:
   MouseGetPos RulerX, RulerY
   If (OldX <> RulerX)
   OldX := RulerX
   If (OldY <> RulerY)
   OldY := RulerY
   WinMove ahk_id %ID1%,, %RulerX%, % RulerY-VirtualScreenHeight    ;create crosshair by moving 1/2 length of segment
   WinMove ahk_id %ID2%,, % RulerX-VirtualScreenWidth, %RulerY%
Return

Box(n,wide,high)
   {
      Gui %n%:Color, FF0000, 0                  ; Red
      Gui %n%:-Caption +ToolWindow +E0x20 ; No title bar, No taskbar button, Transparent for clicks
      Gui %n%: Show, Center W%wide% H%high%      ; Show it
      WinGet ID, ID, A                    ; ...with HWND/handle ID
      Winset AlwaysOnTop,ON,ahk_id %ID%   ; Keep it always on the top
      WinSet Transparent,255,ahk_id %ID%  ; Opaque
      Return ID
   }

Esc::
ExitApp

EDIT: I can use this "as is" but I'm using
Gui, Add, ActiveX
to show both a Flash menu, and to embed an Adobe Reader PDF... and when the crosshairs are placed overtop the PDF, they are placed underneath and cannot be seen. I can get the one working on top of the PDF from here:
http://www.autohotke...opic.php?t=2006
but somehow i broke it and now it doesn't work :(

  • Guests
  • Last active:
  • Joined: --
You can enter the pixelcoordinates for your screen instead.


#NoEnv
SetWinDelay 0
Coordmode Mouse, Screen
Selecting := False

Locked  := False
Visible := True         ;<= determine start-up behaviour

; use VirtualScreen here to support multiple monitors
; Maybe here is where I need to plant that other code? =============>>>>

xl=10         ;left screenpixel of horizontal crosshair
xr=1100       ;right

yt=10         ;upper screenpixel of vertical crosshair
yb=860       ;lower screenpixel

m1w:=xr-xl
m1h:=yb-yt

ID1 := Box(2,1,m1h)
ID2 := Box(3,m1w,1)

SetTimer Ruler, 10

if (Visible == False) {
    WinHide ahk_id %ID1%,, 
    WinHide ahk_id %ID2%,, 
}
Return

; === Toggle display of crosshairs
F3::
if (Visible == True) {
    WinHide ahk_id %ID1%,,
    WinHide ahk_id %ID2%,,
    Visible := False
   }
else {
    WinShow ahk_id %ID1%,,
    WinShow ahk_id %ID2%,,
    Visible := True
}
Return

 ; Subroutines
ruler:
MouseGetPos, xpos,ypos
WinMove ahk_id %ID1%,, xpos ,yt
WinMove ahk_id %ID2%,, xl   ,ypos

WinSet, alwaysontop,on,ahk_id %ID1%   ;to get them ontop of other windows 
WinSet, alwaysontop,on,ahk_id %ID2%   ;that are also ontop
return 


Box(n,wide,high)
   {
      Gui %n%:Color, FF0000, 0                  ; Red
      Gui %n%:-Caption +ToolWindow +E0x20 ; No title bar, No taskbar button, Transparent for clicks
      Gui %n%: Show, Center W%wide% H%high%      ; Show it
      WinGet ID, ID, A                    ; ...with HWND/handle ID
      Winset AlwaysOnTop,ON,ahk_id %ID%   ; Keep it always on the top
      WinSet Transparent,255,ahk_id %ID%  ; Opaque
      Return ID
   }

Esc::
ExitApp


aaronbewza
  • Members
  • 466 posts
  • Last active: Feb 05 2013 08:40 AM
  • Joined: 20 Feb 2011
wow! "if (Visible == False)" really looks like the answer, thqank you very much, Guest! After the daughter is done her soccer game I'm going to mess with this. Pretty exciting stuff! This is for "Tattoo Design Machine" for Users to be able to select, copy and paste selections of designs into an editor (on monitor 2) from a PDF document (on monitor 1).
Thanks again! :D

aaronbewza
  • Members
  • 466 posts
  • Last active: Feb 05 2013 08:40 AM
  • Joined: 20 Feb 2011
...although Guest's code did not produce any changes in the crosshairs while mouse was not in Monitor 1,
he/she had arranged it in such a way that I was able to mess with it enough to work the way I'd like it to.
thank you Guest :D

This works to keep the crosshairs on Monitor 1, and if User moves mouse to another monitor, the crosshairs hide:
#NoEnv
SetWinDelay, 0 ; Shortens Win commands by removing the default delay
Coordmode, Mouse, Screen ; Mouse coordinates are relative to screen, not to gui

SysGet, Mon1, Monitor, 1 ; Retrieves information about monitor 1's coordinates
m1w := Mon1Right-Mon1Left ; Right side minus left side = width of monitor 1
m1h := Mon1Bottom-Mon1Top ; Bottom side minus top side = height of monitor 1
m1l = %Mon1Left% ; ---- Shortens these variables ---->>
m1t = %Mon1Top% ; -----------------------------------<<

; Sets bevavior for the crosshairs ---------------------------------->>
   Selecting := False
   Locked := False
   Visible := False ; Startup state of crosshairs
   ID1 := Box(98, 2, m1h) ; Box: 98=gui#, 1px wide (adjustable), m1h height
   ID2 := Box(99, m1w, 2) ; Box: 99=gui#, m1h height, 1px wide (adjustable)
   SetTimer, Crosshairs, 20 ; 20ms for each move of the crosshairs
; -------------------------------------------------------------------<<
Return

; --------- Creates crosshairs  --------------------------------------------------------------------->>

Crosshairs:
   MouseGetPos, MouseX, MouseY
;   tooltip, x%MouseX% x%MouseY% ; Tooltip, displays x and y coordinates
; This next section needs determines if mouse is not on Monitor 1, but needs a better method...
; as User's primary monitor may be to the right, or above, or underneath any other ones.
   If (MouseX < 0)
      {
         SetTimer, Crosshairs, Off
         WinHide, ahk_id %ID1%
         WinHide, ahk_id %ID2%
      }
   If (MouseX > 0) ; Needs a better way to determine this, same as above
      {
         SetTimer, Crosshairs, On
         WinShow, ahk_id %ID1% ; Shows vertical crosshair
         WinShow, ahk_id %ID2% ; Shows horizontal crosshair
         WinMove, ahk_id %ID1%,, MouseX, m1t ; Moves the vertical crosshair to current mouse position
         WinMove, ahk_id %ID2%,, m1l, MouseY ; Moves the horizontal crosshair to current mouse position
         WinSet, AlwaysOnTop, On, ahk_id %ID1% ; Sets vertical crosshair always on top
         WinSet, AlwaysOnTop, On, ahk_id %ID2% ; Sets horizontal crosshair always on top
      }
   Else
      {
         SetTimer, Crosshairs, On
         Visible := True
      }
Return

; --------- Crosshairs function -------------------------------------------------------------------->>
 
Box(n, CrossX, CrossY)
   {
      Gui, 98: Color, FF0000 ; Red crosshair X, (actual Gui numbers are used in these two lines as using %n% leaves color artifacts from other Guis)
      Gui, 99: Color, FF0000 ; Red crosshair Y
      Gui, %n%: -Caption +ToolWindow +E0x20 ; No title bar or taskbar button, '+E0x20' lets User click through to gui underneath
      Gui, %n%: Show, Center w%CrossX% h%CrossY% ; Shows horizontal and vertical lines
      WinGet, ID, ID, A ; Gets HWND/handle ID
      Winset, AlwaysOnTop, On, ahk_id %ID%   ; Always on top
      WinSet, Transparent, 180, ahk_id %ID%  ; Adjust transparency here
      Return ID
   }

Esc::
ExitApp

I used Gui 98: and Gui 99: as literal number assignments for the crosshair guis... this seems to avoid
coloring artifacts as Gui %n%: sometimes thinks it is something else entirely.

I see one potential disaster waiting to happen, though, (MouseX < 0) and (MouseX > 0)
need to be replaced with something more reliable, as User might have their second monitor placed to the right of Monitor 1, or underneath,
or above. I don't know of another way to do that... working on it :)

bcn_246
  • Guests
  • Last active:
  • Joined: --
Thanks tomoe_uehara! Worked perfectly...

Found That A_ScreenWidth/2-nWidth/2/A_ScreenHeight/2-NHeight/2 put the crosshair in the centre without having to manually offset (well, 1 pixel left/down... as the posted .png is 25x25, but I changed that anyway).

Updated the script, also noticed that when the mouse was hovered over it changed (if editing text, from the 'I' back to the cursor). Added +Ex20 to fix this.

I know it's a very old post, but just in case anybody searching wants to use Wickedness's script here is a revised version:

; Wickedness' Crosshair Script (September 8th, 2008)
; --------------------------------------------------
; 
;    Modified by bcn_246 (January 9th, 2012)
;
;    http://www.autohotkey.com/forum/topic35517.html

sFile   := "Crosshair.png"   ;Removed the 'C:\' (the image's default location is now wherever this script is located)

mDC_Scr   := Gdi_CreateCompatibleDC(0)
pToken   := Gdip_Startup()
pBitmap   := !hIcon ? Gdip_CreateBitmapFromFile(sFile) : Gdip_CreateBitmapFromHICON(hIcon)
nWidth   := Gdip_GetImageWidth( pBitmap)
nHeight   := Gdip_GetImageHeight(pBitmap)
hBitmap   := !hIcon ? Gdip_CreateHBITMAPFromBitmap(pBitmap) : Gdi_CreateDIBSection(mDC_Scr, nWidth, nHeight)
Gdip_DisposeImage(pBitmap)
Gdip_Shutdown(pToken)
oBitmap   := Gdi_SelectObject(mDC_Scr, hBitmap)
XPos := A_ScreenWidth/2-(nWidth/2)   ;Added to centre the crosshair
YPos := A_ScreenHeight/2-(nHeight/2)   ;Added to centre the crosshair

If   hIcon
   DllCall("DrawIconEx", "Uint", mDC_Scr, "int", 0, "int", 0, "Uint", hIcon, "int", nWidth, "int", nHeight, "Uint", 0, "Uint", 0, "Uint", 1|2)

Gui, +LastFound -Caption +E0x80000 +ToolWindow +AlwaysOnTop +E0x20   ;Added parameter (to prevent the cursor changing when over the crosshair)
DllCall("UpdateLayeredWindow", "Uint", WinExist(), "Uint", 0, "Uint", 0, "int64P", nWidth|nHeight<<32, "Uint", mDC_Scr, "int64P", 0, "Uint", 0, "UintP", 255<<16|1<<24, "Uint", 2)
Gui, Show, W%nWidth% H%nHeight% X%XPos% Y%YPos%, Crosshair   ;Added X and Y positions

Gdi_SelectObject(mDC_Scr, oBitmap)
Gdi_DeleteObject(hBitmap)
Gdi_DeleteDC(mDC_Scr)

Gdi_CreateDIBSection(hDC, nW, nH, bpp = 32, ByRef pBits = "")
{
   NumPut(VarSetCapacity(bi, 40, 0), bi)
   NumPut(nW, bi, 4)
   NumPut(nH, bi, 8)
   NumPut(bpp, NumPut(1, bi, 12, "UShort"), 0, "Ushort")
 
   Return   DllCall("gdi32\CreateDIBSection", "Uint", hDC, "Uint", &bi, "Uint", 0, "UintP", pBits, "Uint", 0, "Uint", 0)
}

Gdi_CreateCompatibleDC(hDC = 0)
{
   Return   DllCall("gdi32\CreateCompatibleDC", "Uint", hDC)
}

Gdi_SelectObject(hDC, hGdiObj)
{
   Return   DllCall("gdi32\SelectObject", "Uint", hDC, "Uint", hGdiObj)
}

Gdi_DeleteObject(hGdiObj)
{
   Return   DllCall("gdi32\DeleteObject", "Uint", hGdiObj)
}

Gdi_DeleteDC(hDC)
{
   Return   DllCall("gdi32\DeleteDC", "Uint", hDC)
}

Gdip_CreateBitmapFromFile(sFile)
{
   VarSetCapacity(wFile, 1023)
   DllCall("kernel32\MultiByteToWideChar", "Uint", 0, "Uint", 0, "Uint", &sFile, "int", -1, "Uint", &wFile, "int", 512)
   DllCall("gdiplus\GdipCreateBitmapFromFile", "Uint", &wFile, "UintP", pBitmap)
   Return   pBitmap
}

Gdip_CreateBitmapFromHICON(hIcon)
{
   DllCall("gdiplus\GdipCreateBitmapFromHICON", "Uint", hIcon, "UintP", pBitmap)
   Return   pBitmap
}

Gdip_CreateHBITMAPFromBitmap(pBitmap, ARGB = 0)
{
   DllCall("gdiplus\GdipCreateHBITMAPFromBitmap", "Uint", pBitmap, "UintP", hBitmap, "Uint", ARGB)
   Return   hBitmap
}

Gdip_DisposeImage(pImage)
{
   Return   DllCall("gdiplus\GdipDisposeImage", "Uint", pImage)
}

Gdip_GetImageWidth(pImage)
{
   DllCall("gdiplus\GdipGetImageWidth", "Uint", pImage, "UintP", nW)
   Return   nW
}

Gdip_GetImageHeight(pImage)
{
   DllCall("gdiplus\GdipGetImageHeight", "Uint", pImage, "UintP", nH)
   Return   nH
}

Gdip_Startup()
{
   If Not   DllCall("GetModuleHandle", "str", "gdiplus")
   DllCall("LoadLibrary"    , "str", "gdiplus")
   VarSetCapacity(si, 16, 0), si := Chr(1)
   DllCall("gdiplus\GdiplusStartup", "UintP", pToken, "Uint", &si, "Uint", 0)
   Return   pToken
}

Gdip_Shutdown(pToken)
{
   DllCall("gdiplus\GdiplusShutdown", "Uint", pToken)
   If   hModule :=   DllCall("GetModuleHandle", "str", "gdiplus")
         DllCall("FreeLibrary"    , "Uint", hModule)
   Return   0
} 

; End of the script


Dinz
  • Guests
  • Last active:
  • Joined: --
Can someone tell me where i should paste these codes?

Scenically
  • Members
  • 1 posts
  • Last active: Feb 14 2014 04:12 PM
  • Joined: 12 Feb 2014

Apologies for the grave digging and what not but I just want to ask

 

How do you change the crosshair color for this one:

#NoEnv

SetWinDelay 0
Coordmode Mouse, Screen
Restart:
Selecting := False
OldX := -1, OldY := -1

ID1 := Box(2,1,40)
ID2 := Box(3,40,1)

SetTimer Ruler, 10
Return
;KeyWait, RButton, D
RButton::             ;using hotkey instead of waiting for a key keeps the right click from calling other behavior during script
SetTimer Ruler, Off
Return


F2::
OutOfHere:
ExitApp

Ruler:
   MouseGetPos RulerX, RulerY
   RulerX := RulerX - 5  ;offset the mouse pointer a bit
   RulerY := RulerY - 5
   If (OldX <> RulerX)
	  OldX := RulerX
   If (OldY <> RulerY)
      OldY := RulerY
   WinMove ahk_id %ID1%,, %RulerX%, % RulerY-20    ;create crosshair by moving 1/2 length of segment
   WinMove ahk_id %ID2%,, % RulerX-20, %RulerY%
Return

Box(n,wide,high)
{
   Gui %n%:Color, 0,0                  ; Black
   Gui %n%:-Caption +ToolWindow +E0x20 ; No title bar, No taskbar button, Transparent for clicks
   Gui %n%: Show, Center W%wide% H%high%      ; Show it
   WinGet ID, ID, A                    ; ...with HWND/handle ID
   Winset AlwaysOnTop,ON,ahk_id %ID%   ; Keep it always on the top
   WinSet Transparent,255,ahk_id %ID%  ; Opaque
   Return ID
}

I've tried a lot of different things all of which haven't worked...

I want a red crosshair variant