#NoTrayIcon
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
Opt("GUIOnEventMode", 1)
Global $Button[65]
Global $x = 1, $y = 1
Global $txt
$Form1 = GUICreate("8*8点阵计算工具---随心飘渺", 342, 350)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
For $i = 1 To 64
$Button[$i] = GUICtrlCreateButton("", ($x * 42) - 36, ($y * 38) - 30, 35, 35)
;GUICtrlSetBkColor(-1, 0x000000)
GUICtrlSetBkColor(-1, 0xC0C0C0)
GUICtrlSetOnEvent($Button[$i], "_ButtonXY")
$x += 1
$txt &= "0"
If $x = 9 Then
$x = 1
Switch $y
Case 1
$y = 2
Case 2
$y = 3
Case 3
$y = 4
Case 4
$y = 5
Case 5
$y = 6
Case 6
$y = 7
Case 7
$y = 8
Case 8
$y = 9
Case 9
$y = 10
EndSwitch
EndIf
Next
$Input1 = GUICtrlCreateInput("", 1, 320, 340, 21)
GUICtrlSetStyle(-1, $ES_READONLY + $ES_CENTER)
GUISetState()
While 1
Sleep(10)
WEnd
Func _ButtonXY()
Local $var, $i, $result[9],$Hex
$var = StringInStr($txt, "1", 0, 1, @GUI_CtrlId - 2, 1)
If $var = 0 Then
$txt = StringReplace($txt, @GUI_CtrlId - 2, "1")
GUICtrlSetBkColor(@GUI_CtrlId, 0x000000)
Else
$txt = StringReplace($txt, @GUI_CtrlId - 2, "0")
GUICtrlSetBkColor(@GUI_CtrlId, 0xC0C0C0)
EndIf
$Hex=$txt
For $i = 1 To 8
$result[$i] = StringLeft($Hex, 8)
$Hex = StringTrimLeft($Hex, 8)
$result[$i] = _BinaryToHex($result[$i],2)
Next
For $i = 1 To 8
$Hex = $Hex&"0x" & $result[$i] & ","
Next
GUICtrlSetData($Input1, $Hex)
EndFunc ;==>_ButtonXY
Func Form1Close()
Exit
EndFunc ;==>Form1Close
Func _BinaryToHex($sBinStr, $iLength = 0)
Local $sHexStr = ""
If Not StringRegExp($sBinStr, "^[01]+$") Then Return SetError(1, 0, "")
While Mod(StringLen($sBinStr), 4)
$sBinStr = "0" & $sBinStr
WEnd
For $i = 1 To StringLen($sBinStr) Step 4
Switch StringMid($sBinStr, $i, 4)
Case "0000"
$sHexStr &= "0"
Case "0001"
$sHexStr &= "1"
Case "0010"
$sHexStr &= "2"
Case "0011"
$sHexStr &= "3"
Case "0100"
$sHexStr &= "4"
Case "0101"
$sHexStr &= "5"
Case "0110"
$sHexStr &= "6"
Case "0111"
$sHexStr &= "7"
Case "1000"
$sHexStr &= "8"
Case "1001"
$sHexStr &= "9"
Case "1010"
$sHexStr &= "A"
Case "1011"
$sHexStr &= "B"
Case "1100"
$sHexStr &= "C"
Case "1101"
$sHexStr &= "D"
Case "1110"
$sHexStr &= "E"
Case "1111"
$sHexStr &= "F"
EndSwitch
Next
If $iLength = 0 Then
While StringLeft($sHexStr, 1) = "0"
$sHexStr = StringTrimLeft($sHexStr, 1)
WEnd
Else
For $i = 1 To $iLength - StringLen($sHexStr)
$sHexStr = "0" & $sHexStr
Next
EndIf
Return $sHexStr
EndFunc ;==>_BinaryToHex