-
Notifications
You must be signed in to change notification settings - Fork 3
/
_Window.GUIControl.ahk
90 lines (90 loc) · 2.57 KB
/
_Window.GUIControl.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
Class GUIControl {
__New(_GUIID) {
this._hHost := _GUIID
}
owner {
get {
static GA_ROOTOWNER := 3
return DllCall("User32.dll\GetAncestor", "Ptr", this._hHost, "UInt", GA_ROOTOWNER, "Ptr")
}
}
getPos(ByRef _x:="", ByRef _y:="") {
WinGetPos, _x, _y,,, % "ahk_id " . this.HWND
}
font {
get {
return new this.FontWrapper(this.HWND)
}
set {
return this.font
}
}
Class FontWrapper {
__New(_hControl) {
static GA_ROOT := 2
this.hControl := _hControl
; this.GUIID := DllCall("User32.dll\GetAncestor", "Ptr", _hControl, "UInt", GA_ROOT, "Ptr")
this.GUIID := DllCall("User32.dll\GetParent", "Ptr", _hControl, "Ptr")
this.handle := this._getHandle()
}
_getHandle() {
static WM_GETFONT := 0x31
this.hDC := DllCall("User32.dll\GetDC", "Ptr", this.hControl, "Ptr")
SendMessage, WM_GETFONT, 0, 0,, % "ahk_id " . this.hControl
return DllCall("Gdi32.dll\SelectObject", "Ptr", this.hDC, "Ptr", ErrorLevel, "Ptr")
}
__Delete() {
this._releaseHandle()
; MsgBox, 16,, % A_ThisFunc
; if not (this._releaseHandle())
; MsgBox, 64,, Failed to release the font.
}
_releaseHandle() {
if (this.handle) {
DllCall("Gdi32.dll\SelectObject", "Ptr", this.hDC, "Ptr", this.handle, "Ptr")
return DllCall("User32.dll\ReleaseDC", "Ptr", this.hControl, "Ptr", this.hDC)
}
}
getTextExtentPoint(_text, ByRef _w:="", ByRef _h:="") {
local
_size := "", DllCall("Gdi32.dll\GetTextExtentPoint32", "UPtr", this.hDC, "Str", _text, "Int", StrLen(_text), "Int64P", _size)
(IsByref(_w) && _w := _size &= 0xFFFFFFFF), (IsByref(_h) && _h := >> 32 & 0xFFFFFFFF)
}
color {
set {
try GUI % this.GUIID . ":Font", % "c" . value
GuiControl, Font, % this.hControl
return this.color
}
get { ; ~
; return Format("{1:06X}", DllCall("Gdi32.dll\GetTextColor", "Ptr", this.hDC)) ; http://forum.script-coding.com/viewtopic.php?id=13256 [Сохранить скриншот в файл]
return ""
}
}
name {
set {
try GUI % this.GUIID . ":Font",, % value
GuiControl, Font, % this.hControl
this._releaseHandle(), this._getHandle()
return this.name
}
get {
local
VarSetCapacity(_lpName, 40)
DllCall("Gdi32.dll\GetTextFace", "Ptr", this.hDC, "UInt", 40, "Str", _lpName)
return _lpName
}
}
size {
set {
try GUI % this.GUIID . ":Font", % "s" . value
GuiControl, Font, % this.hControl
this._releaseHandle(), this._getHandle()
return this._size:=value
}
get { ; ~
return ""
}
}
}
}