#include <ACN_NET.au3>
#include <WinAPI.au3>
#include <GUIEdit.au3>
#include <GUIConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Global $_MACS_DELIMITER = ":"
Global $_MACC_MACADDRS[1][7] = [[0]]
Global $_MACN_PRODURE
Global $_MACPP_WND_DEF_PROC = DllCallbackRegister("_MACADDRWNDPROC", "int", "hWnd;uint;wparam;lparam")
$sMac = _API_Get_NetworkAdapterMAC(@IPAddress1)
MsgBox(0, "", $sMac)
Func _GUICtrlMacAddr_Create($hWnd, $iLeft, $iTop, $sMac = "")
Local $iPid, $hParent, $i_Parent, $i_Width, $i_Left, $h_Field, $aMac, $i_Pos = 0
_WinAPI_GetWindowThreadProcessId($hWnd, $iPid)
If $iPid <> @AutoItPID Then Return SetError(1, 0, 0)
$i_Parent = GUICtrlCreateLabel("", $iLeft, $iTop, 140, 20, $SS_SUNKEN)
$hParent = GUICtrlGetHandle(-1)
GUICtrlSetBkColor(-1, 0xFFFFFF)
$_MACC_MACADDRS[0][0] += 1
ReDim $_MACC_MACADDRS[$_MACC_MACADDRS[0][0] + 1][7]
$_MACC_MACADDRS[$_MACC_MACADDRS[0][0]][0] = $i_Parent
For $i = 1 To 6
$_MACC_MACADDRS[$_MACC_MACADDRS[0][0]][$i] = GUICtrlCreateInput("", $i_Pos, 3, 20, 17, 1, 4)
GUICtrlSetLimit(-1, 2)
$h_Field = GUICtrlGetHandle(-1)
_WinAPI_SetParent($h_Field, $hParent)
If $_MACC_MACADDRS[0][0] = 1 And $i = 1 Then
GUIRegisterMsg($WM_COMMAND, "_CuiCtrlMacAddr_CmdProc")
$_MACN_PRODURE = _WinAPI_SetWindowLong($h_Field, -4, DllCallbackGetPtr($_MACPP_WND_DEF_PROC))
Else
_WinAPI_SetWindowLong($h_Field, -4, DllCallbackGetPtr($_MACPP_WND_DEF_PROC))
EndIf
GUICtrlCreateLabel($_MACS_DELIMITER, $i_Pos + 41, $iTop + 10, 4, 2, $SS_SUNKEN)
$i_Pos += 23
Next
GUICtrlDelete(-1)
If $sMac <> "" Then
$aMac = StringSplit($sMac, $_MACS_DELIMITER)
If $aMac[0] > 6 Then Return $_MACC_MACADDRS[0][0]
For $i = $aMac[0] To 1 Step -1
If StringLen($aMac[$i]) = 2 And StringIsXDigit($aMac[$i]) Then
GUICtrlSetData($_MACC_MACADDRS[$_MACC_MACADDRS[0][0]][$i], $aMac[$i])
EndIf
Next
EndIf
Return $_MACC_MACADDRS[0][0]
EndFunc ;==>_GUICtrlMacAddr_Create
Func _GUICtrlMacAddr_GetAddress($iMacIndex)
Local $sAddr
If $iMacIndex < 1 Or $iMacIndex > $_MACC_MACADDRS[0][0] Then Return ""
For $i = 1 To 6
$sAddr &= GUICtrlRead($_MACC_MACADDRS[$iMacIndex][$i]) & $_MACS_DELIMITER
Next
Return StringTrimRight($sAddr, StringLen($_MACS_DELIMITER))
EndFunc ;==>_GUICtrlMacAddr_GetAddress
Func _CuiCtrlMacAddr_CmdProc($hWnd, $iMsg, $wparam, $lparam)
Local $nID, $iNotifyCode
$nID = BitAND($wparam, 0xFFFF)
$iNotifyCode = BitShift($wparam, 0x10)
If $iNotifyCode = $EN_CHANGE Then
For $i = 1 To $_MACC_MACADDRS[0][0]
For $f = 1 To 6
If $nID = $_MACC_MACADDRS[$i][$f] And StringLen(GUICtrlRead($nID)) >= 2 Then
GUICtrlSetState($nID + 2, $GUI_FOCUS)
_GUICtrlEdit_SetSel($nID + 2, 0, 2)
EndIf
Next
Next
EndIf
EndFunc ;==>_CuiCtrlMacAddr_CmdProc
Func _GUICtrlMacAddr_SetAddress($iMacIndex, $sMac)
Local $aMac
If $iMacIndex < 1 Or $iMacIndex > $_MACC_MACADDRS[0][0] Then Return 0
$aMac = StringSplit($sMac, $_MACS_DELIMITER)
For $i = $aMac[0] To 1 Step -1
If StringLen($aMac[$i]) = 2 And StringIsXDigit($aMac[$i]) Then
GUICtrlSetData($_MACC_MACADDRS[$iMacIndex][$i], $aMac[$i])
EndIf
Next
Return 1
EndFunc ;==>_GUICtrlMacAddr_SetAddress
Func _GUICtrlMacAddr_ShowHide($iMacIndex, $fHide = True)
Local $iState = $GUI_SHOW
If $fHide = True Then $iState = $GUI_HIDE
If $iMacIndex < 1 Or $iMacIndex > $_MACC_MACADDRS[0][0] Then Return 0
For $i = 0 To 6
GUICtrlSetState($_MACC_MACADDRS[$iMacIndex][$i], $iState)
If $i = 6 Then ContinueLoop
GUICtrlSetState($_MACC_MACADDRS[$iMacIndex][$i] + 1, $iState)
Next
Return 1
EndFunc ;==>_GUICtrlMacAddr_ShowHide
Func _MACADDRWNDPROC($hWnd, $iMsg, $wparam, $lparam)
If $iMsg = $WM_CHAR Then
If StringIsXDigit(Chr($wparam)) = 0 And $wparam <> 8 Then Return 0
EndIf
Return _WinAPI_CallWindowProc($_MACN_PRODURE, $hWnd, $iMsg, $wparam, $lparam)
EndFunc ;==>_MACADDRWNDPROC