au3全屏置顶显示
#NoTrayIcon
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("", Default, Default, Default, Default, BitOR(0x80000000, 0x1000000),0x8, WinGetHandle(AutoItWinGetTitle()))
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
au3多窗口
#include <GUIConstants.au3>
Opt("GUIOneventMode", 1)
Dim $Button[6]
$WinMain = GUICreate("主窗口", 450, 300) ;创建主窗口
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") ;注册窗口关闭事件到函数_Exit
$Button[0] = GUICtrlCreateButton("显示子窗口 1", 0, 0, 113, 49)
$Button[1] = GUICtrlCreateButton("显示子窗口 2", 216, 0, 105, 49)
$WinSub1 = GUICreate("子窗口", 220, 60) ;创建子窗口1
GUISetOnEvent($GUI_EVENT_CLOSE, "GUICtrlMsg") ;注册窗口关闭事件到函数GUICtrlMsg
$Button[2] = GUICtrlCreateButton("确认", 0, 0, 100, 50)
$Button[3] = GUICtrlCreateButton("取消", 110, 0, 100, 50);创建子窗口中按钮二
$WinSub2 = GUICreate("子窗口", 220, 60) ;创建子窗口2
GUISetOnEvent($GUI_EVENT_CLOSE, "GUICtrlMsg") ;注册窗口关闭事件到函数GUICtrlMsg
$Button[4] = GUICtrlCreateButton("确认", 0, 0, 100, 50)
$Button[5] = GUICtrlCreateButton("取消", 110, 0, 100, 50);创建子窗口中按钮二
For $I = 5 To 0 Step -1
GUICtrlSetOnEvent($Button[$I], "GUICtrlMsg") ;注册总共的六个按钮点击事件到函数 GUICtrlMsg
;请区分 GUISetOnEvent 和 GUICtrlSetOnEvent的区别
Next
GUISwitch($WinMain) ;切换当前窗口到主窗口
GUISetState(@SW_SHOW) ;显示当前窗口
While 1
Sleep(1000)
WEnd
Func GUICtrlMsg()
Switch @GUI_CtrlId;选择事件 ID 或 控件 ID
Case $GUI_EVENT_CLOSE;如果点下的是$GUI_EVENT_CLOSE(关闭)
GUISetState(@SW_HIDE, @GUI_WinHandle); 隐藏产生事件的窗口
Case $Button[0]
GUISetState(@SW_SHOW, $WinSub1); 显示 子窗口 1
Case $Button[1]
GUISetState(@SW_SHOW, $WinSub2); 显示 子窗口 2
Case $Button[2]
MsgBox(48, 0, "你点了子窗口 1 中的第一个按钮")
Case $Button[3]
GUISetState(@SW_HIDE, $WinSub1); 隐藏 子窗口 1
Case $Button[4]
MsgBox(48, 0, "你点了主窗口 2 中的第一个按钮")
Case $Button[5]
GUISetState(@SW_HIDE, $WinSub2); 隐藏 子窗口 2
EndSwitch
EndFunc ;==>GUICtrlMsg
Func _Exit()
Exit
EndFunc ;==>_Exit
一个简单的gui窗口及按键触发
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <DateTimeConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 311, 288, 400, 173)
$MenuItem1 = GUICtrlCreateMenu("菜单")
$MenuItem4 = GUICtrlCreateMenuItem("unlock", $MenuItem1)
$MenuItem3 = GUICtrlCreateMenuItem("advance", $MenuItem1)
$MenuItem2 = GUICtrlCreateMenu("About")
$CardNo = GUICtrlCreateLabel("CardNo", 32, 16, 40, 17)
$Input1 = GUICtrlCreateInput("1111111", 32, 32, 97, 21)
$FixCard = GUICtrlCreateButton("FixCard", 200, 80, 81, 25)
GUICtrlCreateGroup("", 16, 0, 273, 121)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Danger = GUICtrlCreateGroup("Danger", 16, 144, 273, 105)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Label1 = GUICtrlCreateLabel("degree", 32, 64, 60, 17)
$Input3 = GUICtrlCreateInput("0", 32, 80, 97, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_PASSWORD))
$CardDEG = GUICtrlCreateLabel("CardDEG", 201, 13, 49, 17)
$Combo1 = GUICtrlCreateCombo("1", 200, 32, 81, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
$x=32
$w=65
$y=160
$h=17
$none = GUICtrlCreateRadio("none", $x, $y, $w, $h)
GUICtrlSetState(-1, $GUI_CHECKED)
$a = GUICtrlCreateRadio("turn_A", $x+80, $y, $w, $h)
$b = GUICtrlCreateRadio("turn_B", $x, $y+20, $w+20, $h)
$n = GUICtrlCreateDate("", 208, 168, 65, 17, $DTS_TIMEFORMAT)
;$Date1 = GUICtrlCreateDate("2014/03/27 22:55:22", 208, 168, 65, 17)
$Input2 = GUICtrlCreateInput("Input2", 112, 208, 81, 21)
$Update = GUICtrlCreateButton("Update", 208, 208, 73, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Update
MsgBox(0,"提示","成功进入更新!")
EndSwitch
WEnd
#cs
Func Example4()
Local $n, $msg
GUICreate("My GUI get time", 200, 200, 800, 200)
$n = GUICtrlCreateDate("", 20, 20, 100, 20, $DTS_TIMEFORMAT)
GUISetState()
; 运行界面,直到窗口被关闭
Do
$msg = GUIGetMsg()
Until $msg = $GUI_EVENT_CLOSE
MsgBox(0, "Time", GUICtrlRead($n))
GUIDelete()
EndFunc ;==>Example4
#ce
鼠标按键动作及位置
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $GUI_EVENT_PRIMARYDOWN ;发生鼠标按下动作!
$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=0
EndIf
Case $GUI_EVENT_PRIMARYUP ;鼠标松开事件
$no_action=1
$pos = MouseGetPos()
$X2=$POS[0]
$Y2=$POS[1]
If $X1=0 Then
$X1=$X2
ENDIF
; 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-1
If $PIC_NUM<=0 Then
$PIC_NUM=$pic_max
ENDIF
$pic_num=find_num_minus($pic_num, $pic_max, "图片"&$button_current)
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+1
If $PIC_NUM>$pic_max Then
$PIC_NUM=1
ENDIF
$pic_num=find_num($pic_num, $pic_max, "图片"&$button_current)
GUICtrlSetImage($Pic1, "图片"&$button_current&"\"&$PIC_NUM&".jpg")
ENDIF
$cishu=0
Case $BUTTON1
Case Else
EndSwitch
WEnd
au3程序输入正确密码才可进入
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstants.au3>
;#include<onekeysql.au3>
$y = Random(17, 99, 1) & Random(211, 799, 1)
$y = StringMid($y, 1, 4)
MsgBox(0, "解锁密码", encrypt_dat($y))
confi_pass()
Func confi_pass()
;$Form1 = GUICreate("Form1", 621, 444, 292, 135)
$Form1 = GUICreate("程序校验", 290, 200)
$Group1 = GUICtrlCreateGroup("", 60, 20, 160, 35)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateLabel("Serious: ", 95, 35, 45, 17)
GUICtrlSetTip(-1, "5")
$Serious_code = GUICtrlCreateLabel("8888", 150, 35, 45, 17)
GUICtrlSetData($Serious_code, $y)
GUICtrlSetTip(-1, "5")
$Group1 = GUICtrlCreateGroup("请输入启动密码:", 60, 70, 160, 51)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Input1 = GUICtrlCreateInput("", 65, 90, 150, 25)
$Button1 = GUICtrlCreateButton("确定", 60, 130, 160, 35)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
$right_pass = encrypt_dat($y)
$pass = GUICtrlRead($Input1)
If $pass = $right_pass Then
GUISetState(@SW_HIDE, $Form1)
main_view()
;调用主窗口
Else
MsgBox(0, "警告", "密码错误!")
EndIf
Exit
;Exit
EndSwitch
WEnd
EndFunc ;==>confi_pass
Func encrypt_dat($seri)
Local $x = @MDAY
;Local $x1 = 3 ^ (@MDAY + 1)
;While $x1 < 1000000
; $x1 = $x1 ^ 2
;WEnd
;$x1 = StringMid($x1, 3, 4)
; $x1 = $x1* $seri*(Mod($seri,1000)+1)
;MsgBox (4096,"mima",$x1)
;$x = StringMid($x1, 2, 1) & StringMid($x1, 4, 5)
; $x=Mod($x1,1000000)
;MsgBox (4096,"mima",$x)
$seri = $seri * ($seri + 1)
$x = $x * $seri + 579327
$x = Mod($x, 1000000)
Return $x
EndFunc ;==>encrypt_dat
Func main_view()
MsgBox(0,"提示","成功进入测试模式!")
EndFunc
窗口抖动
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("错误提示", 500, 400,-1,-1,$WS_BORDER)
WinSetOnTop("错误提示","",1)
$Input1 = GUICtrlCreateInput("Input1", 240, 240, 161, 45)
GUICtrlSetLimit(-1, 10)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
$Label1 = GUICtrlCreateLabel("单号", 100, 240, 120, 40)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlCreateLabel("50=90(电子券)", 100, 5, 400, 41)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("请保留【会员卡】", 100, 50, 400, 41)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
$button_sure=GUICtrlCreateButton("关闭",200,320,100,40)
$Label3 = GUICtrlCreateLabel("该会员不享有"&@CRLF&"福利 请联系客服", 100, 104, 307, 125)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, 0xFF0000)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
_Jitter()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $button_sure
exit
EndSwitch
WEnd
Func _Jitter()
$sCoor = WinGetPos($form1)
For $i = 1 To 4
WinMove($form1, "", $sCoor[0] + 3, $sCoor[1] - 3, Default, Default, 1)
WinMove($form1, "", $sCoor[0], $sCoor[1] - 6, Default, Default, 1)
WinMove($form1, "", $sCoor[0] - 3, $sCoor[1] - 3, Default, Default, 1)
WinMove($form1, "", $sCoor[0], $sCoor[1], Default, Default, 1)
Next
EndFunc ;==>_Jitter
进度条
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
_gui_child(100)
;GUIDelete($hGui_child)
Func _gui_child($i)
Local $hGui_child, $msg
Local $bt_back, $input
; $hGui_child = GUICreate('child gui', 300, 100)
$hGui_child = GUICreate("正在查询...", 260, 30,-1,-1, $WS_POPUP, -1)
GUICtrlCreateLabel("请稍后...",1,10,60,20)
$process=GUICtrlCreateProgress(60,5,200,20)
GUISetState()
Do
For $time=1 To $i Step Random(1, 6, 1)
GUICtrlSetData($process, $time)
Sleep(200)
next
Until $i=100
GUIDelete($hGui_child)
EndFunc
au3最小化到托盘,托盘菜单
#include <Constants.au3>
#include <GUIConstantsEx.au3>
Opt('TrayIconHide', 1)
Opt('TrayOnEventMode', 1)
Opt('TrayMenuMode', 1 + 2)
$MyGui1 = GUICreate('托盘菜单例子', 400, 300)
$TrayMenu1 = TrayCreateItem('菜单1')
TrayItemSetOnEvent(-1, 'TrayMenuEvent')
$TrayMenu2 = TrayCreateItem('菜单2')
TrayItemSetOnEvent(-1, 'TrayMenuEvent')
$TrayMenu3 = TrayCreateItem('菜单3')
TrayItemSetOnEvent(-1, 'TrayMenuEvent')
$TrayMenuExit = TrayCreateItem('退出')
TrayItemSetOnEvent(-1, 'TrayMenuEvent')
TraySetClick(8)
GUISetState()
TraySetOnEvent($TRAY_EVENT_PRIMARYUP, 'TrayEvent')
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3
Exit
Case $GUI_EVENT_MINIMIZE
GUISetState(@SW_HIDE, $MyGui1)
Opt('TrayIconHide', 0)
TrayTip('程序最小化到托盘!', '鼠标左键点击托盘图标可恢复程序界面' & @CRLF & '鼠标右键点击托盘图标可弹出右键菜单', 3)
EndSwitch
WEnd
Func TrayEvent()
Opt('TrayIconHide', 1)
GUISetState(@SW_SHOW, $MyGui1)
WinActivate($MyGui1)
EndFunc ;==>TrayEvent
Func TrayMenuEvent()
Switch @TRAY_ID
Case $TrayMenu1
MsgBox(0, '托盘菜单控件标识符 = ' & @TRAY_ID, '托盘菜单1')
Case $TrayMenu2
MsgBox(0, '托盘菜单控件标识符 = ' & @TRAY_ID, '托盘菜单2')
Case $TrayMenu3
MsgBox(0, '托盘菜单控件标识符 = ' & @TRAY_ID, '托盘菜单3')
Case $TrayMenuExit
Exit
EndSwitch
EndFunc ;==>TrayMenuEvent
au3右键菜单
#include <GUIListBox.au3>
#include <GUIListView.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
GUICreate("右键菜单测试", 400, 350)
$hListView = GUICtrlCreateListView(" 代码测试 ",10, 10, 380, 200,-1, BitOR($WS_EX_CLIENTEDGE,$LVS_EX_FULLROWSELECT,$LVS_REPORT))
$zhucaidan = GUICtrlCreateContextMenu($hListView)
$tianjia = GUICtrlCreateMenuItem("添加数据 ", $zhucaidan)
$shanchu = GUICtrlCreateMenuItem("删除数据", $zhucaidan)
$shuaxin = GUICtrlCreateMenuItem("修改数据", $zhucaidan)
$sousuo = GUICtrlCreateMenuItem("搜索数据", $zhucaidan)
GUICtrlCreateMenuItem("", $zhucaidan)
$pailie = GUICtrlCreateMenu("排列方式", $zhucaidan)
$plshijian = GUICtrlCreateMenuItem("录入时间", $pailie)
$plriqi = GUICtrlCreateMenuItem("销售日期", $pailie)
$fileitem = GUICtrlCreateMenuItem("控制面板", $zhucaidan)
GUICtrlCreateMenuItem("", $zhucaidan)
$infoitem = GUICtrlCreateMenuItem("关闭程序", $zhucaidan)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
case $fileitem
MsgBox(0,0,"kongzhimianban")
EndSwitch
WEnd
au3回车热键触发
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Process.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 386, 210, 192, 124)
$Input1 = GUICtrlCreateInput("Input1", 40, 72, 305, 28)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$OK = GUICtrlCreateButton("Submit", 32, 120, 145, 41)
$NO = GUICtrlCreateButton("Exit", 192, 120, 145, 41)
$Thanks = GUICtrlCreateLabel("Thanks for coming back.", 40, 24, 309, 42)
GUICtrlSetFont(-1, 20, 400, 0, "Comic Sans MS")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Dim $AccelKeys[2][2]=[["{Enter}", $Input1], ["{Enter}", $Input1]]
GUISetAccelerators($AccelKeys)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $OK
MsgBox(1,"OK",GUICtrlRead($Input1))
Case $NO
Exit
Case $Input1
MsgBox(1,"OK",GUICtrlRead($Input1))
EndSwitch
WEnd
最后编辑: admin 文档更新时间: 2021-03-16 21:53 作者:admin