2013年8月27日

on
一、建立第一個表單:
#include <GUIConstantsEx.au3>
GUICreate("Hello World", 200, 100)  ;表單標題名稱Hello World,寬度:200 高度:100
GUISetState(@SW_SHOW) ;顯示表單      
Sleep(2000)       ;停留2秒後關閉

二、建立提示表單:
#include <GUIConstantsEx.au3>
GUICreate("Hello World", 200, 100)
GUICtrlCreateLabel("Hello world! How are you?", 30, 10)
GUICtrlCreateButton("OK", 70, 50, 60)
GUISetState(@SW_SHOW)
Sleep(2000)
三、建立表單的訊息循環模式(MessageLoop Mode):
由於上述表單,僅能停留2秒,若要等使用者使用關閉事件($GUI_EVENT_CLOSE),
才關閉表單,就必須建立此模式。

#include <GUIConstantsEx.au3>
GUICreate("Hello World", 200, 100)
GUICtrlCreateLabel("Hello world! How are you?", 30, 10)
$okbutton = GUICtrlCreateButton("OK", 70, 50, 60)
GUISetState(@SW_SHOW)
While 1
  $msg = GUIGetMsg()
  Select
    Case $msg = $okbutton
      MsgBox(0, "GUI Event", "You pressed OK!")
    Case $msg = $GUI_EVENT_CLOSE
      MsgBox(0, "GUI Event", "You clicked CLOSE! Exiting...")
      ExitLoop
  EndSelect
WEnd
四、進階GUIGetMsg應用:(多重視窗關閉事件之判斷)
#include <GUIConstantsEx.au3>
$mainwindow = GUICreate("Hello World", 200, 100)
GUICtrlCreateLabel("Hello world! How are you?", 30, 10)
$okbutton = GUICtrlCreateButton("OK", 70, 50, 60)
$dummywindow = GUICreate("Dummy window for testing ", 200, 100)
GUISwitch($mainwindow)GUISetState(@SW_SHOW)
While 1
  $msg = GUIGetMsg(1)
  Select
    Case $msg[0] = $okbutton
      MsgBox(0, "GUI Event", "You pressed OK!")
    Case $msg[0] = $GUI_EVENT_CLOSE And $msg[1] = $mainwindow
      MsgBox(0, "GUI Event", "You clicked CLOSE on the main window! Exiting...")
      ExitLoop
  EndSelect
WEnd
五、進階關閉事件處理與多重視窗應用:
#include <GUIConstantsEx.au3>
Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode
$mainwindow = GUICreate("Hello World", 200, 100)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
GUICtrlCreateLabel("Hello world! How are you?", 30, 10)
$okbutton = GUICtrlCreateButton("OK", 70, 50, 60)
GUICtrlSetOnEvent($okbutton, "OKButton")
$dummywindow = GUICreate("Dummy window for testing ", 200, 100)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
GUISwitch($mainwindow)
GUISetState(@SW_SHOW)
While 1
  Sleep(1000)  ; Idle around
WEnd
Func OKButton()
  ;Note: at this point @GUI_CTRLID would equal $okbutton
  MsgBox(0, "GUI Event", "You pressed OK!")
EndFunc
Func CLOSEClicked()
  
;Note: at this point @GUI_CTRLID would equal $GUI_EVENT_CLOSE,
  ;@GUI_WINHANDLE will be either $mainwindow or $dummywindow

  If @GUI_WINHANDLE = $mainwindow Then
    MsgBox(0, "GUI Event", "You clicked CLOSE in the main window! Exiting...")
    Exit
  EndIf
EndFunc

0 意見:

張貼留言

注意:只有此網誌的成員可以留言。