Code: Select all
varwidth=25
varheight=25
Gui 1: Add , picture, vMyPicture x10 y10 w%varwidth% h%varheight% C:\Pic1.bmp
Gui 1: Show, x400 y400 w100 h100, PICTURES
ControlGetPos, x1, y1, w1, h1, MyPicture, PICTURES
tooltip, %x1% %y1% %w1% %h1%
return
Code: Select all
varwidth=25
varheight=25
Gui 1: Add , picture, vMyPicture x10 y10 w%varwidth% h%varheight% C:\Pic1.bmp
Gui 1: Show, x400 y400 w100 h100, PICTURES
ControlGetPos, x1, y1, w1, h1, MyPicture, PICTURES
tooltip, %x1% %y1% %w1% %h1%
return
Code: Select all
varwidth=25
varheight=25
Gui 1: Add , picture, vMyPicture x10 y10 w%varwidth% h%varheight%, % "C:\Users\Jérémy\Pictures\Sans titre.png"
Gui 1: Show, x400 y400 w100 h100, PICTURES
ControlGetPos, x1, y1, w1, h1, Static1, PICTURES
tooltip, %x1% %y1% %w1% %h1%
return
see: https://www.autohotkey.com/docs/command ... GetPos.htmCan be either ClassNN (the classname and instance number of the control) or the control's text, both of which can be determined via Window Spy
Code: Select all
varwidth=25
varheight=25
Gui 1: Add , picture, hwndID vMyPicture x10 y10 w%varwidth% h%varheight%, % "C:\Users\Jérémy\Pictures\Sans titre.png"
Gui 1: Show, x400 y400 w100 h100, PICTURES
ControlGetPos, x1, y1, w1, h1,, % "ahk_id " . ID
tooltip, %x1% %y1% %w1% %h1%
return
To operate upon a control's HWND (window handle), leave the Control parameter blank and specify ahk_id %ControlHwnd% for the WinTitle parameter (this also works on hidden controls even when DetectHiddenWindows is Off).
Code: Select all
GuiControlGet, MyPicture, 1:Pos
Tooltip, %MyPictureX% %MyPictureY% %MyPictureW% %MyPictureH%
Note nevertheless that in this code...scriptor2016 wrote:All I had to do was replace "MyPicture" with "Static1" and it returns the proper values. Static2 for the 2nd picture, static 3 for the third, and so on.
Code: Select all
Gui, Add, Text, x1 y1, blabla
varwidth=25
varheight=25
Gui 1: Add , picture, vMyPicture x100 y10 w%varwidth% h%varheight%, % "C:\Users\Jérémy\Pictures\Sans titre.png"
Gui 1: Show, x400 y400 w400 h400, PICTURES
ControlGetPos, x1, y1, w1, h1, Static1, PICTURES
tooltip, %x1% %y1% %w1% %h1%
return
Code: Select all
color001=A2BF87
Gui,1: Add, Progress, x0 y0 w20 h20 Background%color001% vbutton001
Gui,1: Show, x500 y500 w50 h50 ,SWATCHES
OnMessage(0x201, "WM_LBUTTONDOWN")
return
WM_LBUTTONDOWN(wParam, lParam)
{
;check first if the left click happened ontop of a control- can be [i]any[/i] control for the time being (I might need to specify [i]which[/i] control later)
;if so, do stuff
;if not, just regular left click
return
}
see: https://www.autohotkey.com/docs/command ... GetPos.htmthe name of the variable in which to store the name (ClassNN) of the control under the mouse cursor.
Code: Select all
color001=A2BF87
Gui,1: Add, Progress, x0 y0 w20 h20 Background%color001% vbutton001
Gui,1: Show, x500 y500 w550 h550 ,SWATCHES
OnMessage(0x201, "WM_LBUTTONDOWN")
return
WM_LBUTTONDOWN(wParam, lParam)
{
MouseGetPos,,,, OutputVarControl
if (InStr(OutputVarControl, "progress")) ; for example msctls_progress321 class NN
MsgBox % OutputVarControl
}
Code: Select all
varwidth=35 ;change this value to change the size of the swatch widths
varheight=35 ;change this value to change the size of the swatch heights
x+=%varwidth%
y+=%varheight%
x+=1
y+=0
001=f4e7bd
002=CFDEC7
003=A3BF96
004=B25921
Gui 1: -Caption +Border +ToolWindow +AlwaysOnTop
Gui 1: Color, 000000
Gui,1:Add,Progress, x0 y%y% w%varwidth% h%varheight% Background%001% vbutton001
Gui,1:Add,Progress, x%x% y%y% w%varwidth% h%varheight% Background%002% vbutton002
x+=%varwidth%
y+=%varheight%
x+=1 ;add a single pixel vertical line in between swatches
Gui,1:Add,Progress, x%x% y%varheight% w%varwidth% h%varheight% Background%003% vbutton003
x+=%varwidth%
y+=%varheight%
x+=1 ;add a single pixel vertical line in between swatches
Gui,1:Add,Progress, x%x% y%varheight% w%varwidth% h%varheight% Background%004% vbutton004
x+=%varwidth%
y+=%varheight%
x+=1 ;add a single pixel vertical line in between swatches
j=4
k=2
m:=(varwidth*j)
n:=(varheight*k)
Gui,1: Show, x400 y400 w%m% h%n% ,SWATCHES
OnMessage(0x201, "WM_LBUTTONDOWN")
return
WM_LBUTTONDOWN(wParam, lParam)
{
MouseGetPos,,,, OutputVarControl
if (InStr(OutputVarControl, "progress"))
{
CoordMode Pixel, Screen
CoordMode Mouse, Screen
MouseGetPos X, Y
PixelGetColor Color, %X%, %Y%, RGB
clipboard=%Color%
String := clipboard
StringTrimLeft, OutputVar, String, 2
Clipboard := OutputVar
ControlGetPos, x, y, w, h, %OutputVarControl%, SWATCHES
PreviousOutputVarControl :=OutputVarControl
x+=1
y+=1
w-=4
h-=4
GuiControl, Hide, %OutputVarControl%
Gui,1:Add,Progress, x%x% y%y% w%w% h%h% Background%clipboard%
return
}
else
return
}
Code: Select all
; Requires AHK 1.1.23.+
#NoEnv
SetBatchLines, -1
VarWidth := 35 ;change this value to change the size of the swatch widths
VarHeight := 35 ;change this value to change the size of the swatch heights
X := 0
Y := VarHeight
Swatches := 4
BG1 := "f4e7bd"
BG2 := "CFDEC7"
BG3 := "A3BF96"
BG4 := "B25921"
SelectedControl := ""
Gui 1:Margin, 0, 0
Gui 1:-Caption +Border +ToolWindow +AlwaysOnTop
Gui 1:Color, 000000
Loop, %Swatches%
{
HBM := CreateDIB("0x" . BG%A_Index%)
Gui 1:Add, Pic, X%X% Y%Y% w%VarWidth% h%VarHeight% vSwatch%A_Index% gSelectColor, HBITMAP:%HBM%
X += VarWidth + 1 ;add a single pixel vertical line in between Swatches
}
Gui,1: Show, x400 y400, Swatches
Return
SelectColor:
If (A_GuiControl <> SelectedControl)
{
If (SelectedControl)
{
GuiControlGet, P, 1:Pos, %SelectedControl%
PX -= 2
PY -= 2
PW += 4
PH += 4
GuiControl, 1:MoveDraw, %SelectedControl%, X%PX% Y%PY% w%PW% h%PH%
}
ColorIndex := SubStr(A_GuiControl, 7)
Clipboard := BG%ColorIndex%
GuiControlGet, P, 1:Pos, %A_GuiControl%
PX += 2
PY += 2
PW -= 4
PH -= 4
GuiControl, 1:MoveDraw, %A_GuiControl%, X%PX% Y%PY% w%PW% h%PH%
SelectedControl := A_GuiControl
Tooltip, %Clipboard% ; just for testing
}
Return
; ==================================================================================================================================
; Modified version of a function by SKAN, 01-Apr-2014, autohotkey.com/boards/viewtopic.php?t=3203
; Creates an uni-colored bitmap of 2 * 2 pixels.
; ==================================================================================================================================
CreateDIB(Color) {
Static W := 2, H := 2
Static SLL := (W * 3) ; length of a scan line in a 24-bit (3-byte) bitmap (must be word aligned)
VarSetCapacity(BMBITS, SLL * H, 0)
P := &BMBITS
Loop, % H ; loop thru the rows
Loop, % W ; loop thru the pixels per row
P := Numput(Color, P + 0, "UInt") - 1
HBM := DllCall("CreateBitmap", "Int", W, "Int", H, "UInt", 1, "UInt", 24, "Ptr", 0, "UPtr")
HBM := DllCall("CopyImage", "Ptr", HBM, "UInt", 0, "Int", 0, "Int", 0, "UInt", 0x2008, "UPtr")
DllCall("SetBitmapBits", "Ptr", HBM, "UInt", SLL * H, "Ptr", &BMBITS)
Return DllCall("CopyImage", "Ptr", HBM, "UInt", 0, "Int", W, "Int", H, "UInt", 0x200C, "UPtr")
}
I don't think so.scriptor2016 wrote:If I upgrade, will it affect any of my current scripts?
Code: Select all
While (Index <= Swatches) {
X := "xm"
Loop, % SwatchesPerRow
{
Gui 1:Add, Pic, %X% Y%Y% w%VarWidth% h%VarHeight% vSwatch%Index% hwndHCTL 0x4E gSelectColor
DllCall("SendMessage", "Ptr", HCTL, "UInt", 0x0172, "Ptr", 0, "Ptr", CreateDIB("0x" . BG%Index%))
X := "x+1"
Index++
} Until (Index > Swatches)
Y += VarHeight + 1
}
Code: Select all
; Requires AHK 1.1.23.+
#NoEnv
SetBatchLines, -1
VarWidth := 35 ;change this value to change the size of
the swatch widths
VarHeight := 35 ;change this value to change the size of
the swatch heights
X := 0
Y := VarHeight
Swatches := 4
BG1 := "f4e7bd"
BG2 := "CFDEC7"
BG3 := "A3BF96"
BG4 := "B25921"
SelectedControl := ""
Gui 1:Margin, 0, 0
Gui 1:-Caption +Border +ToolWindow +AlwaysOnTop
Gui 1:Color, 000000
While (Index <= Swatches) {
X := "xm"
Loop, % SwatchesPerRow
{
Gui 1:Add, Pic, %X% Y%Y% w%VarWidth% h%VarHeight%
vSwatch%Index% hwndHCTL 0x4E gSelectColor
DllCall("SendMessage", "Ptr", HCTL, "UInt", 0x0172,
"Ptr", 0, "Ptr", CreateDIB("0x" . BG%Index%))
X := "x+1"
Index++
} Until (Index > Swatches)
Y += VarHeight + 1
}
Gui,1: Show, x400 y400, Swatches
Return
SelectColor:
If (A_GuiControl <> SelectedControl)
{
If (SelectedControl)
{
GuiControlGet, P, 1:Pos, %SelectedControl%
PX -= 2
PY -= 2
PW += 4
PH += 4
GuiControl, 1:MoveDraw, %SelectedControl%, X%PX%
Y%PY% w%PW% h%PH%
}
ColorIndex := SubStr(A_GuiControl, 7)
Clipboard := BG%ColorIndex%
GuiControlGet, P, 1:Pos, %A_GuiControl%
PX += 2
PY += 2
PW -= 4
PH -= 4
GuiControl, 1:MoveDraw, %A_GuiControl%, X%PX% Y%PY%
w%PW% h%PH%
SelectedControl := A_GuiControl
Tooltip, %Clipboard% ; just for testing
}
Return
CreateDIB(Color) {
Static W := 2, H := 2
Static SLL := (W * 3) ; length of a scan line in a 24-
bit (3-byte) bitmap (must be word aligned)
VarSetCapacity(BMBITS, SLL * H, 0)
P := &BMBITS
Loop, % H ; loop thru the rows
Loop, % W ; loop thru the pixels per row
P := Numput(Color, P + 0, "UInt") - 1
HBM := DllCall("CreateBitmap", "Int", W, "Int", H,
"UInt", 1, "UInt", 24, "Ptr", 0, "UPtr")
HBM := DllCall("CopyImage", "Ptr", HBM, "UInt", 0,
"Int", 0, "Int", 0, "UInt", 0x2008, "UPtr")
DllCall("SetBitmapBits", "Ptr", HBM, "UInt", SLL * H,
"Ptr", &BMBITS)
Return DllCall("CopyImage", "Ptr", HBM, "UInt", 0,
"Int", W, "Int", H, "UInt", 0x200C, "UPtr")
}
Code: Select all
Loop, %Swatches%
{
Gui 1:Add, Pic, %X% Y%Y% w%VarWidth% h%VarHeight% vSwatch%A_Index% hwndHCTL 0x4E gSelectColor
DllCall("SendMessage", "Ptr", HCTL, "UInt", 0x0172, "Ptr", 0, "Ptr", CreateDIB("0x" . BG%A_Index%))
X += VarWidth + 1 ;add a single pixel vertical line in between Swatches
}
Users browsing this forum: No registered users and 355 guests