Jump to content
Sign in to follow this  
KevinO

Help with Crosshair

Recommended Posts

KevinO

Hello there, i want some help with my code :) ,

im new to AutoIT

the problem is that the crosshair isn't center for some reason.

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <Constants.au3>
#include <WinAPI.au3>

Local $iSize = 35

#region GUI
$hGUIMain = GUICreate("")

$hGUIChild = GUICreate("", $iSize, $iSize, -1, -1, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_LAYERED, $WS_EX_TRANSPARENT), $hGUIMain)
GUISetBkColor($COLOR_BLACK)

GUICtrlCreateLabel("", 0, Int($iSize / 2), $iSize, 1)
GUICtrlSetBkColor(-1, $COLOR_BLUE)

GUICtrlCreateLabel("", Int($iSize / 2), 0, 1, $iSize)
GUICtrlSetBkColor(-1, $COLOR_BLUE)

_WinAPI_SetLayeredWindowAttributes($hGUIChild, $COLOR_BLACK)

GUISetState(@SW_SHOWNOACTIVATE, $hGUIChild)
#endregion

While 1
    Sleep(10)
    _WinAPI_SetWindowPos($hGUIChild, $HWND_TOPMOST, 0, 0, 0, 0, BitOR($SWP_NOACTIVATE, $SWP_NOMOVE, $SWP_NOSIZE, $SWP_NOSENDCHANGING))
WEnd

Could you guys please tell me how to make it center so i can learn from it next time :)

BFmvq15.png

The Red one is from the internet, and the blue one is me.... the red one is center

Edited by KevinO

Share this post


Link to post
Share on other sites
Danyfirex

Share this post


Link to post
Share on other sites
KevinO

Welcome.

Look.

Saludos

 

yea i've read it :)... all i want to know is how to make it center thats all :)

Share this post


Link to post
Share on other sites
Maelstrom

Welcome.

Look.

Saludos

Does it interfere with the forum rules?  I see where you are going with this, but it doesn't seem like he is making a bot or anything.

--------------------------------------------------------------------------------------------------------------------------------------------------------

Anyways, back on topic, the reason that the cross hairs are not pointing in the dead center is because of window's menu bar.  For instance if my menu bar is 16 pixels (it isn't, but examples) autoit wouldn't read these 16 pixels as part of the screen.  To center it fully you have to know the size of the task-bar that the user has.

Does that help?

Edited by Maelstrom

Share this post


Link to post
Share on other sites
KevinO

Does it interfere with the forum rules?  I see where you are going with this, but it doesn't seem like he is making a bot or anything.

--------------------------------------------------------------------------------------------------------------------------------------------------------

Anyways, back on topic, the reason that the cross hairs are not pointing in the dead center is because of window's menu bar.  For instance if my menu bar is 16 pixels (it isn't, but examples) autoit wouldn't read these 16 pixels as part of the screen.  To center it fully you have to know the size of the task-bar that the user has.

Does that help?

 

you are right, when i move my menu bar up the cross will get another position.... now my question is how do i fix that?. so the cross will always stay in middle of the screen

Share this post


Link to post
Share on other sites
Maelstrom

you are right, when i move my menu bar up the cross will get another position.... now my question is how do i fix that?. so the cross will always stay in middle of the screen

 

You would have to add in the amount of pixels that your menu bar takes up.

Share this post


Link to post
Share on other sites
KevinO

this is the source from the red one.... but what am i doing wrong in the blue one?

#include <GDIPlus.au3>
#include <WindowsConstants.au3>

Local $hGUI, $hGraphics, $hBitmap, $hBackBuffer, $hPen, $wedith = @DesktopWidth/2, $height = @DesktopHeight/2

_GDIPlus_Startup()
HotKeySet("{ESC}","_Exit")


$hDummy = GUICreate("")
$hGUI = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST,$WS_EX_TRANSPARENT),$hDummy)
GUISetBkColor(0xABCDEF, $hGUI)
_WinAPI_SetLayeredWindowAttributes($hGUI, 0xABCDEF, 255)

$hPen = _GDIPlus_PenCreate(0xFFFF0000,1)
$hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hBitmap = _GDIPlus_BitmapCreateFromGraphics(@DesktopWidth, @DesktopHeight, $hGraphics)
$hBackBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
GUISetState()

While Sleep(10)
    _GDIPlus_GraphicsDrawLine($hGraphics, $wedith-40, $height, $wedith+40, $height, $hPen)
    _GDIPlus_GraphicsDrawLine($hGraphics, $wedith+1, $height-40, $wedith+1, $height+40, $hPen)
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, $wedith, $height)
WEnd


Func _Exit()
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_PenDispose($hPen)
    GUIDelete($hGUI)
    Exit
EndFunc

i don't see it

Share this post


Link to post
Share on other sites
Maelstrom

This is what I mean:

Screen:

l23TypZ.jpg

Menu

Dlbcoph.jpg

Toolbar length:

iJ8mmNL.jpg

So if our toolbar length was 16, and the toolbar was on the left side (like mine is), then your function would be as follows:

#include <GDIPlus.au3>
#include <WindowsConstants.au3>
;//---------------------------------------------------------------------------------VV----------------------------\\;
Local $hGUI, $hGraphics, $hBitmap, $hBackBuffer, $hPen, $wedith = @DesktopWidth/2 + 16, $height = @DesktopHeight/2

_GDIPlus_Startup()
HotKeySet("{ESC}","_Exit")


$hDummy = GUICreate("")
$hGUI = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST,$WS_EX_TRANSPARENT),$hDummy)
GUISetBkColor(0xABCDEF, $hGUI)
_WinAPI_SetLayeredWindowAttributes($hGUI, 0xABCDEF, 255)

$hPen = _GDIPlus_PenCreate(0xFFFF0000,1)
$hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hBitmap = _GDIPlus_BitmapCreateFromGraphics(@DesktopWidth, @DesktopHeight, $hGraphics)
$hBackBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
GUISetState()

This variant of the script moves the pointer 16 to the right.  If I wanted to move it to the left, I would subtract 16 instead of add it.

Get the idea?

Share this post


Link to post
Share on other sites
KevinO

i got it, thx for your helps :)

Share this post


Link to post
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
Sign in to follow this  

×