#Persistent
SetTimer, Show_Sound, 100
Return
Show_Sound:
MouseGetPos,mX,mY,
SoundGet, CurSound
CurSound:=Round(CurSound)
if !hToolTip
hToolTip := CustomToolTip({text: "Громкость: " . CurSound, x: mX, y: mY}*)
else {
if !(CurSound = prevCurSound)
UpdateText(hTooltip, "Громкость: " . CurSound), prevCurSound := CurSound
if !(mX = prevMx && mY = prevMy) {
SendMessage, TTM_TRACKPOSITION := 0x412,, mX | (mY << 16),, ahk_id %hToolTip%
prevMx := mX, prevMy := mY
}
}
return
CustomToolTip( text, x := "", y := "", title := ""
, icon := 0 ; can be 1 — Info, 2 — Warning, 3 — Error, if greater than 3 — hIcon
, transparent := false
, closeButton := false, backColor := "", textColor := 0
, fontName := "", fontOptions := "" ; like in GUI
, isBallon := false, timeout := "", maxWidth := 600 )
{
static ttStyles := (TTS_NOPREFIX := 2) | (TTS_ALWAYSTIP := 1), TTS_BALLOON := 0x40, TTS_CLOSE := 0x80
, TTF_TRACK := 0x20, TTF_ABSOLUTE := 0x80
, TTM_SETMAXTIPWIDTH := 0x418, TTM_TRACKACTIVATE := 0x411, TTM_TRACKPOSITION := 0x412
, TTM_SETTIPBKCOLOR := 0x413, TTM_SETTIPTEXTCOLOR := 0x414
, TTM_ADDTOOL := A_IsUnicode ? 0x432 : 0x404
, TTM_SETTITLE := A_IsUnicode ? 0x421 : 0x420
, TTM_UPDATETIPTEXT := A_IsUnicode ? 0x439 : 0x40C
, WM_SETFONT := 0x30, WM_GETFONT := 0x31
, WS_EX_TRANSPARENT := 0x00000020
, exStyles := (WS_EX_TOPMOST := 0x00000008) | (WS_EX_COMPOSITED := 0x2000000) | (WS_EX_LAYERED := 0x00080000)
dhwPrev := A_DetectHiddenWindows
DetectHiddenWindows, On
defGuiPrev := A_DefaultGui, lastFoundPrev := WinExist()
hWnd := DllCall("CreateWindowEx", "UInt", exStyles | WS_EX_TRANSPARENT * !!transparent, "Str", "tooltips_class32", "Str", ""
, "UInt", ttStyles | TTS_CLOSE * !!CloseButton | TTS_BALLOON * !!isBallon
, "Int", 0, "Int", 0, "Int", 0, "Int", 0, "Ptr", 0, "Ptr", 0, "Ptr", 0, "Ptr", 0, "Ptr")
WinExist("ahk_id" . hWnd)
if (textColor != 0 || backColor != "") {
DllCall("UxTheme\SetWindowTheme", "Ptr", hWnd, "Ptr", 0, "Str", "")
ByteSwap := Func("DllCall").Bind("msvcr100\_byteswap_ulong", "UInt")
SendMessage, TTM_SETTIPBKCOLOR , ByteSwap.Call(backColor << 8)
SendMessage, TTM_SETTIPTEXTCOLOR, ByteSwap.Call(textColor << 8)
}
if (fontName || fontOptions) {
Gui, New
Gui, Font, % fontOptions, % fontName
Gui, Add, Text, hwndhText
SendMessage, WM_GETFONT,,,, ahk_id %hText%
SendMessage, WM_SETFONT, ErrorLevel
Gui, Destroy
Gui, %defGuiPrev%: Default
}
if (x = "" || y = "")
DllCall("GetCursorPos", "Int64P", pt)
(x = "" && x := (pt & 0xFFFFFFFF) + 15), (y = "" && y := (pt >> 32) + 15)
VarSetCapacity(TOOLINFO, sz := 24 + A_PtrSize*6, 0)
NumPut(sz, TOOLINFO)
NumPut(TTF_TRACK | TTF_ABSOLUTE * !isBallon, TOOLINFO, 4)
NumPut(&text, TOOLINFO, 24 + A_PtrSize*3)
SendMessage, TTM_SETTITLE , icon, &title
SendMessage, TTM_TRACKPOSITION , , x | (y << 16)
SendMessage, TTM_SETMAXTIPWIDTH, , maxWidth
SendMessage, TTM_ADDTOOL , , &TOOLINFO
SendMessage, TTM_UPDATETIPTEXT , , &TOOLINFO
SendMessage, TTM_TRACKACTIVATE , true, &TOOLINFO
if timeout {
Timer := Func("DllCall").Bind("DestroyWindow", "Ptr", hWnd)
SetTimer, % Timer, % "-" . timeout
}
WinExist("ahk_id" . lastFoundPrev)
DetectHiddenWindows, % dhwPrev
Return hWnd
}
UpdateText(hTooltip, text) {
static TTM_UPDATETIPTEXT := A_IsUnicode ? 0x439 : 0x40C
VarSetCapacity(TOOLINFO, sz := 24 + A_PtrSize*6, 0)
NumPut(sz, TOOLINFO)
NumPut(&text, TOOLINFO, 24 + A_PtrSize*3)
SendMessage, TTM_UPDATETIPTEXT,, &TOOLINFO,, ahk_id %hTooltip%
}