AutoIt3 GUI事件模式 实现字符串大小写转换功能

AutoIT3 10/29 阅读 2164 views次 人气 1
摘要:

AutoIt3的设计用于Windows GUI(图形化用户界面)的自动化操作,AutoIt3具有创建由Windows和控件组成的简单图形用户界面(GUI)的能力,通过消息循环、事件驱动进行控制。

AutoIt3版本:

Version 3.5.4 


AutoIt3 GUI官方介绍:

A GUI consists of one or more windows and each window contains one or more controls. GUIs are "event driven" which means you react to events - like a button that is clicked. You spend most of your time idling and waiting for an event to happen - this is a little different to a normal script where you are in control of what happens and when! Think of it as waiting by the door for the postman - you sit there until a letter pops through the postbox and then you look at the letters and decide what to do with them - this is exactly how GUIs work - you wait for the postman to come to you.


AutoIt3脚本代码:

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

;UGI使用事件模式
Opt("GUIOnEventMode", 1)

;创建一个窗口
Local $window=GUICreate("大小写转-小奋斗", 400, 300)
;绑定事件
GUISetOnEvent($GUI_EVENT_CLOSE, "CloseWindow")
;创建文本域
Local $inputEdit=GUICtrlCreateEdit("", 30,10,340,100)
;创建按钮
Local $transforUpperButton=GUICtrlCreateButton("大写", 100,135,60,25)
Local $transforLowerButton=GUICtrlCreateButton("小写", 170,135,60,25)
Local $clearButton=GUICtrlCreateButton("清除", 240,135,60,25)
;创建文本域
Local $outputEdit=GUICtrlCreateEdit("", 30, 180,340,100)
;事件绑定
GUICtrlSetOnEvent($transforUpperButton, "TransforUpperButton")
GUICtrlSetOnEvent($transforLowerButton, "TransforLowerButton")
GUICtrlSetOnEvent($clearButton, "ClearButton")
;显示当前窗口
GUISetState(@SW_SHOW)

; 消息循环模式
While 1
    Sleep(100);
WEnd

;关闭窗口
func CloseWindow()
   MsgBox($MB_OK, "提示", "您选择了关闭窗口! 正在退出...")
   Exit
EndFunc

;转换成大写
Func TransforUpperButton()
   ; 获取控件内容
   $sourceTxt = GUICtrlRead($inputEdit)
   ; 从控件上修改数据
   GUICtrlSetData($outputEdit,StringUpper($sourceTxt))
EndFunc

;转换成小写
Func TransforLowerButton()
   ; 获取控件内容
   $sourceTxt = GUICtrlRead($inputEdit)
   ; 从控件上修改数据
   GUICtrlSetData($outputEdit,StringLower($sourceTxt))
EndFunc

;转换成小写
Func ClearButton()
   ; 从控件上修改数据
   GUICtrlSetData($inputEdit,"")
   GUICtrlSetData($outputEdit,"")
EndFunc


AutoIt3运行效果:

AutoIt3_GUI_大小写转换.jpg

评论

表情
  1. XfdBoy 把别人想成天使,你就不会遇见魔鬼。

    效果还不错~

    2018/11/01 回复

分享到: