软件介绍

1、随机打开,是一款AHK语言编写的软件,作用如软件名字一样,随机打开一个文件,这个文件可以是视频、图片、或者其它文件......软件免费且开源
2、编写这个软件的原因:某天,作者本人在学习时,面对文件夹上千个文件竟然犯了难,不知道该选哪个,忽发奇想,何不用软件随机打开一个呢?故动手写了一个软件......
3、更多功能还在开发中(学习中)
4、软件更新地址:https://www.cnblogs.com/chr2020/p/15171012.html
5、关于软件速度:有个朋友说使用随机打开每次都要十多秒,我自己实测机械硬盘目录中2.3万张图片,机械硬盘休眠状态的冷启动文件时间为4s左右,热启动每次为1.2s左右。

 

Plain text
复制到剪贴板
Open code in new window
EnlighterJS 3 Syntax Highlighter
; By 有千山
#NoEnv ;不检查空变量是否为环境变量
#SingleInstance, Force ;新开程序替换旧实例
#Persistent ;让脚本持续运行(即直到用户关闭或遇到 ExitApp).
SetBatchLines, -1 ;让操作以最快速度进行
;强制设置工作路径为软件所在文件夹,否则使用快捷方式打开软件无法读取随同的配置文件
SetWorkingDir %A_ScriptDir%
if !FileExist(A_ScriptDir "\随机打开.ini") {
_=
(
[Section]
视频格式=mp4,avi,rmvb,flv,mpeg,wmv,mkv
图片格式=jpg,png,gif,webp
自定格式=
视频路径=
图片路径=
自定路径=
[Options]
关闭至托盘=1
打开文件无需确认=1
使用pic控件=1
PlayTime=2
MainX=254
MainY=347
FirstStartApp=0
)
FileAppend, %_%, %A_ScriptDir%\随机打开.ini
}
;变量
AppVersion := "随机打开V3.0"
Startuplnk := A_StartMenu . "\Programs\Startup\随机打开.lnk"
StartupTime := A_TickCount // 1000
LitePext := "jpg,png"
CutSize := 750
;声明全局变量,函数中使用
global box2, box3, box4, Play, file, maxfile, PlayTime
;启动执行段
if (StartupTime>60)
Gosub, 主界面
Gosub, 托盘菜单
gosub, Pic右键菜单
if FirstStartApp {
if(FileExist(Startuplnk))
FileCreateShortcut, % A_ScriptFullpath, % Startuplnk
IniWrite, 0, 随机打开.ini, Options, FirstStartApp
}
return
;GUi和Menu菜单部分
;*****************************************************************************
;*****************************************************************************
;*****************************************************************************
主界面:
MainView := 1
Gosub,读取配置
Gui, Main:Add, Button,x10 y10 w130 h40 g视频Button, 视频
Gui, Main:Add, Button,x10 y55 w130 h40 g图片Button v图片Button, 图片
Gui, Main:Add, Button,x10 y100 w130 h40 g自定格式Button, 自定格式
Gui, Main:Add, Button,x10 y145 w130 h40 g设置Button, 设置
;以下为设置View(默认隐藏)
Gui, Main:Add, GroupBox, x150 y10 w180 h140, 选项
;使用文件判断checkbox状态
if (FileExist(Startuplnk))
Gui, Main:Add, CheckBox, x165 y30 w130 h30 Checked1 gAutoStartBox1, 开机启动
else
Gui, Main:Add, CheckBox, x165 y30 w130 h30 Checked0 gAutoStartBox1, 开机启动
;使用配置文件和变量判断checkbox状态
Gui, Main:Add, CheckBox, x165 y55 w130 h30 Checked%box2% g关闭至托盘Box2, 关闭至托盘
Gui, Main:Add, CheckBox, x165 y80 w130 h30 Checked%box3% gAskOpenBox3, 打开文件无需确认
Gui, Main:Add, CheckBox, x165 y105 w130 h30 Checked%box4% g使用pic控件Box4, 使用pic控件看图
Gui, Main:Add, GroupBox, x10 y205 w600 h140, 默认路径
Gui, Main:Add, Text, x25 y230 w80 h30 +0x200, 视频路径:
Gui, Main:Add, Text, x25 y265 w80 h30 +0x200, 图片路径:
Gui, Main:Add, Text, x25 y300 w80 h30 +0x200, 自定路径:
Gui, Main:Add, Text, x90 y230 w380 h30 +0x200 vText1 ;视频路径显示
Gui, Main:Add, Text, x90 y265 w380 h30 +0x200 vText2 ;图片路径显示
Gui, Main:Add, Text, x90 y300 w380 h30 +0x200 vText3 ;自定路径显示
Gui, Main:Add, Button, x475 y230 w60 h30 g设置-视频路径选择, 选择
Gui, Main:Add, Button, x475 y265 w60 h30 g设置-图片路径选择, 选择
Gui, Main:Add, Button, x475 y300 w60 h30 g设置-自定路径选择, 选择
Gui, Main:Add, Button, x540 y230 w60 h30 g设置-视频路径清除, 清除
Gui, Main:Add, Button, x540 y265 w60 h30 g设置-图片路径清除, 清除
Gui, Main:Add, Button, x540 y300 w60 h30 g设置-自定路径清除, 清除
Gui, Main:Add, GroupBox, x10 y345 w600 h140, 格式
Gui, Main:Add, Text, x25 y370 w80 h30 +0x200, 视频格式:
Gui, Main:Add, Text, x25 y405 w80 h30 +0x200, 图片格式:
Gui, Main:Add, Text, x25 y440 w80 h30 +0x200, 自定格式:
Gui, Main:Add, Button, x540 y370 w60 h30 g设置-保存视频格式, 保存
Gui, Main:Add, Button, x540 y405 w60 h30 g设置-保存图片格式, 保存
Gui, Main:Add, Button, x540 y440 w60 h30 g设置-保存自定格式, 保存
Gui, Main:Add, Text, x15 y488 w400 h30 +0x200, 本软件免费且开源,如觉得好用欢迎分享,你的鼓励就是我的动力
Gui, Main:Font, s11, Segoe UI
Gui, Main:Add, Edit, x85 y371 w450 h50 r1 vEdit1
Gui, Main:Add, Edit, x85 y406 w450 h40 r1 vEdit2
Gui, Main:Add, Edit, x85 y441 w450 h40 r1 vEdit3
;加了WindowMove函数会导致Link无法点击跳转,故不启用
; Gui, Main:Add, Link, x520 y492 w80 h30 +0x200, <a href="https://www.cnblogs.com/chr2020/p/15171012.html">软件更新</a>
Gosub, 控件数据刷新
Gui, Main: -MaximizeBox -MinimizeBox +hWndhWnd
if FirstStartApp
Gui, Main:Show ,w150 h195, %AppVersion%
else
Gui, Main:Show ,x%MainX% y%MainY% w150 h195, %AppVersion%
OnMessage(0x201, "WindowMove")
return
托盘菜单:
Menu, Tray, NoStandard
Menu, Tray, Tip, %AppVersion%
Menu, tray, add, 打开主窗口, 托盘-打开主窗口
Menu, tray, add, 打开视频, 视频Button
Menu, tray, add, 打开图片, 图片Button
Menu, tray, add, 自定格式, 自定格式Button
Menu, tray, add
Menu, tray, add, 设置, 托盘-打开设置
Menu, tray, add, 关于, 托盘-About
Menu, tray, add, 退出, Exit
Menu, Tray, Click, 1
Menu, Tray, Default, 打开主窗口
return
pic控件:
Gui, PicView: New
; Gui, PicView: Color, F0F0F0
; Gui +LastFound
; WinSet, TransColor, F0F0F0
Gui, PicView: -Caption ; +hWndhWnd2
Gui, PicView: Add, Pic,x0 y0 vPicture
OnMessage(0x201, "WindowMove")
OnMessage(0x203, "SendPlay")
;OnMessage(0x20A, "SetShowSize")
return
Pic右键菜单:
Menu, RButtonMenu,add, 开始播放 , SendPlay , 1&
Menu, RButtonMenu,add
Menu, RButtonMenu,add, 打开文件路径, 打开文件路径, 2&
Menu, RButtonMenu,add, 回到上一张, Pic_Prev, 3&
Menu, Submenu1, Add, 1, SetPlayTime
Menu, Submenu1, Add, 2, SetPlayTime
Menu, Submenu1, Add, 3, SetPlayTime
Menu, Submenu1, Add, 4, SetPlayTime
Menu, Submenu1, Add, 5, SetPlayTime
Menu, Submenu1, Add, 6, SetPlayTime
Menu, Submenu1, Add, 7, SetPlayTime
Menu, Submenu1, Add, 8, SetPlayTime
Menu, Submenu1, Add, 9, SetPlayTime
Menu, Submenu1, Add, 自定义, SetPlayTime
Menu, RButtonMenu, Add, 播放时间, :Submenu1
Menu, Submenu2, Add, 大, SetCutSize
Menu, Submenu2, Add, 中, SetCutSize
Menu, Submenu2, Add, 小, SetCutSize
Menu, Submenu2, Add
Menu, Submenu2, Add, 增大, SetCutSize
Menu, Submenu2, Add, 减小, SetCutSize
Menu, RButtonMenu, Add, 显示大小, :Submenu2
Menu, RButtonMenu,add
Menu, RButtonMenu,add, 设置, 托盘-打开设置
Menu, RButtonMenu,add, 关于, 托盘-About
Menu, RButtonMenu,add, 关闭, PicViewGuiEscape
return
PicViewGuiContextMenu:
Menu, RButtonMenu, Show
return
;主界面Button控件部分
;*****************************************************************************
;*****************************************************************************
;*****************************************************************************
视频Button:
Gosub,读取配置
if Vpath
随机打开(Vext, Vpath)
else
路径选择(Vext, Vpath, "视频路径")
return
图片Button:
Gosub,读取配置
if !box4{
if Ppath
随机打开(Pext, Ppath)
else
路径选择(Pext, Ppath, "图片路径")
return
}
else {
PicView := !PicView
if PicView {
FileList := Clear
file := 0
Loop, parse, LitePext, `,
{
Loop Files, %Ppath%\*.%A_LoopField%, R
FileList .= A_LoopFilePath "`n"
}
Sort, FileList, Random
; MsgBox %FileList%
pic := StrSplit(FileList, "`n")
maxfile := pic.Length()-1
gosub, pic控件
SetTimer, ShowPic
GuiControl, Main:Text, 图片Button, 关闭Pic控件
}
else
gosub, PicViewGuiEscape
}
return
自定格式Button:
Gosub,读取配置
if !Uext
MsgBox 0, 提示, 未设置自定格式,请在设置中添加自定格式并保存
else
if Upath
随机打开(Uext, Upath)
else if !Upath
路径选择(Uext, Upath, "自定路径")
return
设置Button:
if (MainView == 1) {
Gui, Main: +MinimizeBox -MaximizeBox
Gui, Main: Show, w620 h520, %AppVersion%-设置
MainView := 2
WinGetPos, X, Y, W, H, A
if (X+W > A_ScreenWidth)
WinMove, (A_ScreenWidth-W)
if (Y+H > A_ScreenHeight)
WinMove, ,(A_ScreenHeight-H)
}
else {
Gui, Main: -MaximizeBox -MinimizeBox
Gui, Main: Show ,w150 h195, %AppVersion%
MainView := 1
}
return
设置-视频路径选择:
路径选择2( Vpath, "视频路径")
Gosub, 控件数据刷新
return
设置-图片路径选择:
路径选择2( Ppath, "图片路径")
Gosub, 控件数据刷新
return
设置-自定路径选择:
路径选择2( Upath, "自定路径")
Gosub, 控件数据刷新
return
设置-视频路径清除:
IniWrite, %clear% , 随机打开.ini, Section, 视频路径
Gosub, 控件数据刷新
return
设置-图片路径清除:
IniWrite, %clear% , 随机打开.ini, Section, 图片路径
Gosub, 控件数据刷新
return
设置-自定路径清除:
IniWrite, %clear% , 随机打开.ini, Section, 自定路径
Gosub, 控件数据刷新
return
设置-保存视频格式:
Gui, Main:Submit, NoHide
IniWrite, %Edit1%, 随机打开.ini, Section, 视频格式
TrayTip 提示, 格式已保存
return
设置-保存图片格式:
Gui, Main:Submit, NoHide
IniWrite, %Edit2%, 随机打开.ini, Section, 图片格式
TrayTip 提示, 格式已保存
return
设置-保存自定格式:
Gui, Main:Submit, NoHide
IniWrite, %Edit3%, 随机打开.ini, Section, 自定格式
TrayTip 提示, 格式已保存
return
;与PicView控件相关的动作
;*****************************************************************************
;*****************************************************************************
;*****************************************************************************
Pic适应屏幕:
strPic = % pic[file]
objImage := ComObjCreate("WIA.ImageFile")
objImage.LoadFile(strPic)
PicW := objImage.Width
PicH := objImage.Height
ShowWidth := A_ScreenWidth-CutSize
ShowHeight := A_ScreenHeight-CutSize
loop {
if (PicW>ShowWidth or PicH>ShowHeight) {
PicW *= 0.95
PicH *= 0.95
}
else
break
}
return
ShowPic:
if (PicView and !file) {
file := 1
gosub, Pic适应屏幕
Gui, PicView: Show, x0 y0 w%PicW% h%PicH%
GuiControl, PicView: Move, Picture, w%PicW% h%PicH%
GuiControl, PicView:, Picture, % pic[file]
}
if (PicView and Play and file<maxfile) {
Sleep PlayTime*1000
file ++
gosub, Pic适应屏幕
if Play {
Gui, PicView: Show, w%PicW% h%PicH% NA
GuiControl, PicView: Move, Picture, w%PicW% h%PicH%
GuiControl, PicView:, Picture, % pic[file]
}
}
if (file==maxfile) {
Play := 0
SetTimer, ShowPic, Off
TrayTip 提示, 全部图片都看完了, ,17
}
if (!PicView and !Play) {
SetTimer, ShowPic, Off
Gui, PicView: Destroy
}
return
SendPlay() {
if (file < maxfile) {
Play := !Play
if Play {
if (file==1)
TrayTip 提示, 开始以%PlayTime%秒的速度播放%maxfile%个文件, ,17
else if (file>1) {
Remain := maxfile-file
TrayTip 提示, 以%PlayTime%秒的速度继续播放,剩余%Remain%个文件, ,17
}
Menu, RButtonMenu, Rename, 1&, 暂停播放
}
else {
TrayTip 提示, 暂停播放, ,17
Menu, RButtonMenu, Rename, 1&, 继续播放
}
}
else
TrayTip 提示, 全部图片都看完了, ,17
}
Pic_Prev:
Play := 0
if (file>1) {
file --
gosub, Pic适应屏幕
Gui, PicView: Show, w%PicW% h%PicH% NA
GuiControl, PicView: Move, Picture, w%PicW% h%PicH%
GuiControl, PicView:, Picture, % pic[file]
}
else
TrayTip 提示, 当前为第一张哦, ,17
return
SetCutSize:
if (A_ThisMenuItem == "大")
CutSize := 750
else if (A_ThisMenuItem == "中")
CutSize := 1000
else if (A_ThisMenuItem == "小")
CutSize := 1250
else if (A_ThisMenuItem == "增大")
CutSize *= 0.9
else if (A_ThisMenuItem == "减小")
CutSize *= 1.1
if !Play {
gosub, Pic适应屏幕
GuiControl, PicView: Move, Picture, w%PicW% h%PicH%
Gui, PicView: Show, w%PicW% h%PicH% NA
GuiControl, PicView:, Picture, % pic[file]
}
return
SetPlayTime:
if (A_ThisMenuItem == "自定义") {
if Play {
Play := 0
RePlay := 1
}
Gui, GetPlayTime: Destroy
MouseGetPos, GetX, GetY
Gui GetPlayTime:Add, Text, x8 y0 w136 h40 +0x200, 输入播放时间:(单位:秒)
Gui GetPlayTime:Font, s11, Segoe UI
Gui GetPlayTime:Add, Edit, x10 y35 w80 h30 center
Gui GetPlayTime:Add, UpDown, vPlayTime Range0-100
Gui GetPlayTime:Add, Button, x95 y35 w50 h30 g获取自定义时间, 确定
Gui GetPlayTime:-Caption AlwaysOnTop Border
Gui GetPlayTime:Show, x%GetX% y%GetY%
GuiControl, GetPlayTime:, PlayTime, %PlayTime%
}
else {
PlayTime := % A_ThisMenuItem
IniWrite, %PlayTime%, 随机打开.ini, Options, PlayTime
TrayTip 提示, 播放时间已调整为%PlayTime%秒, ,17
}
return
获取自定义时间:
Gui, GetPlayTime: Submit
Gui, GetPlayTime: Destroy
IniWrite, %PlayTime%, 随机打开.ini, Options, PlayTime
TrayTip 提示, 播放时间已调整为%PlayTime%秒, ,17
if RePlay
Play := 1
return
打开文件路径:
filepath := % pic[file]
RunWait, Explorer /select`, %filepath%
return
;Checkbox项目
;*****************************************************************************
;*****************************************************************************
;*****************************************************************************
AutoStartBox1:
if (FileExist(Startuplnk))
FileDelete, % Startuplnk
else
FileCreateShortcut, % A_ScriptFullpath, % Startuplnk
return
关闭至托盘Box2:
box2 := !box2
if box2
IniWrite, 1, 随机打开.ini, Options, 关闭至托盘
else
IniWrite, 0, 随机打开.ini, Options, 关闭至托盘
return
AskOpenBox3:
box3 := !box3
if box3
IniWrite, 1, 随机打开.ini, Options, 打开文件无需确认
else
IniWrite, 0, 随机打开.ini, Options, 打开文件无需确认
return
使用pic控件Box4:
box4 := !box4
if box4
IniWrite, 1, 随机打开.ini, Options, 使用pic控件
else {
IniWrite, 0, 随机打开.ini, Options, 使用pic控件
gosub, PicViewGuiEscape
}
return
;Gui关闭动作
;*****************************************************************************
;*****************************************************************************
;*****************************************************************************
MainGuiClose:
MainGuiEscape:
MainView := 0
WinGetPos, MainX, MainY, , , ahk_id %hWnd%
IniWrite, %MainX%, 随机打开.ini, Options, MainX
IniWrite, %MainY%, 随机打开.ini, Options, MainY
if box2
Gui, Main: Destroy
else
ExitApp
return
Exit:
ExitApp
return
PicViewGuiEscape:
Gui, GetPlayTime: Destroy
Play := 0
PicView := 0
SetTimer, ShowPic, Off
Gui, PicView: Destroy
TrayTip 提示, 退出Pic控件, ,17
GuiControl, Main:Text, 图片Button, 图片
return
;托盘相关动作
;*****************************************************************************
;*****************************************************************************
;*****************************************************************************
托盘-打开主窗口:
if (MainView < 1)
Gosub, 主界面
else
Gui, Main: Show
return
托盘-打开设置:
if (MainView < 1) {
Gosub, 主界面
Gui, Main: +MinimizeBox -MaximizeBox
Gui, Main: Show, w620 h520, %AppVersion%-设置
MainView := 2
}
else {
Gui, Main: Show, w620 h520, %AppVers1ion%-设置
MainView := 2
}
return
托盘-About:
Run https://www.cnblogs.com/chr2020/p/15171012.html
return
;读取ini配置文件和刷新控件
;*****************************************************************************
;*****************************************************************************
;*****************************************************************************
读取配置:
IniRead, FirstStartApp, 随机打开.ini, Options, FirstStartApp
IniRead, MainX, 随机打开.ini, Options, MainX
IniRead, MainY, 随机打开.ini, Options, MainY
IniRead, box2, 随机打开.ini, Options, 关闭至托盘
IniRead, box3, 随机打开.ini, Options, 打开文件无需确认
IniRead, box4, 随机打开.ini, Options, 使用pic控件
IniRead, PlayTime, 随机打开.ini, Options, PlayTime
IniRead, Vext, 随机打开.ini, Section, 视频格式
IniRead, Pext, 随机打开.ini, Section, 图片格式
IniRead, Uext, 随机打开.ini, Section, 自定格式
IniRead, Vpath, 随机打开.ini, Section, 视频路径
IniRead, Ppath, 随机打开.ini, Section, 图片路径
IniRead, Upath, 随机打开.ini, Section, 自定路径
return
控件数据刷新:
gosub, 读取配置
GuiControl, Main:, Text1, %Vpath%
GuiControl, Main:, Text2, %Ppath%
GuiControl, Main:, Text3, %Upath%
GuiControl, Main:, Edit1, %Vext%
GuiControl, Main:, Edit2, %Pext%
GuiControl, Main:, Edit3, %Uext%
return
;函数
;*****************************************************************************
;*****************************************************************************
;*****************************************************************************
路径选择(ext,path,vb){
FileSelectFolder, WhichFolder, ::{20d04fe0-3aea-1069-a2d8-08002b30309d},,选择路径
if ErrorLevel
return
else {
MsgBox 4, 提示, 是否保存为默认%vb%?
IfMsgBox Yes
IniWrite, %WhichFolder%, 随机打开.ini, Section, %vb%
Gosub, 控件数据刷新
随机打开(ext, WhichFolder)
}
}
路径选择2(path,vb){
FileSelectFolder, WhichFolder, ::{20d04fe0-3aea-1069-a2d8-08002b30309d},,选择路径
if ErrorLevel
return
else
IniWrite, %WhichFolder%, 随机打开.ini, Section, %vb%
}
随机打开(ext,path){
Loop, parse, ext, `,
{
Loop Files, %path%\*.%A_LoopField%, R
FileList .= A_LoopFilePath "`n"
}
Sort, FileList, Random
loop, Parse, FileList, `n
{
if !box3 {
MsgBox 4, 打开文件?,%A_LoopField%
IfMsgBox Yes
Run %A_LoopField%
}
else
Run %A_LoopField%
break
}
}
WindowMove(){
PostMessage, 0xA1, 2
}
; By 有千山 #NoEnv ;不检查空变量是否为环境变量 #SingleInstance, Force ;新开程序替换旧实例 #Persistent ;让脚本持续运行(即直到用户关闭或遇到 ExitApp). SetBatchLines, -1 ;让操作以最快速度进行 ;强制设置工作路径为软件所在文件夹,否则使用快捷方式打开软件无法读取随同的配置文件 SetWorkingDir %A_ScriptDir% if !FileExist(A_ScriptDir "\随机打开.ini") { _= ( [Section] 视频格式=mp4,avi,rmvb,flv,mpeg,wmv,mkv 图片格式=jpg,png,gif,webp 自定格式= 视频路径= 图片路径= 自定路径= [Options] 关闭至托盘=1 打开文件无需确认=1 使用pic控件=1 PlayTime=2 MainX=254 MainY=347 FirstStartApp=0 ) FileAppend, %_%, %A_ScriptDir%\随机打开.ini } ;变量 AppVersion := "随机打开V3.0" Startuplnk := A_StartMenu . "\Programs\Startup\随机打开.lnk" StartupTime := A_TickCount // 1000 LitePext := "jpg,png" CutSize := 750 ;声明全局变量,函数中使用 global box2, box3, box4, Play, file, maxfile, PlayTime ;启动执行段 if (StartupTime>60) Gosub, 主界面 Gosub, 托盘菜单 gosub, Pic右键菜单 if FirstStartApp { if(FileExist(Startuplnk)) FileCreateShortcut, % A_ScriptFullpath, % Startuplnk IniWrite, 0, 随机打开.ini, Options, FirstStartApp } return ;GUi和Menu菜单部分 ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** 主界面: MainView := 1 Gosub,读取配置 Gui, Main:Add, Button,x10 y10 w130 h40 g视频Button, 视频 Gui, Main:Add, Button,x10 y55 w130 h40 g图片Button v图片Button, 图片 Gui, Main:Add, Button,x10 y100 w130 h40 g自定格式Button, 自定格式 Gui, Main:Add, Button,x10 y145 w130 h40 g设置Button, 设置 ;以下为设置View(默认隐藏) Gui, Main:Add, GroupBox, x150 y10 w180 h140, 选项 ;使用文件判断checkbox状态 if (FileExist(Startuplnk)) Gui, Main:Add, CheckBox, x165 y30 w130 h30 Checked1 gAutoStartBox1, 开机启动 else Gui, Main:Add, CheckBox, x165 y30 w130 h30 Checked0 gAutoStartBox1, 开机启动 ;使用配置文件和变量判断checkbox状态 Gui, Main:Add, CheckBox, x165 y55 w130 h30 Checked%box2% g关闭至托盘Box2, 关闭至托盘 Gui, Main:Add, CheckBox, x165 y80 w130 h30 Checked%box3% gAskOpenBox3, 打开文件无需确认 Gui, Main:Add, CheckBox, x165 y105 w130 h30 Checked%box4% g使用pic控件Box4, 使用pic控件看图 Gui, Main:Add, GroupBox, x10 y205 w600 h140, 默认路径 Gui, Main:Add, Text, x25 y230 w80 h30 +0x200, 视频路径: Gui, Main:Add, Text, x25 y265 w80 h30 +0x200, 图片路径: Gui, Main:Add, Text, x25 y300 w80 h30 +0x200, 自定路径: Gui, Main:Add, Text, x90 y230 w380 h30 +0x200 vText1 ;视频路径显示 Gui, Main:Add, Text, x90 y265 w380 h30 +0x200 vText2 ;图片路径显示 Gui, Main:Add, Text, x90 y300 w380 h30 +0x200 vText3 ;自定路径显示 Gui, Main:Add, Button, x475 y230 w60 h30 g设置-视频路径选择, 选择 Gui, Main:Add, Button, x475 y265 w60 h30 g设置-图片路径选择, 选择 Gui, Main:Add, Button, x475 y300 w60 h30 g设置-自定路径选择, 选择 Gui, Main:Add, Button, x540 y230 w60 h30 g设置-视频路径清除, 清除 Gui, Main:Add, Button, x540 y265 w60 h30 g设置-图片路径清除, 清除 Gui, Main:Add, Button, x540 y300 w60 h30 g设置-自定路径清除, 清除 Gui, Main:Add, GroupBox, x10 y345 w600 h140, 格式 Gui, Main:Add, Text, x25 y370 w80 h30 +0x200, 视频格式: Gui, Main:Add, Text, x25 y405 w80 h30 +0x200, 图片格式: Gui, Main:Add, Text, x25 y440 w80 h30 +0x200, 自定格式: Gui, Main:Add, Button, x540 y370 w60 h30 g设置-保存视频格式, 保存 Gui, Main:Add, Button, x540 y405 w60 h30 g设置-保存图片格式, 保存 Gui, Main:Add, Button, x540 y440 w60 h30 g设置-保存自定格式, 保存 Gui, Main:Add, Text, x15 y488 w400 h30 +0x200, 本软件免费且开源,如觉得好用欢迎分享,你的鼓励就是我的动力 Gui, Main:Font, s11, Segoe UI Gui, Main:Add, Edit, x85 y371 w450 h50 r1 vEdit1 Gui, Main:Add, Edit, x85 y406 w450 h40 r1 vEdit2 Gui, Main:Add, Edit, x85 y441 w450 h40 r1 vEdit3 ;加了WindowMove函数会导致Link无法点击跳转,故不启用 ; Gui, Main:Add, Link, x520 y492 w80 h30 +0x200, <a href="https://www.cnblogs.com/chr2020/p/15171012.html">软件更新</a> Gosub, 控件数据刷新 Gui, Main: -MaximizeBox -MinimizeBox +hWndhWnd if FirstStartApp Gui, Main:Show ,w150 h195, %AppVersion% else Gui, Main:Show ,x%MainX% y%MainY% w150 h195, %AppVersion% OnMessage(0x201, "WindowMove") return 托盘菜单: Menu, Tray, NoStandard Menu, Tray, Tip, %AppVersion% Menu, tray, add, 打开主窗口, 托盘-打开主窗口 Menu, tray, add, 打开视频, 视频Button Menu, tray, add, 打开图片, 图片Button Menu, tray, add, 自定格式, 自定格式Button Menu, tray, add Menu, tray, add, 设置, 托盘-打开设置 Menu, tray, add, 关于, 托盘-About Menu, tray, add, 退出, Exit Menu, Tray, Click, 1 Menu, Tray, Default, 打开主窗口 return pic控件: Gui, PicView: New ; Gui, PicView: Color, F0F0F0 ; Gui +LastFound ; WinSet, TransColor, F0F0F0 Gui, PicView: -Caption ; +hWndhWnd2 Gui, PicView: Add, Pic,x0 y0 vPicture OnMessage(0x201, "WindowMove") OnMessage(0x203, "SendPlay") ;OnMessage(0x20A, "SetShowSize") return Pic右键菜单: Menu, RButtonMenu,add, 开始播放 , SendPlay , 1& Menu, RButtonMenu,add Menu, RButtonMenu,add, 打开文件路径, 打开文件路径, 2& Menu, RButtonMenu,add, 回到上一张, Pic_Prev, 3& Menu, Submenu1, Add, 1, SetPlayTime Menu, Submenu1, Add, 2, SetPlayTime Menu, Submenu1, Add, 3, SetPlayTime Menu, Submenu1, Add, 4, SetPlayTime Menu, Submenu1, Add, 5, SetPlayTime Menu, Submenu1, Add, 6, SetPlayTime Menu, Submenu1, Add, 7, SetPlayTime Menu, Submenu1, Add, 8, SetPlayTime Menu, Submenu1, Add, 9, SetPlayTime Menu, Submenu1, Add, 自定义, SetPlayTime Menu, RButtonMenu, Add, 播放时间, :Submenu1 Menu, Submenu2, Add, 大, SetCutSize Menu, Submenu2, Add, 中, SetCutSize Menu, Submenu2, Add, 小, SetCutSize Menu, Submenu2, Add Menu, Submenu2, Add, 增大, SetCutSize Menu, Submenu2, Add, 减小, SetCutSize Menu, RButtonMenu, Add, 显示大小, :Submenu2 Menu, RButtonMenu,add Menu, RButtonMenu,add, 设置, 托盘-打开设置 Menu, RButtonMenu,add, 关于, 托盘-About Menu, RButtonMenu,add, 关闭, PicViewGuiEscape return PicViewGuiContextMenu: Menu, RButtonMenu, Show return ;主界面Button控件部分 ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** 视频Button: Gosub,读取配置 if Vpath 随机打开(Vext, Vpath) else 路径选择(Vext, Vpath, "视频路径") return 图片Button: Gosub,读取配置 if !box4{ if Ppath 随机打开(Pext, Ppath) else 路径选择(Pext, Ppath, "图片路径") return } else { PicView := !PicView if PicView { FileList := Clear file := 0 Loop, parse, LitePext, `, { Loop Files, %Ppath%\*.%A_LoopField%, R FileList .= A_LoopFilePath "`n" } Sort, FileList, Random ; MsgBox %FileList% pic := StrSplit(FileList, "`n") maxfile := pic.Length()-1 gosub, pic控件 SetTimer, ShowPic GuiControl, Main:Text, 图片Button, 关闭Pic控件 } else gosub, PicViewGuiEscape } return 自定格式Button: Gosub,读取配置 if !Uext MsgBox 0, 提示, 未设置自定格式,请在设置中添加自定格式并保存 else if Upath 随机打开(Uext, Upath) else if !Upath 路径选择(Uext, Upath, "自定路径") return 设置Button: if (MainView == 1) { Gui, Main: +MinimizeBox -MaximizeBox Gui, Main: Show, w620 h520, %AppVersion%-设置 MainView := 2 WinGetPos, X, Y, W, H, A if (X+W > A_ScreenWidth) WinMove, (A_ScreenWidth-W) if (Y+H > A_ScreenHeight) WinMove, ,(A_ScreenHeight-H) } else { Gui, Main: -MaximizeBox -MinimizeBox Gui, Main: Show ,w150 h195, %AppVersion% MainView := 1 } return 设置-视频路径选择: 路径选择2( Vpath, "视频路径") Gosub, 控件数据刷新 return 设置-图片路径选择: 路径选择2( Ppath, "图片路径") Gosub, 控件数据刷新 return 设置-自定路径选择: 路径选择2( Upath, "自定路径") Gosub, 控件数据刷新 return 设置-视频路径清除: IniWrite, %clear% , 随机打开.ini, Section, 视频路径 Gosub, 控件数据刷新 return 设置-图片路径清除: IniWrite, %clear% , 随机打开.ini, Section, 图片路径 Gosub, 控件数据刷新 return 设置-自定路径清除: IniWrite, %clear% , 随机打开.ini, Section, 自定路径 Gosub, 控件数据刷新 return 设置-保存视频格式: Gui, Main:Submit, NoHide IniWrite, %Edit1%, 随机打开.ini, Section, 视频格式 TrayTip 提示, 格式已保存 return 设置-保存图片格式: Gui, Main:Submit, NoHide IniWrite, %Edit2%, 随机打开.ini, Section, 图片格式 TrayTip 提示, 格式已保存 return 设置-保存自定格式: Gui, Main:Submit, NoHide IniWrite, %Edit3%, 随机打开.ini, Section, 自定格式 TrayTip 提示, 格式已保存 return ;与PicView控件相关的动作 ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** Pic适应屏幕: strPic = % pic[file] objImage := ComObjCreate("WIA.ImageFile") objImage.LoadFile(strPic) PicW := objImage.Width PicH := objImage.Height ShowWidth := A_ScreenWidth-CutSize ShowHeight := A_ScreenHeight-CutSize loop { if (PicW>ShowWidth or PicH>ShowHeight) { PicW *= 0.95 PicH *= 0.95 } else break } return ShowPic: if (PicView and !file) { file := 1 gosub, Pic适应屏幕 Gui, PicView: Show, x0 y0 w%PicW% h%PicH% GuiControl, PicView: Move, Picture, w%PicW% h%PicH% GuiControl, PicView:, Picture, % pic[file] } if (PicView and Play and file<maxfile) { Sleep PlayTime*1000 file ++ gosub, Pic适应屏幕 if Play { Gui, PicView: Show, w%PicW% h%PicH% NA GuiControl, PicView: Move, Picture, w%PicW% h%PicH% GuiControl, PicView:, Picture, % pic[file] } } if (file==maxfile) { Play := 0 SetTimer, ShowPic, Off TrayTip 提示, 全部图片都看完了, ,17 } if (!PicView and !Play) { SetTimer, ShowPic, Off Gui, PicView: Destroy } return SendPlay() { if (file < maxfile) { Play := !Play if Play { if (file==1) TrayTip 提示, 开始以%PlayTime%秒的速度播放%maxfile%个文件, ,17 else if (file>1) { Remain := maxfile-file TrayTip 提示, 以%PlayTime%秒的速度继续播放,剩余%Remain%个文件, ,17 } Menu, RButtonMenu, Rename, 1&, 暂停播放 } else { TrayTip 提示, 暂停播放, ,17 Menu, RButtonMenu, Rename, 1&, 继续播放 } } else TrayTip 提示, 全部图片都看完了, ,17 } Pic_Prev: Play := 0 if (file>1) { file -- gosub, Pic适应屏幕 Gui, PicView: Show, w%PicW% h%PicH% NA GuiControl, PicView: Move, Picture, w%PicW% h%PicH% GuiControl, PicView:, Picture, % pic[file] } else TrayTip 提示, 当前为第一张哦, ,17 return SetCutSize: if (A_ThisMenuItem == "大") CutSize := 750 else if (A_ThisMenuItem == "中") CutSize := 1000 else if (A_ThisMenuItem == "小") CutSize := 1250 else if (A_ThisMenuItem == "增大") CutSize *= 0.9 else if (A_ThisMenuItem == "减小") CutSize *= 1.1 if !Play { gosub, Pic适应屏幕 GuiControl, PicView: Move, Picture, w%PicW% h%PicH% Gui, PicView: Show, w%PicW% h%PicH% NA GuiControl, PicView:, Picture, % pic[file] } return SetPlayTime: if (A_ThisMenuItem == "自定义") { if Play { Play := 0 RePlay := 1 } Gui, GetPlayTime: Destroy MouseGetPos, GetX, GetY Gui GetPlayTime:Add, Text, x8 y0 w136 h40 +0x200, 输入播放时间:(单位:秒) Gui GetPlayTime:Font, s11, Segoe UI Gui GetPlayTime:Add, Edit, x10 y35 w80 h30 center Gui GetPlayTime:Add, UpDown, vPlayTime Range0-100 Gui GetPlayTime:Add, Button, x95 y35 w50 h30 g获取自定义时间, 确定 Gui GetPlayTime:-Caption AlwaysOnTop Border Gui GetPlayTime:Show, x%GetX% y%GetY% GuiControl, GetPlayTime:, PlayTime, %PlayTime% } else { PlayTime := % A_ThisMenuItem IniWrite, %PlayTime%, 随机打开.ini, Options, PlayTime TrayTip 提示, 播放时间已调整为%PlayTime%秒, ,17 } return 获取自定义时间: Gui, GetPlayTime: Submit Gui, GetPlayTime: Destroy IniWrite, %PlayTime%, 随机打开.ini, Options, PlayTime TrayTip 提示, 播放时间已调整为%PlayTime%秒, ,17 if RePlay Play := 1 return 打开文件路径: filepath := % pic[file] RunWait, Explorer /select`, %filepath% return ;Checkbox项目 ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** AutoStartBox1: if (FileExist(Startuplnk)) FileDelete, % Startuplnk else FileCreateShortcut, % A_ScriptFullpath, % Startuplnk return 关闭至托盘Box2: box2 := !box2 if box2 IniWrite, 1, 随机打开.ini, Options, 关闭至托盘 else IniWrite, 0, 随机打开.ini, Options, 关闭至托盘 return AskOpenBox3: box3 := !box3 if box3 IniWrite, 1, 随机打开.ini, Options, 打开文件无需确认 else IniWrite, 0, 随机打开.ini, Options, 打开文件无需确认 return 使用pic控件Box4: box4 := !box4 if box4 IniWrite, 1, 随机打开.ini, Options, 使用pic控件 else { IniWrite, 0, 随机打开.ini, Options, 使用pic控件 gosub, PicViewGuiEscape } return ;Gui关闭动作 ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** MainGuiClose: MainGuiEscape: MainView := 0 WinGetPos, MainX, MainY, , , ahk_id %hWnd% IniWrite, %MainX%, 随机打开.ini, Options, MainX IniWrite, %MainY%, 随机打开.ini, Options, MainY if box2 Gui, Main: Destroy else ExitApp return Exit: ExitApp return PicViewGuiEscape: Gui, GetPlayTime: Destroy Play := 0 PicView := 0 SetTimer, ShowPic, Off Gui, PicView: Destroy TrayTip 提示, 退出Pic控件, ,17 GuiControl, Main:Text, 图片Button, 图片 return ;托盘相关动作 ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** 托盘-打开主窗口: if (MainView < 1) Gosub, 主界面 else Gui, Main: Show return 托盘-打开设置: if (MainView < 1) { Gosub, 主界面 Gui, Main: +MinimizeBox -MaximizeBox Gui, Main: Show, w620 h520, %AppVersion%-设置 MainView := 2 } else { Gui, Main: Show, w620 h520, %AppVers1ion%-设置 MainView := 2 } return 托盘-About: Run https://www.cnblogs.com/chr2020/p/15171012.html return ;读取ini配置文件和刷新控件 ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** 读取配置: IniRead, FirstStartApp, 随机打开.ini, Options, FirstStartApp IniRead, MainX, 随机打开.ini, Options, MainX IniRead, MainY, 随机打开.ini, Options, MainY IniRead, box2, 随机打开.ini, Options, 关闭至托盘 IniRead, box3, 随机打开.ini, Options, 打开文件无需确认 IniRead, box4, 随机打开.ini, Options, 使用pic控件 IniRead, PlayTime, 随机打开.ini, Options, PlayTime IniRead, Vext, 随机打开.ini, Section, 视频格式 IniRead, Pext, 随机打开.ini, Section, 图片格式 IniRead, Uext, 随机打开.ini, Section, 自定格式 IniRead, Vpath, 随机打开.ini, Section, 视频路径 IniRead, Ppath, 随机打开.ini, Section, 图片路径 IniRead, Upath, 随机打开.ini, Section, 自定路径 return 控件数据刷新: gosub, 读取配置 GuiControl, Main:, Text1, %Vpath% GuiControl, Main:, Text2, %Ppath% GuiControl, Main:, Text3, %Upath% GuiControl, Main:, Edit1, %Vext% GuiControl, Main:, Edit2, %Pext% GuiControl, Main:, Edit3, %Uext% return ;函数 ;***************************************************************************** ;***************************************************************************** ;***************************************************************************** 路径选择(ext,path,vb){ FileSelectFolder, WhichFolder, ::{20d04fe0-3aea-1069-a2d8-08002b30309d},,选择路径 if ErrorLevel return else { MsgBox 4, 提示, 是否保存为默认%vb%? IfMsgBox Yes IniWrite, %WhichFolder%, 随机打开.ini, Section, %vb% Gosub, 控件数据刷新 随机打开(ext, WhichFolder) } } 路径选择2(path,vb){ FileSelectFolder, WhichFolder, ::{20d04fe0-3aea-1069-a2d8-08002b30309d},,选择路径 if ErrorLevel return else IniWrite, %WhichFolder%, 随机打开.ini, Section, %vb% } 随机打开(ext,path){ Loop, parse, ext, `, { Loop Files, %path%\*.%A_LoopField%, R FileList .= A_LoopFilePath "`n" } Sort, FileList, Random loop, Parse, FileList, `n { if !box3 { MsgBox 4, 打开文件?,%A_LoopField% IfMsgBox Yes Run %A_LoopField% } else Run %A_LoopField% break } } WindowMove(){ PostMessage, 0xA1, 2 }
; By 有千山
#NoEnv							 ;不检查空变量是否为环境变量
#SingleInstance, Force			 ;新开程序替换旧实例
#Persistent						;让脚本持续运行(即直到用户关闭或遇到 ExitApp).
SetBatchLines, -1				  ;让操作以最快速度进行

;强制设置工作路径为软件所在文件夹,否则使用快捷方式打开软件无法读取随同的配置文件
SetWorkingDir %A_ScriptDir%

if !FileExist(A_ScriptDir "\随机打开.ini") {
_=
(
[Section]
视频格式=mp4,avi,rmvb,flv,mpeg,wmv,mkv
图片格式=jpg,png,gif,webp
自定格式=
视频路径=
图片路径=
自定路径=

[Options]
关闭至托盘=1
打开文件无需确认=1
使用pic控件=1
PlayTime=2
MainX=254
MainY=347
FirstStartApp=0
)
FileAppend, %_%, %A_ScriptDir%\随机打开.ini
}

;变量
AppVersion := "随机打开V3.0"
Startuplnk := A_StartMenu . "\Programs\Startup\随机打开.lnk"
StartupTime := A_TickCount // 1000
LitePext  := "jpg,png"
CutSize := 750

;声明全局变量,函数中使用
global box2, box3, box4, Play, file, maxfile, PlayTime

;启动执行段
if (StartupTime>60)
Gosub, 主界面
Gosub, 托盘菜单
gosub, Pic右键菜单
if FirstStartApp {
  if(FileExist(Startuplnk))
  FileCreateShortcut, % A_ScriptFullpath, % Startuplnk
  IniWrite, 0, 随机打开.ini, Options, FirstStartApp
}
return


;GUi和Menu菜单部分
;*****************************************************************************
;*****************************************************************************
;*****************************************************************************
主界面:
  MainView := 1
  Gosub,读取配置
  Gui, Main:Add, Button,x10 y10 w130 h40 g视频Button, 视频
  Gui, Main:Add, Button,x10 y55 w130 h40 g图片Button v图片Button, 图片
  Gui, Main:Add, Button,x10 y100 w130 h40 g自定格式Button, 自定格式
  Gui, Main:Add, Button,x10 y145 w130 h40 g设置Button, 设置

  ;以下为设置View(默认隐藏)
  Gui, Main:Add, GroupBox, x150 y10 w180 h140, 选项
  ;使用文件判断checkbox状态
  if (FileExist(Startuplnk))
  Gui, Main:Add, CheckBox, x165 y30 w130 h30 Checked1 gAutoStartBox1, 开机启动
  else
  Gui, Main:Add, CheckBox, x165 y30 w130 h30 Checked0 gAutoStartBox1, 开机启动
  ;使用配置文件和变量判断checkbox状态
  Gui, Main:Add, CheckBox, x165 y55 w130 h30 Checked%box2% g关闭至托盘Box2, 关闭至托盘
  Gui, Main:Add, CheckBox, x165 y80 w130 h30 Checked%box3% gAskOpenBox3, 打开文件无需确认
  Gui, Main:Add, CheckBox, x165 y105 w130 h30 Checked%box4% g使用pic控件Box4, 使用pic控件看图

  Gui, Main:Add, GroupBox, x10 y205 w600 h140, 默认路径
  Gui, Main:Add, Text, x25 y230 w80 h30 +0x200, 视频路径:
  Gui, Main:Add, Text, x25 y265 w80 h30 +0x200, 图片路径:
  Gui, Main:Add, Text, x25 y300 w80 h30 +0x200, 自定路径:

  Gui, Main:Add, Text, x90 y230 w380 h30 +0x200 vText1 ;视频路径显示
  Gui, Main:Add, Text, x90 y265 w380 h30 +0x200 vText2 ;图片路径显示
  Gui, Main:Add, Text, x90 y300 w380 h30 +0x200 vText3 ;自定路径显示

  Gui, Main:Add, Button, x475 y230 w60 h30 g设置-视频路径选择, 选择
  Gui, Main:Add, Button, x475 y265 w60 h30 g设置-图片路径选择, 选择
  Gui, Main:Add, Button, x475 y300 w60 h30 g设置-自定路径选择, 选择

  Gui, Main:Add, Button, x540 y230 w60 h30 g设置-视频路径清除, 清除
  Gui, Main:Add, Button, x540 y265 w60 h30 g设置-图片路径清除, 清除
  Gui, Main:Add, Button, x540 y300 w60 h30 g设置-自定路径清除, 清除

  Gui, Main:Add, GroupBox, x10 y345 w600 h140, 格式
  Gui, Main:Add, Text, x25 y370 w80 h30 +0x200, 视频格式:
  Gui, Main:Add, Text, x25 y405 w80 h30 +0x200, 图片格式:
  Gui, Main:Add, Text, x25 y440 w80 h30 +0x200, 自定格式:

  Gui, Main:Add, Button, x540 y370 w60 h30 g设置-保存视频格式, 保存
  Gui, Main:Add, Button, x540 y405 w60 h30 g设置-保存图片格式, 保存
  Gui, Main:Add, Button, x540 y440 w60 h30 g设置-保存自定格式, 保存
  
  Gui, Main:Add, Text, x15 y488 w400 h30 +0x200, 本软件免费且开源,如觉得好用欢迎分享,你的鼓励就是我的动力
  
  Gui, Main:Font, s11, Segoe UI
  Gui, Main:Add, Edit, x85 y371 w450 h50 r1 vEdit1
  Gui, Main:Add, Edit, x85 y406 w450 h40 r1 vEdit2
  Gui, Main:Add, Edit, x85 y441 w450 h40 r1 vEdit3

  ;加了WindowMove函数会导致Link无法点击跳转,故不启用
  ; Gui, Main:Add, Link, x520 y492 w80 h30 +0x200, <a href="https://www.cnblogs.com/chr2020/p/15171012.html">软件更新</a>

  Gosub, 控件数据刷新
  Gui, Main: -MaximizeBox -MinimizeBox +hWndhWnd

  if FirstStartApp
  Gui, Main:Show ,w150 h195, %AppVersion%
  else
  Gui, Main:Show ,x%MainX% y%MainY% w150 h195, %AppVersion%
  OnMessage(0x201, "WindowMove")
  return

托盘菜单:
  Menu, Tray, NoStandard
  Menu, Tray, Tip, %AppVersion%
  Menu, tray, add, 打开主窗口, 托盘-打开主窗口
  Menu, tray, add, 打开视频, 视频Button
  Menu, tray, add, 打开图片, 图片Button
  Menu, tray, add, 自定格式, 自定格式Button
  Menu, tray, add
  Menu, tray, add, 设置, 托盘-打开设置
  Menu, tray, add, 关于, 托盘-About
  Menu, tray, add, 退出, Exit
  Menu, Tray, Click, 1
  Menu, Tray, Default, 打开主窗口
  return

pic控件:
  Gui, PicView: New
  ; Gui, PicView: Color, F0F0F0
  ; Gui +LastFound
  ; WinSet, TransColor, F0F0F0
  Gui, PicView: -Caption ; +hWndhWnd2
  Gui, PicView: Add, Pic,x0 y0 vPicture
  OnMessage(0x201, "WindowMove")
  OnMessage(0x203, "SendPlay")
  ;OnMessage(0x20A, "SetShowSize")
  return

Pic右键菜单:
  Menu, RButtonMenu,add, 开始播放 , SendPlay , 1&
  Menu, RButtonMenu,add
  Menu, RButtonMenu,add, 打开文件路径, 打开文件路径, 2&
  Menu, RButtonMenu,add, 回到上一张, Pic_Prev, 3&

  Menu, Submenu1, Add, 1, SetPlayTime
  Menu, Submenu1, Add, 2, SetPlayTime
  Menu, Submenu1, Add, 3, SetPlayTime
  Menu, Submenu1, Add, 4, SetPlayTime
  Menu, Submenu1, Add, 5, SetPlayTime
  Menu, Submenu1, Add, 6, SetPlayTime
  Menu, Submenu1, Add, 7, SetPlayTime
  Menu, Submenu1, Add, 8, SetPlayTime
  Menu, Submenu1, Add, 9, SetPlayTime
  Menu, Submenu1, Add, 自定义, SetPlayTime
  Menu, RButtonMenu, Add, 播放时间, :Submenu1

  Menu, Submenu2, Add, 大, SetCutSize
  Menu, Submenu2, Add, 中, SetCutSize
  Menu, Submenu2, Add, 小, SetCutSize
  Menu, Submenu2, Add
  Menu, Submenu2, Add, 增大, SetCutSize
  Menu, Submenu2, Add, 减小, SetCutSize
  Menu, RButtonMenu, Add, 显示大小, :Submenu2
  
  Menu, RButtonMenu,add
  Menu, RButtonMenu,add, 设置, 托盘-打开设置
  Menu, RButtonMenu,add, 关于, 托盘-About
  Menu, RButtonMenu,add, 关闭, PicViewGuiEscape
  return

PicViewGuiContextMenu:
  Menu, RButtonMenu, Show
  return



;主界面Button控件部分
;*****************************************************************************
;*****************************************************************************
;*****************************************************************************
视频Button:
  Gosub,读取配置
  if Vpath
    随机打开(Vext, Vpath)
  else 
    路径选择(Vext, Vpath, "视频路径")
  return

图片Button:
  Gosub,读取配置
  if !box4{
    if Ppath
      随机打开(Pext, Ppath)
    else
      路径选择(Pext, Ppath, "图片路径")
    return
  }
  else {
    PicView := !PicView
    if PicView {
      FileList := Clear
      file := 0
      Loop, parse, LitePext, `,
      {
        Loop Files, %Ppath%\*.%A_LoopField%, R
        FileList .= A_LoopFilePath "`n"
      }
      Sort, FileList, Random
      ; MsgBox %FileList%
      pic := StrSplit(FileList, "`n")
      maxfile := pic.Length()-1
      
      gosub, pic控件
      SetTimer, ShowPic
      GuiControl, Main:Text, 图片Button, 关闭Pic控件
     }
     else
      gosub, PicViewGuiEscape
  }
  return

自定格式Button:
  Gosub,读取配置
  if !Uext
    MsgBox 0, 提示, 未设置自定格式,请在设置中添加自定格式并保存
  else
    if Upath
      随机打开(Uext, Upath)
    else if !Upath
      路径选择(Uext, Upath, "自定路径")
  return

设置Button:
  if (MainView == 1) {
    Gui, Main: +MinimizeBox -MaximizeBox
    Gui, Main: Show, w620 h520, %AppVersion%-设置
    MainView := 2

    WinGetPos, X, Y, W, H, A
    if (X+W > A_ScreenWidth)
      WinMove, (A_ScreenWidth-W)
    if (Y+H > A_ScreenHeight)
      WinMove, ,(A_ScreenHeight-H)
  }
  else {
    Gui, Main: -MaximizeBox -MinimizeBox
    Gui, Main: Show ,w150 h195, %AppVersion%
    MainView := 1
  }
  return

设置-视频路径选择:
  路径选择2( Vpath, "视频路径")
  Gosub, 控件数据刷新
  return
设置-图片路径选择:
  路径选择2( Ppath, "图片路径")
  Gosub, 控件数据刷新
  return
设置-自定路径选择:
  路径选择2( Upath, "自定路径")
  Gosub, 控件数据刷新
  return
设置-视频路径清除:
  IniWrite, %clear% , 随机打开.ini, Section, 视频路径
  Gosub, 控件数据刷新
  return
设置-图片路径清除:
  IniWrite, %clear% , 随机打开.ini, Section, 图片路径
  Gosub, 控件数据刷新
  return
设置-自定路径清除:
  IniWrite, %clear% , 随机打开.ini, Section, 自定路径
  Gosub, 控件数据刷新
  return
设置-保存视频格式:
  Gui, Main:Submit, NoHide
  IniWrite, %Edit1%, 随机打开.ini, Section, 视频格式
  TrayTip 提示, 格式已保存
  return
设置-保存图片格式:
  Gui, Main:Submit, NoHide
  IniWrite, %Edit2%, 随机打开.ini, Section, 图片格式
  TrayTip 提示, 格式已保存
  return
设置-保存自定格式:
  Gui, Main:Submit, NoHide
  IniWrite, %Edit3%, 随机打开.ini, Section, 自定格式
  TrayTip 提示, 格式已保存
  return


;与PicView控件相关的动作
;*****************************************************************************
;*****************************************************************************
;*****************************************************************************
Pic适应屏幕:
  strPic = % pic[file]
  objImage := ComObjCreate("WIA.ImageFile")
  objImage.LoadFile(strPic)
  PicW := objImage.Width
  PicH := objImage.Height
  ShowWidth := A_ScreenWidth-CutSize
  ShowHeight := A_ScreenHeight-CutSize
  loop {
    if (PicW>ShowWidth or PicH>ShowHeight) {
      PicW *= 0.95
      PicH *= 0.95
    }
    else
    break
  }
  return

ShowPic:
  if (PicView and !file) {
    file := 1
    gosub, Pic适应屏幕
    Gui, PicView: Show, x0 y0 w%PicW% h%PicH%
    GuiControl, PicView: Move, Picture, w%PicW% h%PicH%
    GuiControl, PicView:, Picture, % pic[file] 
  }
  if (PicView and Play and file<maxfile) {
    Sleep PlayTime*1000
    file ++
    gosub, Pic适应屏幕
    if Play {
      Gui, PicView: Show, w%PicW% h%PicH% NA
      GuiControl, PicView: Move, Picture, w%PicW% h%PicH%
      GuiControl, PicView:, Picture, % pic[file]
    }
  }
  if (file==maxfile) {
    Play := 0
    SetTimer, ShowPic, Off
    TrayTip 提示, 全部图片都看完了, ,17
  }
  if (!PicView and !Play) {
    SetTimer, ShowPic, Off
    Gui, PicView: Destroy
  }
  return

SendPlay() {
  if (file < maxfile) {
    Play := !Play
    if Play {
      if (file==1)
        TrayTip 提示, 开始以%PlayTime%秒的速度播放%maxfile%个文件, ,17
      else if (file>1) {
        Remain := maxfile-file
        TrayTip 提示, 以%PlayTime%秒的速度继续播放,剩余%Remain%个文件, ,17
      }
      Menu, RButtonMenu, Rename, 1&, 暂停播放
    }
    else {
      TrayTip 提示, 暂停播放, ,17
      Menu, RButtonMenu, Rename, 1&, 继续播放
    }
  }   
  else
    TrayTip 提示, 全部图片都看完了, ,17
}

Pic_Prev:
  Play := 0
  if (file>1) {
    file --
    gosub, Pic适应屏幕
    Gui, PicView: Show, w%PicW% h%PicH% NA
    GuiControl, PicView: Move, Picture, w%PicW% h%PicH%
    GuiControl, PicView:, Picture, % pic[file]
  }
  else
    TrayTip 提示, 当前为第一张哦, ,17
  return

SetCutSize:
  if (A_ThisMenuItem == "大")
    CutSize := 750
  else if (A_ThisMenuItem == "中")
    CutSize := 1000
  else if (A_ThisMenuItem == "小")
    CutSize := 1250
  else if (A_ThisMenuItem == "增大")
    CutSize *= 0.9
  else if (A_ThisMenuItem == "减小")
    CutSize *= 1.1
  if !Play {
    gosub, Pic适应屏幕
    GuiControl, PicView: Move, Picture, w%PicW% h%PicH%
    Gui, PicView: Show, w%PicW% h%PicH% NA
    GuiControl, PicView:, Picture, % pic[file]
  }
return

SetPlayTime:
  if (A_ThisMenuItem == "自定义") {
    if Play {
      Play := 0
      RePlay := 1
    }
    Gui, GetPlayTime: Destroy
    MouseGetPos, GetX, GetY
    Gui GetPlayTime:Add, Text, x8 y0 w136 h40 +0x200, 输入播放时间:(单位:秒)
    Gui GetPlayTime:Font, s11, Segoe UI
    Gui GetPlayTime:Add, Edit, x10 y35 w80 h30 center
    Gui GetPlayTime:Add, UpDown, vPlayTime Range0-100
    Gui GetPlayTime:Add, Button, x95 y35 w50 h30 g获取自定义时间, 确定
    Gui GetPlayTime:-Caption AlwaysOnTop Border
    Gui GetPlayTime:Show, x%GetX% y%GetY%
    GuiControl, GetPlayTime:, PlayTime, %PlayTime%
  }
  else {
    PlayTime := % A_ThisMenuItem
    IniWrite, %PlayTime%, 随机打开.ini, Options, PlayTime
    TrayTip 提示, 播放时间已调整为%PlayTime%秒, ,17
  }
return

获取自定义时间:
  Gui, GetPlayTime: Submit
  Gui, GetPlayTime: Destroy
  IniWrite, %PlayTime%, 随机打开.ini, Options, PlayTime
  TrayTip 提示, 播放时间已调整为%PlayTime%秒, ,17
  if RePlay
  Play := 1
return

打开文件路径:
  filepath := % pic[file]
  RunWait, Explorer /select`, %filepath%
return



;Checkbox项目
;*****************************************************************************
;*****************************************************************************
;*****************************************************************************
AutoStartBox1:
  if (FileExist(Startuplnk))
    FileDelete, % Startuplnk
  else
    FileCreateShortcut, % A_ScriptFullpath, % Startuplnk
return

关闭至托盘Box2:
  box2 := !box2
  if box2
    IniWrite, 1, 随机打开.ini, Options, 关闭至托盘
  else 
    IniWrite, 0, 随机打开.ini, Options, 关闭至托盘
return

AskOpenBox3:
  box3 := !box3
  if box3
    IniWrite, 1, 随机打开.ini, Options, 打开文件无需确认
  else
    IniWrite, 0, 随机打开.ini, Options, 打开文件无需确认
return

使用pic控件Box4:
  box4 := !box4
  if box4
    IniWrite, 1, 随机打开.ini, Options, 使用pic控件
  else {
    IniWrite, 0, 随机打开.ini, Options, 使用pic控件
    gosub, PicViewGuiEscape
  }
return



;Gui关闭动作
;*****************************************************************************
;*****************************************************************************
;*****************************************************************************
MainGuiClose:
MainGuiEscape:
  MainView := 0
  WinGetPos, MainX, MainY, , , ahk_id %hWnd%
  IniWrite, %MainX%, 随机打开.ini, Options, MainX
  IniWrite, %MainY%, 随机打开.ini, Options, MainY
  if box2
    Gui, Main: Destroy
  else 
    ExitApp
return
  
Exit:
  ExitApp
return

PicViewGuiEscape:
  Gui, GetPlayTime: Destroy
  Play := 0
  PicView := 0
  SetTimer, ShowPic, Off
  Gui, PicView: Destroy
  TrayTip 提示, 退出Pic控件, ,17
  GuiControl, Main:Text, 图片Button, 图片
return



;托盘相关动作
;*****************************************************************************
;*****************************************************************************
;*****************************************************************************
托盘-打开主窗口:
  if (MainView < 1)
  Gosub, 主界面
  else
  Gui, Main: Show
return

托盘-打开设置:
  if (MainView < 1) {
    Gosub, 主界面
    Gui, Main: +MinimizeBox -MaximizeBox
    Gui, Main: Show, w620 h520, %AppVersion%-设置
    MainView := 2
  } 
  else {
    Gui, Main: Show, w620 h520, %AppVers1ion%-设置
    MainView := 2
  }
  return

托盘-About:
  Run https://www.cnblogs.com/chr2020/p/15171012.html
return



;读取ini配置文件和刷新控件
;*****************************************************************************
;*****************************************************************************
;*****************************************************************************
读取配置:
  IniRead, FirstStartApp, 随机打开.ini, Options, FirstStartApp
  IniRead, MainX, 随机打开.ini, Options, MainX
  IniRead, MainY, 随机打开.ini, Options, MainY
  IniRead, box2, 随机打开.ini, Options, 关闭至托盘
  IniRead, box3, 随机打开.ini, Options, 打开文件无需确认
  IniRead, box4, 随机打开.ini, Options, 使用pic控件
  IniRead, PlayTime, 随机打开.ini, Options, PlayTime
  IniRead, Vext, 随机打开.ini, Section, 视频格式
  IniRead, Pext, 随机打开.ini, Section, 图片格式
  IniRead, Uext, 随机打开.ini, Section, 自定格式
  IniRead, Vpath, 随机打开.ini, Section, 视频路径
  IniRead, Ppath, 随机打开.ini, Section, 图片路径
  IniRead, Upath, 随机打开.ini, Section, 自定路径
return

控件数据刷新:
  gosub, 读取配置
  GuiControl, Main:, Text1, %Vpath%
  GuiControl, Main:, Text2, %Ppath%
  GuiControl, Main:, Text3, %Upath%
  GuiControl, Main:, Edit1, %Vext%
  GuiControl, Main:, Edit2, %Pext%
  GuiControl, Main:, Edit3, %Uext%
return



;函数
;*****************************************************************************
;*****************************************************************************
;*****************************************************************************
路径选择(ext,path,vb){
  FileSelectFolder, WhichFolder, ::{20d04fe0-3aea-1069-a2d8-08002b30309d},,选择路径
  if ErrorLevel
    return
  else {
    MsgBox 4, 提示, 是否保存为默认%vb%?
    IfMsgBox Yes
      IniWrite, %WhichFolder%, 随机打开.ini, Section, %vb%
    Gosub, 控件数据刷新
    随机打开(ext, WhichFolder)
  }
}

路径选择2(path,vb){
  FileSelectFolder, WhichFolder, ::{20d04fe0-3aea-1069-a2d8-08002b30309d},,选择路径
  if ErrorLevel
    return
  else 
    IniWrite, %WhichFolder%, 随机打开.ini, Section, %vb%
}

随机打开(ext,path){
  Loop, parse, ext, `,
  {
    Loop Files, %path%\*.%A_LoopField%, R
    FileList .= A_LoopFilePath "`n"
  }
  Sort, FileList, Random
  loop, Parse, FileList, `n
  {
    if !box3 {
      MsgBox 4, 打开文件?,%A_LoopField%
      IfMsgBox Yes
        Run %A_LoopField%
    }
    else 
      Run %A_LoopField%
    break
  }
}

WindowMove(){
  PostMessage, 0xA1, 2
}

 

声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。