How to detect the position an image loaded in a GUI has been clicked?
Posted: 28 Nov 2021, 14:18
How i could detect the exactly position where the image in the GUI has been clicked?
The image is 100x100px, so im trying to figure which area in this range has been clicked. Using random to illustrate that the image could be in a different position:
This is what i already did but im not getting it, confused
The image is 100x100px, so im trying to figure which area in this range has been clicked. Using random to illustrate that the image could be in a different position:
Code: Select all
Random, X, 0, 500
Random, Y, 0, 200
Gui, Add, Picture, x%x% y%y%, % "HBITMAP:" . LoadPicture("tile.png")
Gui, Show, w600 h300
This is what i already did but im not getting it, confused
Code: Select all
Random, X, 0, 500
Random, Y, 0, 200
Gui, Add, Picture, x%x% y%y% gClick, % "HBITMAP:" . LoadPicture("tile.png")
Gui, Show, w600 h300
Gui, P: +hwndGuiP -Caption
Gui, P: Add, Picture, x0 y0, % "HBITMAP:" . LoadPicture("tile.png")
Gui, P: Show, w100 h100
return
Click() {
CoordMode, Mouse, Relative
MouseGetPos, X, Y
FileAppend, X: %X% Y: %Y%`n,*
VarSetCapacity(POINT, 8)
NumPut(X, &POINT, 0, "Int")
NumPut(Y, &POINT, 4, "Int")
DllCall("user32\ScreenToClient", Ptr, GuiP, Ptr, &POINT)
_X := NumGet(&POINT, 0, "Int")
_Y := NumGet(&POINT, 4, "Int")
FileAppend, `nX: %X% Y: %Y%`n,*
FileAppend, _X: %_X% _Y: %_Y%`n,*
}