-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathcolorbuttons.ahk
93 lines (77 loc) · 2.55 KB
/
colorbuttons.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
; Link:
; Author:
; Date:
; for: AHK_L
/*
*/
; Color Buttons - Flat buttons with any text and background color.
;
; ColorButtons(x,by,ty,w,h,bv,tv,g,bc,tc,text)
;
; x = Control's x position. Both the text and background will share this coordinate.
; by = The background's y position. Used only by the background.
; ty = The Text's y position. Used to center text on the background.
; w = Control's width. Used by both background and text.
; H = Background's height. Text height is set with Gui, Font, Size
; bv = Background's variable.
; tv = Text's variable.
; g = Control's glable. Used by both background and text.
; bc = Background Color. Must be a hexadecimal including the 0x prefix.
; tc = Text Color. Overrides color set by Gui, Font, Color
; text = Text button will display.
;
; Tip, to see where the entire text box is in relation to the background insert "Border" in the text options below.
ColorButtons(x,by,ty,w,h,bv,tv,g,bc,tc,text)
{
Global
Gui, Add, Pic, x%x% y%by% w%w% h%h% +0x40 v%bv% g%g%, % "HBITMAP:" . CreateUniDIB(bc) ;
Gui, Add, Text, x%x% y%ty% w%w% c%tc% Center BackgroundTrans v%tv% g%g%, %text%
Return
}
;=================================================================================================
; Modified version of a function by SKAN, 01-Apr-2014, autohotkey.com/boards/viewtopic.php?t=3203
; Creates an uni-colored bitmap of 1 * 1 pixels.
;=================================================================================================
CreateUniDIB(Color)
{
VarSetCapacity(BMBITS, 4, 0)
, Numput(Color, BMBITS, "UInt")
, HBM := DllCall("CreateBitmap", "Int", 1, "Int", 1, "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", 4, "Ptr", &BMBITS)
Return HBM
}
/*
Example Script
Gui, Font, s12 cWhite, Tahoma
#Include, ColorButtons.ahk
;ColorButtons(x,by,ty,w,h,bv,tv,g,bc,tc,text)
ColorButtons(5,5,10,100,30,"exb1","b1","gl1","0xA80903","White","Button 1")
ColorButtons(125,5,10,100,30,"exb2","b2","gl2","0xffffff","Black","Button 2")
ColorButtons(245,5,10,100,30,"exb3","b3","gl3","0x064F93","White","Button 3")
Gui, Show, w350 h100 , Color Buttons
Return
gl1:
click("b1","White","Black")
Return
gl2:
click("b2","Black","Blue")
Return
gl3:
click("b3","White","Black")
Return
click(button,c1,c2)
{
Gui, Font, c%c2%
GuiControl, Font, %button%,
Sleep, 100
Gui, Font, c%c1%
GuiControl, Font, %button%,
}
Exit:
GuiEscape:
GuiClose:
Gui, Destroy
ExitApp
Return
*/