带Gui的模板 - AutoXYWH示例.ahk
/* * * * Compile_AHK SETTINGS BEGIN * * * [AHK2EXE] Exe_File=%In_Dir%\图片整理.exe Compression=0 No_UPX=1 Created_Date=1 Execution_Level=4 [ICONS] Icon_1=%In_Dir%\icon.ico Icon_2=0 Icon_3=0 Icon_4=0 Icon_5=0 * * * Compile_AHK SETTINGS END * * * */ /* (%InputPath%) 输入路径 (%OutputPath%) 输出路径 (%SelectPath%) 选择路径 (%Image%) 当前图像 (%trace%) 操作痕迹 (%ImageName%) 图像名称 (%ImagePath%) 回撤路径 (%Width%) 窗口宽 (%Height%) 窗口高 */ #SingleInstance Force #NoEnv SetWorkingDir %A_ScriptDir% SetBatchLines -1 FileInstall, Default.jpg, C:\Default.jpg, 0 Image := "C:\Default.jpg" Gui +Resize +MinSize Gui Font, s10 Norm, Segoe UI Gui Add, Button, hWndhButton1 x405 y10 w185 h40, 选择输入路径 Gui Add, Button, hWndhButton2 x405 y60 w185 h40, 选择输出路径 Gui Add, Button, hWndhButton3 x405 y124 w90 h40, 客厅正面 Gui Add, Button, hWndhButton4 x500 y124 w90 h40, 客厅侧面 Gui Add, Button, hWndhButton5 x405 y169 w90 h40, 玄关正面 Gui Add, Button, hWndhButton6 x500 y169 w90 h40, 玄关侧面 Gui Add, Button, hWndhButton7 x405 y214 w90 h40, 卧室正面 Gui Add, Button, hWndhButton8 x500 y214 w90 h40, 卧室侧面 Gui Add, Button, hWndhButton9 x405 y259 w90 h40, 餐厅正面 Gui Add, Button, hWndhButton10 x500 y259 w90 h40, 餐厅侧面 Gui Add, Button, hWndhButton11 x405 y304 w90 h40, 办公室正面 Gui Add, Button, hWndhButton12 x500 y304 w90 h40, 办公室侧面 Gui Add, Button, hWndhButton13 x405 y349 w90 h40, 其它正面 Gui Add, Button, hWndhButton14 x500 y349 w90 h40, 其它侧面 Gui Add, Picture, hWndhStatic1 x10 y10 w380 h380, %Image% Gui Color, 0x40535E Gui Show, w600 h400, 图片分类 Sleep, 333 ; MsgBox, 262208, 提示, 按 Delete 键可以删除不需要的图片`n按 ctrl+z 可以撤销最近一次操作 Return Button选择输入路径: FileSelectFolder, InputPath, , 1 If InputPath = { Return } FileCreateDir, %InputPath%\删除 Gosub, ImageAdd Return Button选择输出路径: FileSelectFolder, OutputPath, , 1 Return Button客厅正面: Gosub, SelfCheck SelectPath = %OutputPath%\客厅正面 Gosub, Migrate Return Button客厅侧面: Gosub, SelfCheck SelectPath = %OutputPath%\客厅侧面 Gosub, Migrate Return Button玄关正面: Gosub, SelfCheck SelectPath = %OutputPath%\玄关正面 Gosub, Migrate Return Button玄关侧面: Gosub, SelfCheck SelectPath = %OutputPath%\玄关侧面 Gosub, Migrate Return Button卧室正面: Gosub, SelfCheck SelectPath = %OutputPath%\卧室正面 Gosub, Migrate Return Button卧室侧面: Gosub, SelfCheck SelectPath = %OutputPath%\卧室侧面 Gosub, Migrate Return Button餐厅正面: Gosub, SelfCheck SelectPath = %OutputPath%\餐厅正面 Gosub, Migrate Return Button餐厅侧面: Gosub, SelfCheck SelectPath = %OutputPath%\餐厅侧面 Gosub, Migrate Return Button办公室正面: Gosub, SelfCheck SelectPath = %OutputPath%\办公室正面 Return Button办公室侧面: Gosub, SelfCheck SelectPath = %OutputPath%\办公室侧面 Gosub, Migrate Return Button其它正面: Gosub, SelfCheck SelectPath = %OutputPath%\其它正面 Gosub, Migrate Return Button其它侧面: Gosub, SelfCheck SelectPath = %OutputPath%\其它侧面 Gosub, Migrate Return SelfCheck: ; 预检测 If InputPath = { If OutputPath = { MsgBox, 262160, 错误, 未选择输入和输出路径 Exit } MsgBox, 262160, 错误, 未选择输入路径 Exit } Else If OutputPath = { MsgBox, 262160, 错误, 未选择输出路径 Exit } Return #IfWinActive, 图片分类 ahk_class AutoHotkeyGUI ; 删除无用图片 Delete:: If Image = C:\Default.jpg { MsgBox, 262160, 错误, 未导入图片 Return } FileMove, %Image%, %InputPath%\删除 Gosub, ImageAdd Return #IfWinActive, 图片分类 ahk_class AutoHotkeyGUI ; 撤销操作 ^z:: If trace = { MsgBox, 262192, 提示, 没有可供撤销的步数了 Exit } MsgBox, %ImagePath%`n%InputPath% FileMove, %ImagePath%, %InputPath% Gosub, ImageAdd trace := Return Migrate: ; 移动图片 If !FileExist(SelectPath) { FileCreateDir, %SelectPath% } FileMove, %Image%, %SelectPath% ImagePath = %SelectPath%\%ImageName% InputPath := "F:\素材\场景相关\还没整理\测试" If !FileExist("%InputPath%\*.*") { MsgBox, 无 } Else { MsgBox, 有 } ExitApp Gosub, ImageAdd trace = true Return ImageAdd: ; 更新图片控件 Loop, Files, %InputPath%\*.* { ImageName := A_LoopFileName Image := A_LoopFileLongPath GuiControl, , Static1, %Image% Break } Return GuiSize: If (A_EventInfo == 1) { Return } AutoXYWH("x", hButton1) AutoXYWH("x", hButton2) AutoXYWH("xy", hButton3) AutoXYWH("xy", hButton4) AutoXYWH("xy", hButton5) AutoXYWH("xy", hButton6) AutoXYWH("xy", hButton7) AutoXYWH("xy", hButton8) AutoXYWH("xy", hButton9) AutoXYWH("xy", hButton10) AutoXYWH("xy", hButton11) AutoXYWH("xy", hButton12) AutoXYWH("xy", hButton13) AutoXYWH("xy", hButton14) AutoXYWH("wh", hStatic1) WinSet, Redraw Return AutoXYWH(DimSize, cList*) { static cInfo := {} If (DimSize = "reset") Return cInfo := {} For i, ctrl in cList { ctrlID := A_Gui ":" ctrl If ( cInfo[ctrlID].x = "" ) { GuiControlGet, i, %A_Gui%:Pos, %ctrl% MMD := InStr(DimSize, "*") ? "MoveDraw" : "Move" fx := fy := fw := fh := 0 For i, dim in (a := StrSplit(RegExReplace(DimSize, "i)[^xywh]"))) If !RegExMatch(DimSize, "i)" dim "\s*\K[\d.-]+", f%dim%) f%dim% := 1 cInfo[ctrlID] := { x:ix, fx:fx, y:iy, fy:fy, w:iw, fw:fw, h:ih, fh:fh, gw:A_GuiWidth, gh:A_GuiHeight, a:a , m:MMD} } Else If ( cInfo[ctrlID].a.1) { dgx := dgw := A_GuiWidth - cInfo[ctrlID].gw , dgy := dgh := A_GuiHeight - cInfo[ctrlID].gh For i, dim in cInfo[ctrlID]["a"] Options .= dim (dg%dim% * cInfo[ctrlID]["f" dim] + cInfo[ctrlID][dim]) A_Space GuiControl, % A_Gui ":" cInfo[ctrlID].m , % ctrl, % Options } } } GuiEscape: GuiClose: FileDelete, C:\Default.jpg ExitApp
AutoXYWH - 更新.ahk
#NoEnv #SingleInstance Force Gui +Resize +MinSize Gui Add, Tab3, x14 y8 w298 h160 vTab, Tab 1|Tab 2 Gui Tab, 1 Gui Add, Button, x113 y50 w80 h24 vBtn1 g调整大小, 按钮1 Gui Add, Button, x113 y83 w80 h24 vBtn2, 按钮2 Gui Tab Gui Add, Button, x113 y206 w80 h24 vBtn3, 按钮3 Gui Show, , AutoXYWH Test Window Return F1:: 调整大小: GuiControl, Move, Btn1, h30 AutoXYWH("reset") ; 如果你手动改变了控制尺寸,需要重置。【点击按钮可重置"按钮1"大小】 return GuiSize: ; If (A_EventInfo = 1) ; 窗口已被最小化。【官方示例添加】 ; Return AutoXYWH("w h0.5", "Tab") AutoXYWH("t x h0.5", "Btn1") AutoXYWH("t x y0.5", "Btn2") AutoXYWH("x y0.5 h0.5", "Btn3") Return GuiEscape: GuiClose: ExitApp ; ================================================================= ; 功能: AutoXYWH ; 当GUI调整大小时,自动移动和调整控件大小。 ; 参数: ; DimSize - 可以是x/y/w/h中的一个或多个可选,后面是一个分数。 ; 在DimSize中添加一个'*',以'MoveDraw'控件,而不是仅仅'Move',这对于Groupboxes来说是值得推荐的。 ; 在DimSize中添加一个't'来告诉AutoXYWH,cList中的控件是在一个tab3控件中。 ; cList - 控制ID的变量列表 ; ControlID可以是一个控件HWND,相关的变量名称,ClassNN或显示的文本。 ; 后者(显示文本)是可能的,但不推荐,因为不是很可靠。 ; 实例: ; AutoXYWH("xy", "Btn1", "Btn2") ; AutoXYWH("w0.5 h 0.75", hEdit, "displayed text", "vLabel", "Button1") ; AutoXYWH("*w0.5 h 0.75", hGroupbox1, "GrbChoices") ; AutoXYWH("t x h0.5", "Btn1") ; --------------------------------------------------------------------------------- ; Version: 2020-5-20 / small code improvements (toralf) ; 2018-1-31 / added a line to prevent warnings (pramach) ; 2018-1-13 / added t option for controls on Tab3 (Alguimist) ; 2015-5-29 / added 'reset' option (tmplinshi) ; 2014-7-03 / mod by toralf ; 2014-1-02 / initial version tmplinshi ; requires AHK version : 1.1.13.01+ due to SprSplit() ; ================================================================= AutoXYWH(DimSize, cList*){ ;https://www.autohotkey.com/boards/viewtopic.php?t=1079 Static cInfo := {} If (DimSize = "reset") Return cInfo := {} For i, ctrl in cList { ctrlID := A_Gui ":" ctrl If !cInfo.hasKey(ctrlID) { ix := iy := iw := ih := 0 GuiControlGet i, %A_Gui%: Pos, %ctrl% MMD := InStr(DimSize, "*") ? "MoveDraw" : "Move", fx := fy := fw := fh := 0 For i, dim in (a := StrSplit(RegExReplace(DimSize, "i)[^xywh]"))) If !RegExMatch(DimSize, "i)" . dim . "\s*\K[\d.-]+", f%dim%) f%dim% = 1 If (InStr(DimSize, "t")) { GuiControlGet hWnd, %A_Gui%: hWnd, %ctrl% hParentWnd := DllCall("GetParent", "Ptr", hWnd, "Ptr"), VarSetCapacity(RECT, 16, 0), DllCall("GetWindowRect", "Ptr", hParentWnd, "Ptr", &RECT), DllCall("MapWindowPoints", "Ptr", 0, "Ptr", DllCall("GetParent", "Ptr", hParentWnd, "Ptr"), "Ptr", &RECT, "UInt", 1), ix -= (NumGet(RECT, 0, "Int") * 96) // A_ScreenDPI, iy -= (NumGet(RECT, 4, "Int") * 96) // A_ScreenDPI } cInfo[ctrlID] := {x:ix, fx:fx, y:iy, fy:fy, w:iw, fw:fw, h:ih, fh:fh, gw:A_GuiWidth, gh:A_GuiHeight, a:a, m:MMD} } Else { dgx := dgw := A_GuiWidth - cInfo[ctrlID].gw, dgy := dgh := A_GuiHeight - cInfo[ctrlID].gh, Options := "" For i, dim in cInfo[ctrlID]["a"] Options .= dim (dg%dim% * cInfo[ctrlID]["f" . dim] + cInfo[ctrlID][dim]) A_Space GuiControl, % A_Gui ":" cInfo[ctrlID].m, % ctrl, % Options } } }
声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。
评论(0)