分享几种tooltip脚本
- btt 显示速度、效果完爆内置tooltip 2021.10.03 BeautifulToolTip 高兼容 高性能 简单易用 自定义效果丰富的 ToolTip – AutoAHK
- 带标题和关闭按钮
title := "Hello,"
text := "This is my custom ToolTip!`nIt will disappear in five seconds."
hToolTip := CustomToolTip(text,,, title, 1, true, 0xFFC141, 0x50669F, "Calibri", "s18", true, 5000)
Timer := Func("UpdateText").Bind(hToolTip, [ StrReplace(text, "five seconds", "one second")
, StrReplace(text, "five", "two")
, StrReplace(text, "five", "three")
, StrReplace(text, "five", "four") ])
SetTimer, % Timer, 1000
Return
CustomToolTip( text, x := "", y := "", title := ""
, icon := 0 ; can be 1 — Info, 2 — Warning, 3 — Error, if greater than 3 — hIcon
, 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
, exStyles := (WS_EX_TOPMOST := 0x00000008) | (WS_EX_COMPOSITED := 0x2000000) | (WS_EX_LAYERED := 0x80000)
, WM_SETFONT := 0x30, WM_GETFONT := 0x31
dhwPrev := A_DetectHiddenWindows, defGuiPrev := A_DefaultGui, lastFoundPrev := WinExist()
DetectHiddenWindows, On
hWnd := DllCall("CreateWindowEx", "UInt", exStyles, "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, "UShortP", empty := 0)
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
}
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)
if (x = "" || y = "")
DllCall("GetCursorPos", "Int64P", pt)
(x = "" && x := (pt & 0xFFFFFFFF) + 15), (y = "" && y := (pt >> 32) + 15)
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
}
DetectHiddenWindows, % dhwPrev
WinExist("ahk_id" . lastFoundPrev)
Return hWnd
}
UpdateText(hTooltip, TextArray) {
static TTM_UPDATETIPTEXT := A_IsUnicode ? 0x439 : 0x40C
text := TextArray.Pop()
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%
if (TextArray[1] = "")
SetTimer,, Delete
}
- 可编辑tooltip 带滚动条
tip("sdfsdfsdfsdfdsf")
return
TipGuiEscape:
Gui, Tip:Destroy
Return
tip(ttext := "", x := 0, y := 0) {
If (ttext > "") {
Gui, Tip:New, +ToolWindow -Caption +AlwaysOnTop
Gui, Margin, 1, 1
Gui, Add, Edit, r30 ReadOnly Multi, %ttext%
Gui, Show, X%x% Y%y% NoActivate AutoSize
} Else Gui, Tip:Destroy
}
- 提示框类型
PleasantNotify("PleasantNotify", "position t hc" , 600, 210, "t hc", "3")
Sleep, 3000
PleasantNotify("PleasantNotify", "position b hc" , 600, 210, "b hc", "3")
Sleep, 3000
PleasantNotify("PleasantNotify", "position default, b r" , 600, 210, "b r", "3")
Sleep, 3000
PleasantNotify("PleasantNotify", "position b l" , 600, 210, "b l", "3")
Sleep, 3000
PleasantNotify("PleasantNotify", "position t l" , 600, 210, "t l", "3")
Sleep, 3000
PleasantNotify("PleasantNotify", "position t r" , 600, 210, "t r", "3")
return
PleasantNotify(title, message, pnW=700, pnH=300, position="b r", time=10) {
global pn_title, pn_msg, PN_hwnd, w, h
Notify_Destroy()
Gui, Notify: +AlwaysOnTop +ToolWindow -SysMenu -Caption +LastFound
PN_hwnd := WinExist()
WinSet, ExStyle, +0x20
WinSet, Transparent, 0
Gui, Notify: Color, 0xF2F2F0
Gui, Notify: Font, c0x07D82F s18 wBold, Segoe UI
Gui, Notify: Add, Text, % " x" 20 " y" 12 " w" pnW-20 " vpn_title", % title
Gui, Notify: Font, cBlack s15 wRegular
Gui, Notify: Add, Text, % " x" 20 " y" 56 " w" pnW-20 " h" pnH-56 " vpn_msg", % message
RealW := pnW + 50
RealH := pnH + 20
Gui, Notify: Show, W%RealW% H%RealH% NoActivate
WinMove(PN_hwnd, position)
if A_ScreenDPI = 96
WinSet, Region,0-0 w%pnW% h%pnH% R40-40,%A_ScriptName%
/* For Screen text size 125%
if A_ScreenDPI = 120
WinSet, Region, 0-0 w800 h230 R40-40, %A_ScriptName%
*/
winfade("ahk_id " PN_hwnd,210,5)
if (time <> "P")
{
Closetick := time*1000
SetTimer, ByeNotify, % Closetick
}
}
Notify_Destroy() {
global PN_hwnd
ByeNotify:
SetTimer, ByeNotify, Off
winfade("ahk_id " PN_hwnd,0,5)
Gui, Notify: Destroy
return
}
pn_mod_title(title) {
global pn_title
GuiControl, Notify: Text,pn_title, % title
}
pn_mod_msg(message) {
global pn_msg
GuiControl, Notify: Text,pn_msg, % message
}
WinMove(hwnd,position) {
SysGet, Mon, MonitorWorkArea
WinGetPos,ix,iy,w,h, ahk_id %hwnd%
x := InStr(position,"l") ? MonLeft : InStr(position,"hc") ? (MonRight-w)/2 : InStr(position,"r") ? MonRight - w : ix
y := InStr(position,"t") ? MonTop : InStr(position,"vc") ? (MonBottom-h)/2 : InStr(position,"b") ? MonBottom - h : iy
WinMove, ahk_id %hwnd%,,x,y
}
winfade(w:="",t:=128,i:=1,d:=10) {
w:=(w="")?("ahk_id " WinActive("A")):w
t:=(t>255)?255:(t<0)?0:t
WinGet,s,Transparent,%w%
s:=(s="")?255:s ;prevent trans unset bug
WinSet,Transparent,%s%,%w%
i:=(s<t)?abs(i):-1*abs(i)
while(k:=(i<0)?(s>t):(s<t)&&WinExist(w)) {
WinGet,s,Transparent,%w%
s+=i
WinSet,Transparent,%s%,%w%
sleep %d%
}
}
- 可移动tooltip
text =
(%
UpdateText(hTooltip, TextArray) {
static TTM_UPDATETIPTEXT := A_IsUnicode ? 0x439 : 0x40C
text := TextArray.Pop()
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%
if (TextArray[1] = "")
SetTimer,, Delete
)
#NoEnv
OnMessage(0x201, "WM_LBUTTONDOWN")
Global tClass:="SysShadow,Alternate Owner,tooltips_class32,DummyDWMListenerWindow,EdgeUiInputTopWndClass,ApplicationFrameWindow,TaskManagerWindow,Qt5QWindowIcon,Windows.UI.Core.CoreWindow,WorkerW,Progman,Internet Explorer_Hidden,Shell_TrayWnd" ; HH Parent
WinGetActiveTitle, aWin
ToolTip,% text, 0, 0
return
WM_LBUTTONDOWN(wParam, lParam, msg, hwnd) {
PostMessage, 0xA1, 2 ; WM_NCLBUTTONDOWN
KeyWait, LButton, U
Loop { ; adapted from https://autohotkey.com/board/topic/32171-how-to-get-the-id-of-the-next-or-previous-window-in-z-order/
; GetWindow() returns a decimal value, so we have to convert it to hex
; GetWindow() processes even hidden windows, so we move down the z oder until the next visible window is found
hwnd := Format("0x{:x}", DllCall("GetWindow", UPtr,hwnd, UInt,2) ) ; 2 = GW_HWNDNEXT
if DllCall("IsWindowVisible", UPtr,hwnd) {
WinGet, Ex, ExStyle, ahk_id %hwnd%
;if ( IsWindowCloaked(hwnd) || Ex & (0x8 | 0x80 | 0x8000000) ) ;WS_EX_TOPMOST, WS_EX_TOOLWINDOW, WS_EX_NOACTIVATE
if (IsWindowCloaked(hwnd) || Ex & 0x8000088) ;WS_EX_TOPMOST, WS_EX_TOOLWINDOW, WS_EX_NOACTIVATE
Continue
WinGetClass, cClass, ahk_id %hwnd%
if InStr(tClass, cClass, 1) ; if cClass in %tClass%
Continue
else break
}
} WinActivate, ahk_id %hwnd%
}
IsWindowCloaked(hwnd) {
return DllCall("dwmapi\DwmGetWindowAttribute", "ptr",hwnd, "int",14, "int*",cloaked, "int",4) >= 0
&& cloaked
}
Esc::exitapp
非常不错的总结,如果能带上截图更好一些!