本篇目录
这是很早之前完成的一个小程序,利用au3实现了图片的自动轮播,在图片自动轮播的过程中也可以使用鼠标或触屏左右滑动进行图片的切换。支持多个分类栏目,可用于广告轮播机展示广告图片。
因为是很久之前写的代码了,在这里将源码免费公布出来。共有三个au3源文件。
图片目录结构如下:


file_find.au3
;$return = find_num(5, 9, "图片3");MsgBox(0, "", "fanhuizhi: " & $return)Func find_num($start, $end, $file_way) ;假设find_num(5,9,"xxxx") 则搜索范围包含5和9本身$pic_num = $start$pic_max = $end;;///////////////////查询第一个符合要求的文件For $i = 1 To $pic_max Step 1If FileExists($file_way & "" & $i & ".jpg") ThenExitLoopElse;MsgBox(0,"","循环中的"&$i)EndIfNextIf $i > $pic_max ThenMsgBox(0, "", "图片目录不存在,或该目录下不存在符合命名要求的jpg文件!")FileCopy("图片1默认.jpg", $file_way&"1.jpg", 9)ExitElse$exit_one = $i;MsgBox(0,"","第一个存在的文件已找到"&$file_way&""&$i&".jpg")EndIf;;///////////////////查询第一个符合要求的文件;;//开始按预定值查找下一个符合条件的文件For $i = $pic_num To $pic_max Step 1If FileExists($file_way & "" & $i & ".jpg") Then;MsgBox(0,"C:autoexec.bat 文件", "图片1"&$i&".jpg");MsgBox(0, "", $file_way & "" & $i & ".jpg")ExitLoopElse;MsgBox(0,"","循环中的"&$i)EndIfNextIf $i > $pic_max Then;MsgBox(0, "", "没有找到该文件!")$i = $exit_oneElse;MsgBox(0, "", "已找到" & $file_way & "" & $i & ".jpg")EndIfReturn $iEndFunc ;==>find_num
file_find_minus.au3
;$return = find_num(5, 9, "图片3");$pic_num=find_num_minus(11, 9, "图片13"); 三个参数,第一个为当前序号,第二个为最大的序号,第三个为路径!;MsgBox(0, "", "fanhuizhi: " & $pic_num)Func find_num_minus($start, $end, $file_way) ;假设find_num(5,9,"xxxx") 则搜索范围包含5和9本身$pic_num = $start$pic_max = $end;;//开始按预定值查找下一个符合条件的文件;For $i = $pic_max To $pic_num Step -1For $i = $pic_max To 1 Step -1If FileExists($file_way & "" & $i & ".jpg") Then;MsgBox(0,"C:autoexec.bat 文件", "图片1"&$i&".jpg");MsgBox(0, "", $file_way & "" & $i & ".jpg")ExitLoopElse;MsgBox(0,"","循环中的"&$i)EndIfNextIf $i < 1 ThenMsgBox(0, "", "图片目录不存在,或该目录下不存在符合命名要求的jpg文件!");DirCreate($file_way)FileCopy("图片1默认.jpg", $file_way&"1.jpg", 9)exitElse$exit_one=$i;MsgBox(0, "", "已找到" & $file_way & "" & $i & ".jpg");MsgBox(0,"","diyici"&$i)EndIf;MsgBox(0,"","xxxxxxxxxxxx");;///////////////////查询第一个符合要求的文件;For $i = $pic_num To 1 Step -1For $i = $pic_num To 1 Step -1If FileExists($file_way & "" & $i & ".jpg") ThenExitLoopElse;MsgBox(0,"","循环中的"&$i)EndIfNextIf $i < 1 Then;MsgBox(0, "", "符合命名规则的文件不存在!");Exit$i=$exit_oneElse;MsgBox(0,"","第一个存在的文件已找到"&$file_way&""&$i&".jpg")EndIf;;///////////////////查询第一个符合要求的文件Return $iEndFunc ;==>find_num
main.au3 主程序
#NoTrayIcon#Region ;**** 参数创建于 ACNWrapper_GUI ****#AutoIt3Wrapper_Outfile=64自动超时换_自定义_LISTVIEW.exe#AutoIt3Wrapper_UseUpx=n#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****#Include <WinAPI.au3>#include <EditConstants.au3>#include <GUIConstantsEx.au3>#include <StaticConstants.au3>#include <WindowsConstants.au3>#include <GuiButton.au3>;#include<tooltip.au3>#include<file_find.au3>#include<file_find_minus.au3>#Region ### START Koda GUI section ### Form=;Opt("GUICloseOnESC", 0);Dim $button[]$PIC_NUM=0 ;初始$pic_num, 程序运行中$pic_num表示当前需要显示的图片序号$pic_max=9 ;定义最大的图片数量,建议不要超过9张$time_out=10 ;无操作10秒后自动切换$time_auto=3 ;每3秒自动切换$pic_class=9 ;总的分类个数,最大不要超过9个$cishu=1 ;记时单位!!!!!$no_action=0 ;判定鼠标操作,有鼠标事件则置1, 超过指定时间后置0$button_current=1 ;从0分类开始,程序运行过程中用来确定是第几个分类If $pic_class>10 Then ;分类大于9则置9$pic_class=10EndIf;MsgBox(0,0,"class"&$pic_class)DirCreate("图片1") ;创建最基本的分类FileInstall("图片1默认.jpg","图片1默认.jpg",1) ;提示图片,表示没有放置正确图片!;;;;;;控件 大小数据设置==============================$xi=@DesktopWidth-250$xi=@DesktopWidth-Int(@DesktopWidth/7)-20$yi0=Int(@DesktopHeight/25) ;$yi0=50$yi1=Int(@DesktopHeight/18)+5 ;$yi1=65 ;设置相邻两个按钮之间的距离$high=Int(@DesktopHeight/18) ;$high=60$width=Int(@DesktopWidth/7) ;$width=240$Form1 = GUICreate("", Default, Default, Default, Default, BitOR(0x80000000, 0x1000000),0x8, WinGetHandle(AutoItWinGetTitle()))GUISetBkColor(0x81A0CE);$Form1 = GUICreate("", Default, Default, Default, Default, BitOR(0x80000000, 0x1000000),0x8);$GROUP1=GUICtrlCreateGroup("展示区域",1,1,@DesktopWidth-300, @DesktopHeight-10)$GROUP1=GUICtrlCreateGroup("展示区域",1,1,Int(@DesktopWidth*0.82)+10, @DesktopHeight-4);GUICtrlCreatePic("9,jpg", @DesktopWidth-220, @DesktopHeight-200, 200,100)$asd1=GUICtrlCreatepic("1,jpg", @DesktopWidth-220, @DesktopHeight-200, 200,100);GUICtrlSetState($button9,$GUI_HIDE)$pic_num=find_num_minus($pic_max, $pic_max, "图片"&$button_current) ;设置默认图片序号从最大的开始;$Pic1 = GUICtrlCreatePic("图片"&$button_current&""&$pic_num&".jpg", 6, 16, @DesktopWidth-310, @DesktopHeight-30)$Pic1 = GUICtrlCreatePic("图片"&$button_current&""&$pic_num&".jpg", 6, 16, Int(@DesktopWidth*0.82), @DesktopHeight-22);$Pic1 = GUICtrlCreatePic("图片11.jpg", $group1)$GROUP2=GUICtrlCreateGroup("分类选择",$xi-4,Int(@DesktopHeight/40),$width+8, $yi0+$yi1*$pic_class-Int(@DesktopHeight/40));$Label0 = GUICtrlCreateLabel("分类选择", $xi, 10, 100, 20) ;显示当前分类(按钮)序号$Label1 = GUICtrlCreateLabel("xuhao", @DesktopWidth-50, @DesktopHeight-20, 40, 10) ;显示当前分类(按钮)序号$Label2 = GUICtrlCreateLabel("kongzhi", @DesktopWidth-100, @DesktopHeight-20, 40, 10) ;显示 时间超时 控制阀$Label3 = GUICtrlCreateLabel("time", $xi, @DesktopHeight-40, 200, 20) ;显示 时间;$button_exit=GUICtrlCreatepic("退出",$xi,@DesktopHeight-100,$width,$high);$button1=GUICtrlCreateButton("button1",1400,500,200,50);$pic1=GUICtrlCreatePic("1.jpg",0,0, 169,68);#cs$button1=GUICtrlCreatePic("1.jpg",$xi,$yi0+$yi1*0,$width,$high)GUICtrlSetState($button1,$GUI_HIDE)$button2=GUICtrlCreatePic("2.jpg",$xi,$yi0+$yi1*1,$width,$high)GUICtrlSetState($button2,$GUI_HIDE)$button3=GUICtrlCreatePic("3.jpg",$xi,$yi0+$yi1*2,$width,$high)GUICtrlSetState($button3,$GUI_HIDE)$button4=GUICtrlCreatePic("4.jpg",$xi,$yi0+$yi1*3,$width,$high)GUICtrlSetState($button4,$GUI_HIDE)$button5=GUICtrlCreatePic("5.jpg",$xi,$yi0+$yi1*4,$width,$high)GUICtrlSetState($button5,$GUI_HIDE)$button6=GUICtrlCreatePic("6.jpg",$xi,$yi0+$yi1*5,$width,$high)GUICtrlSetState($button6,$GUI_HIDE)$button7=GUICtrlCreatePic("7.jpg",$xi,$yi0+$yi1*6,$width,$high)GUICtrlSetState($button7,$GUI_HIDE)$button8=GUICtrlCreatePic("8.jpg",$xi,$yi0+$yi1*7,$width,$high)GUICtrlSetState($button8,$GUI_HIDE)$button9=GUICtrlCreatePic("9.jpg",$xi,$yi0+$yi1*8,$width,$high)GUICtrlSetState($button9,$GUI_HIDE)$button10=GUICtrlCreatePic("10.jpg",$xi,$yi0+$yi1*9,$width,$high)GUICtrlSetState($button10,$GUI_HIDE);#ce;$button9=GUICtrlCreateButton("button9",$xi,$yi0+$yi1*8,$width,$high); GUICtrlSetState($button9,$GUI_HIDE)_check_pic_class($pic_class) ;检查分类目录是否存在GUISetState(@SW_SHOW)#EndRegion ### END Koda GUI section ###$x1=0$y1=0While 1;GUICtrlSetData($Label3,@YEAR&"年"&@MON&"月"&@MDAY&"日 "&@HOUR&":"&@MIN&":"&@SEC)If $cishu<=200 Then$TIME1=@HOUR&@MIN&@SEC$pos1 = MouseGetPos()$X_start=$POS1[0]$Y_start=$POS1[1]$time2=$TIME1EndIfIf $CISHU>=350 Then$TIME2=@HOUR&@MIN&@SEC$pos1 = MouseGetPos()$X_end=$POS1[0]$Y_end=$POS1[1]EndIfIf $no_action=0 And $TIME2-$TIME1>$time_auto then ;action=0表示没有鼠标事件, 无操作time_auto秒开始切换If $pic_num<$PIC_max then$pic_num=$pic_num+1Else$pic_num=1EndIf$pic_num=find_num($pic_num, $pic_max, "图片"&$button_current);MsgBox(0,0,"自动超过时间换图")GUICtrlSetImage($Pic1, "图片"&$button_current&""&$PIC_NUM&".jpg");Sleep(3000)$cishu=0ElseIf $no_action=1 And $TIME2-$TIME1>$time_out Then ;有操作后,延时$time_out秒开始切换If $pic_num<$pic_max then$pic_num=$pic_num+1Else$pic_num=1EndIf$pic_num=find_num($pic_num, $pic_max, "图片"&$button_current);MsgBox(0,0,"无操作超过时间换图")GUICtrlSetImage($Pic1, "图片"&$button_current&""&$PIC_NUM&".jpg");Sleep(3000)$cishu=0$no_action=0EndIf$cishu=$cishu+1GUICtrlSetData($Label1,"-"&$cishu)GUICtrlSetData($Label2,"&"&$button_current)GUICtrlSetData($Label3,@YEAR&"年"&@MON&"月"&@MDAY&"日 "&@HOUR&":"&@MIN&":"&@SEC);以下是判断鼠标操作$nMsg = GUIGetMsg()Switch $nMsgCase $GUI_EVENT_CLOSE$passwd = InputBox("EXIT", "输入密码退出! 初始密码:123456", "", "*")If $passwd=123456 ThenExitENDIF;ExitCase $GUI_EVENT_PRIMARYDOWN$no_action=1$cishu=0$Pos = GUIGetCursorInfo($Form1);$pos1 = MouseGetPos()If $Pos[4] = $Pic1 Then ;判断鼠标点下区域$pos1 = MouseGetPos()$X1=$POS1[0]$Y1=$POS1[1];GUICtrlSetData($Input1, $PIC_NUM,0);MsgBox(0,0,"点击了 Input"); GUICtrlSetData($input_x1,"x1:"&$X1)Else$x1=0$y1=0EndIfCase $GUI_EVENT_PRIMARYUP ;鼠标松开事件$no_action=1$pos = MouseGetPos()$X2=$POS[0]$Y2=$POS[1]If $X1=0 Then$X1=$X2ENDIF; GUICtrlSetData($input_x2,"x2:"&$X2);if 位置有效区间If $X2-$X1>10 And $X2-$X1<2000 And $y2-$y1<200 And $y2-$y1>-200 Then ;位置移动有效区间$PIC_NUM=$PIC_NUM-1If $PIC_NUM<=0 Then$PIC_NUM=$pic_maxENDIF$pic_num=find_num_minus($pic_num, $pic_max, "图片"&$button_current);MsgBox(0,0,"向右换图换图")GUICtrlSetImage($Pic1, "图片"&$button_current&""&$PIC_NUM&".jpg")ElseIf $X2-$X1<-10 And $X2-$X1>-2000 And $y2-$y1<200 And $y2-$y1>-200 THEN$PIC_NUM=$PIC_NUM+1If $PIC_NUM>$pic_max Then$PIC_NUM=1ENDIF$pic_num=find_num($pic_num, $pic_max, "图片"&$button_current)GUICtrlSetImage($Pic1, "图片"&$button_current&""&$PIC_NUM&".jpg");MsgBox(0,0,"向左换换图")Else$Pos2 = GUIGetCursorInfo($Form1);$pos1 = MouseGetPos()If $Pos2[4] = $Pic1 Then ;判断鼠标点下区域$pos2 = MouseGetPos()$X_m=$POS2[0]$Y_m=$POS2[1]SplashTextOn("", "左右滑动可选择不同礼品哦~",250,38,$x_m,$y_m,1)Sleep(400)SplashOff(); GUICtrlSetTip($Pic1, '这是一段提示信息');3 _tooltip()EndIf;If $x1=0 And $y1=0 then; EndIfENDIF$cishu=0Case $BUTTON1$button_current=1$pic_num=find_num(1, $pic_max, "图片1"); MsgBox(0,0,"GUICtrlSetImage($Pic1,'图片'"&$button_current&""&$PIC_NUM&".jpg")GUICtrlSetImage($Pic1, "图片"&$button_current&""&$PIC_NUM&".jpg");GUICtrlSetImage($Pic1, "图片"&$button_current&"1.jpg")$pic_num=1Case $BUTTON2$button_current=2$pic_num=find_num(1, $pic_max, "图片2"); MsgBox(0,0,"GUICtrlSetImage($Pic1,'图片'"&$button_current&""&$PIC_NUM&".jpg")GUICtrlSetImage($Pic1, "图片"&$button_current&""&$PIC_NUM&".jpg");GUICtrlSetImage($Pic1, "图片"&$button_current&"1.jpg")$pic_num=1Case $BUTTON3$button_current=3$pic_num=find_num(1, $pic_max, "图片3"); MsgBox(0,0,"GUICtrlSetImage($Pic1,'图片'"&$button_current&""&$PIC_NUM&".jpg")GUICtrlSetImage($Pic1, "图片"&$button_current&""&$PIC_NUM&".jpg"); GUICtrlSetImage($Pic1, "图片"&$button_current&"1.jpg")$pic_num=1Case $BUTTON4$button_current=4$pic_num=find_num(1, $pic_max, "图片4"); MsgBox(0,0,"GUICtrlSetImage($Pic1,'图片'"&$button_current&""&$PIC_NUM&".jpg")GUICtrlSetImage($Pic1, "图片"&$button_current&""&$PIC_NUM&".jpg");GUICtrlSetImage($Pic1, "图片"&$button_current&"1.jpg")$pic_num=1Case $BUTTON5$button_current=5$pic_num=find_num(1, $pic_max, "图片5"); MsgBox(0,0,"GUICtrlSetImage($Pic1,'图片'"&$button_current&""&$PIC_NUM&".jpg")GUICtrlSetImage($Pic1, "图片"&$button_current&""&$PIC_NUM&".jpg");GUICtrlSetImage($Pic1, "图片"&$button_current&"1.jpg")$pic_num=1Case $BUTTON6$button_current=6$pic_num=find_num(1, $pic_max, "图片6"); MsgBox(0,0,"GUICtrlSetImage($Pic1,'图片'"&$button_current&""&$PIC_NUM&".jpg")GUICtrlSetImage($Pic1, "图片"&$button_current&""&$PIC_NUM&".jpg");GUICtrlSetImage($Pic1, "图片"&$button_current&"1.jpg")$pic_num=1Case $BUTTON7$button_current=7$pic_num=find_num(1, $pic_max, "图片7"); MsgBox(0,0,"GUICtrlSetImage($Pic1,'图片'"&$button_current&""&$PIC_NUM&".jpg")GUICtrlSetImage($Pic1, "图片"&$button_current&""&$PIC_NUM&".jpg");GUICtrlSetImage($Pic1, "图片"&$button_current&"1.jpg")$pic_num=1Case $BUTTON8$button_current=8$pic_num=find_num(1, $pic_max, "图片8"); MsgBox(0,0,"GUICtrlSetImage($Pic1,'图片'"&$button_current&""&$PIC_NUM&".jpg")GUICtrlSetImage($Pic1, "图片"&$button_current&""&$PIC_NUM&".jpg"); GUICtrlSetImage($Pic1, "图片"&$button_current&"1.jpg")$pic_num=1Case $BUTTON9$button_current=9$pic_num=find_num(1, $pic_max, "图片9"); MsgBox(0,0,"GUICtrlSetImage($Pic1,'图片'"&$button_current&""&$PIC_NUM&".jpg")GUICtrlSetImage($Pic1, "图片"&$button_current&""&$PIC_NUM&".jpg"); GUICtrlSetImage($Pic1, "图片"&$button_current&"1.jpg")$pic_num=1; Case $button10; $button_current=10; $pic_num=find_num(1, $pic_max, "图片10");MsgBox(0,0,"GUICtrlSetImage($Pic1,'图片'"&$button_current&""&$PIC_NUM&".jpg"); GUICtrlSetImage($Pic1, "图片"&$button_current&""&$PIC_NUM&".jpg");GUICtrlSetImage($Pic1, "图片"&$button_current&"1.jpg"); $pic_num=1; Case $pic_exit; GUICtrlSetImage($pic_exit, "XX.jpg"); Sleep (500);MsgBox(0,0,"asdasdas"); exit;Case $button_exit; ExitCase ElseEndSwitchWEndFunc _check_pic_class($pic_class)If $pic_class>=1 Then;$button1=GUICtrlCreateButton("button1",1400,100,200,50)GUICtrlSetState($button1,$GUI_show)$pic_num=find_num_minus(1, $pic_max, "图片1")EndIfIf $pic_class>=2 then;$button2=GUICtrlCreateButton("button2",1400,160,200,50)GUICtrlSetState($button2,$GUI_show)$pic_num=find_num_minus(1, $pic_max, "图片2")EndIfif $pic_class>=3 Then;$button3=GUICtrlCreateButton("button3",1400,220,200,50)GUICtrlSetState($button3,$GUI_show);If Not FileExists("图片31.jpg") Then;MsgBox(0,"","文件夹[图片3]不存在,或图片[1.jpg]不存在!");Exit;endif$pic_num=find_num_minus(1, $pic_max, "图片3")EndIfIf $pic_class>=4 Then;$button4=GUICtrlCreateButton("button4",1400,280,200,50)GUICtrlSetState($button4,$GUI_show)$pic_num=find_num_minus(1, $pic_max, "图片4")EndIfIf $pic_class>=5 Then;$button5=GUICtrlCreateButton("button5",1400,340,200,50)GUICtrlSetState($button5,$GUI_show)$pic_num=find_num_minus(1, $pic_max, "图片5")EndIfIf $pic_class>=6 Then;$button6=GUICtrlCreateButton("button6",1400,400,200,50)GUICtrlSetState($button6,$GUI_show)$pic_num=find_num_minus(1, $pic_max, "图片6")EndIfIf $pic_class>=7 Then;$button7=GUICtrlCreateButton("button7",1400,460,200,50)GUICtrlSetState($button7,$GUI_show)$pic_num=find_num_minus(1, $pic_max, "图片7")EndIfIf $pic_class>=8 Then;$button8=GUICtrlCreateButton("button8",1400,520,200,50)GUICtrlSetState($button8,$GUI_show)$pic_num=find_num_minus(1, $pic_max, "图片8")EndIfIf $pic_class>=9 Then;$button9=GUICtrlCreateButton("button9",1400,580,200,50)GUICtrlSetState($button9,$GUI_show)$pic_num=find_num_minus(1, $pic_max, "图片9")EndIfIf $pic_class>=10 Then;$button9=GUICtrlCreateButton("button9",1400,580,200,50)GUICtrlSetState($button10,$GUI_show)$pic_num=find_num_minus(1, $pic_max, "图片10")EndIfEndFunc
最终效果见下图,没有做界面优化。经测试该au3代码在触屏windows10上也可运行,注意管理员权限。

发表评论