#include <EditConstants.au3>
#include <WinAPI.au3> ; used for Lo/Hi word
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
Global Const $GUI_ENVET_CLOSE = -3
Opt("GUIOnEventMode", 1)
Opt("MustDeclareVars", 1)
Local $Gui = GUICreate("简易计算器", 450, 100)
Local $y = "|+|-|*|/|"
Local $Input1 = GUICtrlCreateInput("", 30, 30, 50, 20)
Local $Combo = GUICtrlCreateCombo("", 90, 30, 50, 20, -1, -1)
Local $Input2 = GUICtrlCreateInput("", 150, 30, 50, 20)
Local $Button = GUICtrlCreateButton("=", 210, 30, 50, 20)
Local $Text = GUICtrlCreateEdit("", 270, 30, 150, 20)
GUICtrlSetData($Combo, $y,"+")
GUISetOnEvent($GUI_ENVET_CLOSE, "main")
GUICtrlSetOnEvent($Input1, "main")
GUICtrlSetOnEvent($Input2, "main")
GUICtrlSetOnEvent($Button, "main")
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
While 1
GUISetBkColor(RandomColor())
Sleep(3000)
WEnd
Func main()
Local $n1 = GUICtrlRead($Input1)
Local $n2 = GUICtrlRead($Input2)
Local $x = GUICtrlRead($Combo)
Switch @GUI_CtrlId
Case $Button
GUICtrlSetData($Text, Execute($n1&$x&$n2))
Case $GUI_ENVET_CLOSE
Exit
EndSwitch
EndFunc ;==>main
Func RandomColor()
Local $temp = "0x"
Return $temp & Hex(Random(0, 255, 1), 2) & Hex(Random(0, 255, 1), 2) & Hex(Random(0, 255, 1), 2)
EndFunc ;==>RandomColor
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg
Local $hWndFrom, $iIDFrom, $iCode, $hWndEdit, $hWndEdit1, $a
If Not IsHWnd($Input1) Then $hWndEdit = GUICtrlGetHandle($Input1)
If Not IsHWnd($Input2) Then $hWndEdit1 = GUICtrlGetHandle($Input2)
$hWndFrom = $ilParam
$iIDFrom = _WinAPI_LoWord($iwParam)
$iCode = _WinAPI_HiWord($iwParam)
Switch $hWndFrom
Case $Input1, $Input2, $hWndEdit, $hWndEdit1
Switch $iCode
Case $EN_CHANGE ; Sent when the user has taken an action that may have altered text in an edit control
If $ilParam = $hWndEdit Then
$a = GUICtrlRead($Input1)
If StringRegExp($a, "[^\d\.]", 0) Then
Beep(500, 100)
GUICtrlSetData($Input1, StringRegExpReplace($a, "[^\d\.]",''))
EndIf
Else
$a = GUICtrlRead($Input2)
If StringRegExp($a, "[^\d\.]", 0) Then
Beep(500, 50)
GUICtrlSetData($Input2, StringRegExpReplace($a, "[^\d\.]",''))
EndIf
EndIf
Case $EN_KILLFOCUS ; Sent when an edit control loses the keyboard focus
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc
其实用按钮式样的不是更方便嘛。(像系统自带的计算器)