#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiIPAddress.au3>
#include <GuiEdit.au3>
Opt("GUIOnEventMode", 1)
$Form1 = GUICreate("Form1", 294, 85)
GUISetOnEvent($GUI_EVENT_CLOSE, "GetMain")
GUISetOnEvent($GUI_EVENT_PRIMARYUP, "GetMain")
$Button1 = GUICtrlCreateButton("Button1", 190, 30, 80, 25, 0)
GUICtrlSetOnEvent($Button1, "GetMain")
GUICtrlSetState($Button1, $GUI_DISABLE)
$Label1 = GUICtrlCreateLabel("", 58, 4, 60, 28)
$Input1 = GUICtrlCreateInput("", 10, 20, 169, 25)
GUICtrlSetLimit($Input1, 3) ;只能输入三个字符
$IPAddress1 = _GUICtrlIpAddress_Create($Form1, 10, 50, 169, 25)
_WinAPI_EnableWindow($IPAddress1, False)
_GUICtrlIpAddress_Set($IPAddress1, "0.0.0.0")
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") ;注册WM_COMMAND消息
ControlFocus("Form1", "", $Input1)
GUISetState()
While 1
Sleep(100)
WEnd
Func GetMain()
Switch @GUI_CtrlId
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
MsgBox(0, "", GUICtrlRead($Input1))
Case $GUI_EVENT_PRIMARYUP
_GUICtrlEdit_SetSel($Input1, 3, 3)
EndSwitch
EndFunc ;==>GetMain
Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam) ;消息处理
$nNotifyCode = BitShift($wParam, 16)
$nID = BitAND($wParam, 0x000FFFF)
Switch $nID
Case $Input1
Switch $nNotifyCode
Case $EN_CHANGE
$Select = GUICtrlRead($Input1)
If StringIsDigit($Select) And $Select <> "" And $Select <= 254 Then
_GUICtrlIpAddress_Set($IPAddress1, "192.168.0." & $Select)
GUICtrlSetState($Button1, $GUI_ENABLE)
_WinAPI_EnableWindow($IPAddress1, True)
Else
GUICtrlSetData($Input1, "")
_GUICtrlIpAddress_Set($IPAddress1, "0.0.0.0")
GUICtrlSetState($Button1, $GUI_DISABLE)
_WinAPI_EnableWindow($IPAddress1, False)
EndIf
EndSwitch
EndSwitch
EndFunc ;==>WM_COMMAND
|