Jump to content
Sign in to follow this  
60aside

MAC Address inputbox

Recommended Posts

60aside

Hi Guys,

How can I create an input box for a MAC address? I can see there is GUICtrlIpAddress_Create for IP Address.

It has to be in the form of xx:xx:xx:xx:xx:xx

Thanks.

Share this post


Link to post
Share on other sites
ResNullius

http://www.autoitscript.com/forum/index.php?showtopic=103199&view=findpost&p=733361

:)

Share this post


Link to post
Share on other sites
Authenticity

An IP address control is just a registered class that wrap 4 managed edit controls. This is not the same but the concept is similar:

#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <GUIIPAddress.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

Local $hGUI, $IP, $MAC, $hMAC, $Input, $hInput
Local $hFunc, $hWndProc

$hGUI = GUICreate("Title", 250, 150)
$IP = _GUICtrlIpAddress_Create($hGUI, 20, 20)
$MAC = GUICtrlCreateLabel("         .         .         .         .         .         ", 20, 55, -1, 25, BitOR($SS_CENTER, $WS_BORDER))
$hMAC = GUICtrlGetHandle(-1)
GUICtrlSetBkColor(-1, 0xFFFFFF)

For $i = 0 To 5
    $Input = GUICtrlCreateInput("", $i*30+7, 1, 20, 20, $ES_CENTER, 0)
    GUICtrlSendMsg(-1, $EM_SETLIMITTEXT, 2, 0)
    $hInput = GUICtrlGetHandle(-1)
    _WinAPI_SetWindowLong($hInput, $GWL_STYLE, BitAND(_WinAPI_GetWindowLong($hInput, $GWL_STYLE), BitNOT($WS_BORDER)))
    _WinAPI_SetParent($hInput, $hMAC)
Next

$hFunc = DllCallbackRegister("_LabelProc", "int", "hwnd;uint;wparam;lparam")
$hWndProc = _WinAPI_SetWindowLong($hMAC, $GWL_WNDPROC, DllCallbackGetPtr($hFunc))

GUISetState()
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

_WinAPI_SetWindowLong($hMAC, $GWL_WNDPROC, $hWndProc)
GUIDelete()
DllCallbackFree($hFunc)
Exit

Func _LabelProc($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hDC, $hBrush, $hRgn
    Local $tRc
    
    If $iMsg = $WM_NCPAINT Then
        $hDC = _WinAPI_GetDC($hWnd)
        $tRc = _WinAPI_GetClientRect($hWnd)
        $hRgn = _WinAPI_CreateRectRgn(-1, -1, DllStructGetData($tRc, "Right")-DllStructGetData($tRc, "Left")+1, DllStructGetData($tRc, "Bottom")-DllStructGetData($tRc, "Top")+1)
        $hBrush = _WinAPI_CreateSolidBrush(0xCFAF87)
        _WinAPI_FillRgn($hDC, $hRgn, $hBrush)
        
        _WinAPI_DeleteObject($hBrush)
        _WinAPI_DeleteObject($hRgn)
        _WinAPI_ReleaseDC($hWnd, $hDC)
        
        Return 0
    EndIf
    
    Return _WinAPI_CallWindowProc($hWndProc, $hWnd, $iMsg, $iwParam, $ilParam)
EndFunc

Func _WinAPI_FillRgn($hDC, $hRgn, $hBrush)
    Local $aResult
    If IsPtr($hBrush) Then
        $aResult = DllCall("gdi32.dll", "int", "FillRgn", "hwnd", $hDC, "hwnd", $hRgn, "hwnd", $hBrush)
    Else
        $aResult = DllCall("gdi32.dll", "int", "FillRgn", "hwnd", $hDC, "hwnd", $hRgn, "int", $hBrush)
    EndIf
    
    If @error Then Return SetError(@error, @extended, 0)
    Return SetError(0, 0, $aResult[0] <> 0)
EndFunc

The rest is to subclass the 6 edit controls and manage them. As well, you need to subclass the label control and handle it's WM_GETTEXT and return the content of the 6 edit controls formatted as "xx.xx.xx.xx.xx.xx".

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.