
自己修改了一套通用并美观的AHK界面模板,方便修改里面的控件内容后直接使用即可
不带滚动条的版本:
; 自己修改了一套通用并美观的AHK界面模板,方便修改里面的控件内容后直接使用即可
; 参考至:https://www.autohotkey.com/boards/viewtopic.php?f=6&t=3851
#SingleInstance Force
SetBatchLines -1
Menu Tray, Icon, Shell32.dll, 174
Window := {Width: 530, Height: 360, Title: "Menu Interface"} ; Version: "0.3"
Navigation := ["General", "Advanced", "Language", "Theme", "---", "Help", "About"]
Gui -Resize -MinimizeBox +HwndhGui ; 加上-DPIScale,页面缩放比例会不正常
Gui Color, FFFFFF
Gui Add, Picture, x0 y0 w1699 h1 +0x4E +HwndhDividerLine1 ; 分割线 从左到右【顶部菜单栏】
Gui Add, Slider, w1 h1 ; 处理默认焦点虚线问题
Gui Add, Tab2, x-666 y10 w1699 h334 -Wrap +Theme -Tabstop Buttons HwndhTabControl
Gui Tab
Gui Add, Picture, x-3999 y-3999 w96 h32 vpMenuHover +0x4E +HwndhMenuHover ; 菜单悬停
Gui Add, Picture, x0 y18 w4 h32 vpMenuSelect +0x4E +HwndhMenuSelect ; 菜单选择
Gui Add, Picture, x96 y0 w1 h1340 +0x4E +HwndhDividerLine3 ; 分割线 从上到下
Gui Add, Progress, x0 y0 w96 h799 +0x4000000 +E0x4 Disabled BackgroundF7F7F7 ; 左侧常态背景色
; 左侧Tab标题的 字体大小 和 字体加粗
Gui Font, Bold c808080 Q5, Microsoft YaHei UI
Loop % Navigation.Length() {
GuiControl,, %hTabControl%, % Navigation[A_Index] "|"
If (Navigation[A_Index] = "---")
Continue
Gui Add, Text, % "x0 y" (32*A_Index)-24 " h32 w96 Center +0x200 BackgroundTrans gMenuClick vMenuItem" . A_Index, % Navigation[A_Index]
}
Gui Font
; 右侧顶部Tab标题的字体大小【可删除】
Gui Font, s15 Q5 c000000, Microsoft YaHei UI
Gui Add, Text, x117 y4 w140 h32 +0x200 vPageTitle
Gui Add, Picture, % "x110 y38 w" (Window.Width-110)-16 " h1 +0x4E +HwndhDividerLine2" ; 分割线
Gui Font
Gui Tab, 1
Gui Font, W560, Microsoft YaHei UI
Gui Add, Text, Section x116 y50 BackgroundWhite, Select your primary button
Gui Add, DropDownList, xs+10 w80 vPrimaryButton Choose1, Left||Right
Gui Font, W560, Microsoft YaHei UI
Gui Add, Text, xs yp+40, Cursor Speed
Gui Font
Gui Add, Slider, vMySlider NoTicks, 50
Gui Font, W560, Microsoft YaHei UI
Gui Add, Text, yp+40 , Roll the mouse wheel to scrol
Gui Font
Gui Add, Radio, xs+10 yp+22 h14 Checked, Multiple lines at a time
Gui Add, Radio, xs+10 y+8 h14, On screen at a time
Gui Font, W560, Microsoft YaHei UI
Gui Add, Checkbox, xs yp+36 h14, Mouse Button Tips
Gui Font
Gui Tab, 2
Gui Add, ListView, % "x116 y50 w" (Window.Width-110)-30, Col1|Col2
LV_Add("", "ListView", "Example"), LV_ModifyCol()
Gui Tab, 3
Gui Add, MonthCal, x116 y50
Gui Tab, 4
Gui Add, DateTime, x116 y50, LongDate
Gui Tab, 5 ; Skipped
Gui Tab, 6
Gui Add, GroupBox, % "x116 y50 w" (Window.Width-110)-30, GroupBox
Gui Tab, 7
Gui Add, TreeView, x116 y50 w220 h148
P1 := TV_Add("First parent"), P1C1 := TV_Add("Parent 1's first child", P1)
Gui Show, % " w" Window.Width " h" Window.Height, % Window.Title
SetPixelColor("E9E9E9", hMenuHover)
SetPixelColor("0078D7", hMenuSelect)
Loop 4
SetPixelColor("D8D8D8", hDividerLine%A_Index%)
SelectMenu("MenuItem1")
OnMessage(0x200, "WM_MOUSEMOVE")
Return
MenuClick:
SelectMenu(A_GuiControl)
Return
GuiClose:
ExitApp
WM_MOUSEMOVE(wParam, lParam, Msg, Hwnd) {
Global hMenuSelect
Static hover := {}
if (wParam = "timer") {
MouseGetPos,,,, hControl, 2
if (hControl != hwnd) && (hControl != hMenuSelect) {
SetTimer,, Delete
GuiControl, Move, pMenuHover, x-9999 y-9999
OnMessage(0x200, "WM_MOUSEMOVE")
, hover[hwnd] := False
}
} else {
if (InStr(A_GuiControl, "MenuItem") = True) {
GuiControl, MoveDraw, pMenuHover, % "x0 y" (32*SubStr(A_GuiControl, 9, 2))-24
hover[hwnd] := True
, OnMessage(0x200, "WM_MOUSEMOVE", 0)
, timer := Func(A_ThisFunc).Bind("timer", "", "", hwnd)
SetTimer %timer%, 15
} else if (InStr(A_GuiControl, "MenuItem") = False)
GuiControl, Move, pMenuHover, x-9999 y-9999
}
}
SelectMenu(Control) {
Global
Loop % Navigation.Length()
SetControlColor("808080", Navigation[A_Index]) ; 左侧未选中按钮的颜色
SetControlColor("237FFF", Control) ; 左侧选中按钮的颜色
GuiControl, Move, pMenuSelect, % "x0 y" (32*SubStr(Control, 9, 2))-20 " w4 h24"
GuiControl, Choose, %hTabControl%, % SubStr(Control, 9, 2)
GuiControl,, PageTitle, % Navigation[SubStr(Control, 9, 2)]
}
SetControlColor(Color, Control) {
GuiControl, +c%Color%, %Control%
; 由于 Tab2 控件的重绘问题而需要
GuiControlGet, ControlText,, %Control%
GuiControlGet, ControlHandle, Hwnd, %Control%
DllCall("SetWindowText", "Ptr", ControlHandle, "Str", ControlText)
GuiControl, MoveDraw, %Control%
}
SetPixelColor(Color, Handle) {
VarSetCapacity(BMBITS, 4, 0), Numput("0x" . Color, &BMBITS, 0, "UInt")
, hBM := DllCall("Gdi32.dll\CreateBitmap", "Int", 1, "Int", 1, "UInt", 1, "UInt", 24, "Ptr", 0)
, hBM := DllCall("User32.dll\CopyImage", "Ptr", hBM, "UInt", 0, "Int", 0, "Int", 0, "UInt", 0x2008)
, DllCall("Gdi32.dll\SetBitmapBits", "Ptr", hBM, "UInt", 3, "Ptr", &BMBITS)
return DllCall("User32.dll\SendMessage", "Ptr", Handle, "UInt", 0x172, "Ptr", 0, "Ptr", hBM)
}
带滚动条实现的复杂版本:
#SingleInstance Force
SetBatchLines -1
Menu Tray, Icon, Shell32.dll, 174
Window := {Width: 530, Height: 340, Title: "Menu Interface"} ; Version: "0.3"
Navigation := ["General", "Advanced", "Language", "Theme", "---", "Help", "About"]
Gui -Resize -MinimizeBox +HwndhGui ; 加上-DPIScale,页面缩放比例会不正常
Gui Color, FFFFFF
Gui Add, Text, % "x96 y0 w" Window.Width-102 " h38 +0x4000000 g空白标签" ; 挡住顶部Tab3标签
Gui Add, Tab3, % "x96 y0 w" Window.Width-102 " h" Window.Height " -Wrap +Theme -Tabstop Buttons HwndhTabControl"
Gui Tab
Gui Add, Picture, % "x0 y0 w" Window.Width " h1 +0x4E +HwndhDividerLine1" ; 分割线 从左到右【顶部标题栏】
Gui Add, Picture, % "x96 y1 w1 h" Window.Height " +0x4E +HwndhDividerLine2" ; 分割线 从上到下
; 滚动条控件以及参数调用
ScrollSize := {"General" : 940} ; 滚动内容可显示高度,与Tab文本名匹配,需要滚动条就加名称和高度
_isDragging := false, _startY := 0, _startScrollY := 0 ; 添加滚动条拖动相关变量和函数
OnMessage(0x20A, "OnMouseWheel")
Gui, Add, Text, % "x" Window.Width-8 " y9999 w5 h200 0x5 +0x100 +HwndhScrollBar g_ScrollBarClick_"
Gui Add, Picture, x-9999 y-9999 w96 h32 vpMenuHover +0x4E +HwndhMenuHover ; 菜单悬停
Gui Add, Picture, x0 y18 w4 h32 vpMenuSelect +0x4E +HwndhMenuSelect ; 菜单选择
Gui Add, Progress, % "x0 y0 w96 h" Window.Height " +0x4000000 +E0x4 Disabled BackgroundF7F7F7" ; 左侧常态背景色
; 左侧Tab标题的 字体大小 和 字体加粗
Gui Font, Bold c808080 Q5, Microsoft YaHei UI
Loop % Navigation.Length() {
GuiControl,, %hTabControl%, % Navigation[A_Index] "|"
if (Navigation[A_Index] = "---")
Continue
Gui Add, Text, % "x0 y" (32*A_Index)-24 " h32 w96 Center +0x200 +E0x20 BackgroundTrans gMenuClick vMenuItem" . A_Index, % Navigation[A_Index]
}
Gui Font
; 右侧顶部Tab标题的字体大小【可删除】
Gui Font, s15 Q5 c000000, Microsoft YaHei UI
Gui Add, Text, % "x116 y1 w" Window.Width-116 " h37 +0x200 vPageTitle"
Gui Add, Picture, % "x110 y38 w" Window.Width-110-16 " h1 +0x4E +HwndhDividerLine3" ; 分割线
Gui Font
Gui Tab, 1
Gui Add, Slider, w1 h1 ; 处理默认焦点虚线问题
Gui Font, W560, Microsoft YaHei UI
Gui Add, Text, Section x116 y50, Display Settings
Gui Font
Gui Add, Checkbox, xs+10 yp+24 h14, Test1
Gui Add, Checkbox, Section xs+10 y+8 h14, Test2
Gui Font, s10 Q5 c555555, Segoe MDL2 Assets ; 此字体Win10自带
Gui Add, Text, x+1 ys+1 hWndhText g空白标签, % Chr(0xE9CE) ; 0xE946 ❔ ; 在Text须要有g标签才能生效
AddToolTip(hText, "帮助按钮工具提示")
; AddToolTip("Title", "全局提示标题+图标", LoadPicture("shell32.dll", "Icon131", _)) ; 和上面一同开启
Gui Font
Gui Font, W560, Microsoft YaHei UI
Gui Add, Text, Section xs-10 yp+26, Select your primary button
Gui Font
Gui Add, DropDownList, xs+12 w80 vPrimaryButton Choose1, Left||Right
Gui Font, W560, Microsoft YaHei UI
Gui Add, Text, xs yp+40, Cursor Speed
Gui Font
Gui Add, Slider, vMySlider NoTicks, 50
Gui Font, W560, Microsoft YaHei UI
Gui Add, Text, yp+40, Roll the mouse wheel to scrol
Gui Font
Gui Add, Radio, xs+10 yp+24 h14 Checked, Multiple lines at a time
Gui Add, Radio, xs+10 y+8 h14, On screen at a time
Gui Font, W560, Microsoft YaHei UI
Gui Add, Text, xs yp+32 , Scroll Settings
Gui Font
Gui Add, Text, xs yp+24, Scroll to display character at a time:
Gui Add, Edit, xs+20 y+8 w42 r1 Limit3 Number, edit
Gui Add, UpDown, Range0-999, 30
Gui Font, W560, Microsoft YaHei UI
Gui Add, Checkbox, xs yp+36 h14, Mouse Button Tips
Gui Font
Loop 15
Gui Add, Checkbox, x116 y+10 h24, Additional Option %A_Index%
Gui Tab, 2
Gui Add, ListView, % "x116 y50 w" (Window.Width-110)-30, Col1|Col2
LV_Add("", "ListView", "Example"), LV_ModifyCol()
Gui Tab, 3
Gui Add, MonthCal, x116 y50
Gui Tab, 4
Gui Add, DateTime, x116 y50, LongDate
Gui Tab, 5 ; Skipped
Gui Tab, 6
Gui Add, GroupBox, % "x116 y50 w" (Window.Width-110)-30, GroupBox
Gui Tab, 7
Gui Add, TreeView, x116 y50 w220 h148
P1 := TV_Add("First parent"), P1C1 := TV_Add("Parent 1's first child", P1)
For k, v in { "hMenuHover":"E9E9E9", "hMenuSelect":"0078D7", "hDividerLine1":"D8D8D8", "hDividerLine2":"D8D8D8", "hDividerLine3":"D8D8D8" }
SetPixelColor(v, %k%)
Gui Show, % " w" Window.Width " h" Window.Height, % Window.Title
SelectMenu("MenuItem1")
OnMessage(0x200, "WM_MOUSEMOVE")
Return
GuiClose:
ExitApp
MenuClick:
SelectMenu(A_GuiControl)
空白标签:
Return
SelectMenu(Control) {
Global
Loop % Navigation.Length()
SetControlColor("808080", Navigation[A_Index]) ; 左侧未选中按钮的颜色
SetControlColor("237FFF", Control) ; 左侧选中按钮的颜色
, _ScrollingLower := ScrollSize[Navigation[SubStr(Control, 9, 2)]] ; 滚动条显示长度计算相关
GuiControl, MoveDraw, %hTabControl%, % "y0 h" (_ScrollingLower="" ? Window.Height : _ScrollingLower)
GuiControl, Move, %hScrollBar%, % "y" (_ScrollingLower="" ? 9999 : 44) " h" Format("{:d}", (Window.Height-92)*((Window.Height-92)/(_ScrollingLower-92)))
GuiControl, Move, pMenuSelect, % "x0 y" (32*SubStr(Control, 9, 2))-20 " w4 h24"
GuiControl, Choose, %hTabControl%, % SubStr(Control, 9, 2)
GuiControl,, PageTitle, % Navigation[SubStr(Control, 9, 2)]
}
WM_MOUSEMOVE(wParam, lParam, Msg, Hwnd) {
Global hMenuSelect
Static hover := {}
if (wParam = "timer") {
MouseGetPos,,,, hControl, 2
if (hControl != hwnd) && (hControl != hMenuSelect) {
SetTimer,, Delete
GuiControl, Move, pMenuHover, x-9999 y-9999
OnMessage(0x200, "WM_MOUSEMOVE")
, hover[hwnd] := False
}
} else {
if (InStr(A_GuiControl, "MenuItem") = True) {
GuiControl, MoveDraw, pMenuHover, % "x0 y" (32*SubStr(A_GuiControl, 9, 2))-24
hover[hwnd] := True
, OnMessage(0x200, "WM_MOUSEMOVE", 0)
, timer := Func(A_ThisFunc).Bind("timer", "", "", hwnd)
SetTimer %timer%, 15
} else if (InStr(A_GuiControl, "MenuItem") = False)
GuiControl, Move, pMenuHover, x-9999 y-9999
}
}
SetControlColor(Color, Control) {
GuiControl, +c%Color%, %Control%
; 由于 Tab3 控件的重绘问题而需要
GuiControlGet, ControlText,, %Control%
GuiControlGet, ControlHandle, Hwnd, %Control%
DllCall("SetWindowText", "Ptr", ControlHandle, "Str", ControlText)
GuiControl, MoveDraw, %Control%
}
SetPixelColor(Color, Handle) {
VarSetCapacity(BMBITS, 4, 0), Numput("0x" . Color, &BMBITS, 0, "UInt")
, hBM := DllCall("Gdi32.dll\CreateBitmap", "Int", 1, "Int", 1, "UInt", 1, "UInt", 24, "Ptr", 0)
, hBM := DllCall("User32.dll\CopyImage", "Ptr", hBM, "UInt", 0, "Int", 0, "Int", 0, "UInt", 0x2008)
, DllCall("Gdi32.dll\SetBitmapBits", "Ptr", hBM, "UInt", 3, "Ptr", &BMBITS)
return DllCall("User32.dll\SendMessage", "Ptr", Handle, "UInt", 0x172, "Ptr", 0, "Ptr", hBM)
}
; Modified from: https://www.autohotkey.com/boards/viewtopic.php?f=6&t=30079
AddTooltip(p1, p2:="", p3:="") {
Static hTT, CW_USEDEFAULT:=0x80000000, HWND_DESKTOP:=0, TTDT_AUTOPOP:=2
, TTS_ALWAYSTIP:=0x1, TTS_NOPREFIX:=0x2, TTF_IDISHWND:=0x1, TTF_SUBCLASS:=0x10
, TTI_NONE:=0, TTI_INFO:=1, TTI_WARNING:=2, TTI_ERROR:=3, TTI_INFO_LARGE:=4
, TTI_WARNING_LARGE:=5, TTI_ERROR_LARGE:=6, WS_EX_TOPMOST:=0x8, TTM_ACTIVATE:=0x401
, TTM_ADDTOOLA:=0x404, TTM_ADDTOOLW:=0x432, TTM_DELTOOLA:=0x405, TTM_DELTOOLW:=0x433
, TTM_GETTOOLINFOA:=0x408, TTM_GETTOOLINFOW:=0x435, TTM_SETDELAYTIME:=0x403
, TTM_SETMAXTIPWIDTH:=0x418, TTM_SETTITLEA:=0x420, TTM_SETTITLEW:=0x421
, TTM_UPDATETIPTEXTA:=0x40C, TTM_UPDATETIPTEXTW:=0x439
DetectHiddenWindows % ("On", DHW:=A_DetectHiddenWindows)
if !hTT {
hTT:=DllCall("CreateWindowEx","UInt",WS_EX_TOPMOST,"Str","TOOLTIPS_CLASS32","Ptr",0,"UInt",TTS_ALWAYSTIP|TTS_NOPREFIX,"UInt",CW_USEDEFAULT,"UInt",CW_USEDEFAULT,"UInt",CW_USEDEFAULT,"UInt",CW_USEDEFAULT,"Ptr",HWND_DESKTOP,"Ptr",0,"Ptr",0,"Ptr",0,"Ptr")
SendMessage TTM_SETMAXTIPWIDTH,0,A_ScreenWidth*96//A_ScreenDPI,,ahk_id %hTT%
}
if p1 is not Integer
{
if (p1="Activate")
SendMessage TTM_ACTIVATE,True,0,,ahk_id %hTT%
if (p1="Deactivate")
SendMessage TTM_ACTIVATE,False,0,,ahk_id %hTT%
if (InStr(p1,"AutoPop")=1) ;-- Starts with "AutoPop"
SendMessage TTM_SETDELAYTIME,TTDT_AUTOPOP,p2*1000,,ahk_id %hTT%
else
SendMessage TTM_SETDELAYTIME,TTDT_AUTOPOP,15*1000,,ahk_id %hTT% ; 改为默认显示15秒
if (p1="Title") { ; Title为全局影响,避免全局影响只能复制新建一个AddTooltip2函数独立分配
if (StrLen(p2)>99)
p2:=SubStr(p2,1,99)
if p3 is not Integer
p3:=TTI_NONE
SendMessage A_IsUnicode ? TTM_SETTITLEW:TTM_SETTITLEA,p3,&p2,,ahk_id %hTT%
}
DetectHiddenWindows %DHW%
Return hTT
}
uFlags:=TTF_IDISHWND|TTF_SUBCLASS
, cbSize:=VarSetCapacity(TOOLINFO,(A_PtrSize=8) ? 72:48,0)
, NumPut(cbSize, TOOLINFO, 0,"UInt")
, NumPut(uFlags, TOOLINFO, 4,"UInt")
, NumPut(HWND_DESKTOP,TOOLINFO, 8,"Ptr")
, NumPut(p1, TOOLINFO,(A_PtrSize=8) ? 16:12,"Ptr")
SendMessage,A_IsUnicode ? TTM_GETTOOLINFOW:TTM_GETTOOLINFOA,0,&TOOLINFO,,ahk_id %hTT%
l_RegisteredTool:=ErrorLevel
NumPut(&p2,TOOLINFO,(A_PtrSize=8) ? 48:36,"Ptr")
if (l_RegisteredTool) {
if StrLen(p2)
SendMessage,A_IsUnicode ? TTM_UPDATETIPTEXTW:TTM_UPDATETIPTEXTA,0,&TOOLINFO,,ahk_id %hTT%
else
SendMessage,A_IsUnicode ? TTM_DELTOOLW:TTM_DELTOOLA,0,&TOOLINFO,,ahk_id %hTT%
} else if StrLen(p2)
SendMessage,A_IsUnicode ? TTM_ADDTOOLW:TTM_ADDTOOLA,0,&TOOLINFO,,ahk_id %hTT%
DetectHiddenWindows %DHW%
Return hTT
}
; ============================= ↓滚动条控件相关逻辑↓ =============================
_ScrollRedrawUp_:
_ScrollRedrawDown_:
MouseGetPos, , , _p_
if (_p_=HGui) && (_ScrollingLower!="") {
GuiControlGet, p_, Pos, %hTabControl%
_isUp := A_ThisLabel="_ScrollRedrawUp_"
if ((_isUp && p_Y<0) || (!_isUp && p_Y>(Window.Height-_ScrollingLower))) {
GuiControl, MoveDraw, %hTabControl%, % "y" p_Y + (_isUp ? 20 : -20)
GuiControlGet, _p_, Pos, %hScrollBar%
GuiControl, MoveDraw, %hScrollBar%, % "y" _p_Y + (_isUp ? -1 : 1) * Round((Window.Height-50-Format("{:d}", (Window.Height-92)*((Window.Height-92)/(_ScrollingLower-92)))) / (Format("{:d}", (_ScrollingLower-Window.Height)/20)))
}
}
Return
OnMouseWheel(wParam, lParam, msg, hwnd) {
wheelDelta := wParam >> 16
wheelDelta := wheelDelta > 32767 ? -(65536 - wheelDelta) : wheelDelta ; 将无符号值转为有符号值
if (wheelDelta=120)
SetTimer _ScrollRedrawUp_, -15
else if (wheelDelta=-120)
SetTimer _ScrollRedrawDown_, -15
}
; Text控件+g标签存在点击滚动条左侧两个像素不触发的问题
_ScrollBarClick_:
if (A_GuiEvent = "Normal") { ; 鼠标左键点击
_isDragging := true
MouseGetPos, , _startY
GuiControlGet, _startScroll, Pos, %hScrollBar%
SetTimer, _ScrollBarWatchMouse_, 50
}
Return
_ScrollBarWatchMouse_:
if !GetKeyState("LButton") {
_isDragging := false
SetTimer, _ScrollBarWatchMouse_, Off
Return
}
if _isDragging {
MouseGetPos, , _currentY
_newScrollY := _startScrollY + (_currentY - _startY) ; 计算新的滚动条位置
; 获取滚动条可移动的范围
_maxY := Window.Height - Format("{:d}", (Window.Height-92)*((Window.Height-92)/(_ScrollingLower-92))) - 6
; 限制滚动条在有效范围内
GuiControl, MoveDraw, %hScrollBar%, % "y" _newScrollY := (_newScrollY < 44) ? 44 : (_newScrollY > _maxY) ? _maxY : _newScrollY
; 计算并移动内容区域
GuiControl, MoveDraw, %hTabControl%, % "y" -(_newScrollY - 44) * ((_ScrollingLower - Window.Height) / (_maxY - 44)) ; 内容移动比例
}
Return
; ============================= ↑滚动条控件相关逻辑↑ =============================
声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。

评论(0)