本帖最後由 rictirse 於 2014-12-24 08:39 編輯
- #include <GuiConstants.au3>
- Global $Cnt = 3;全部input box的數量
- Global $DefaultInputData[$Cnt] = ["這是第一行","這是第二行","這是第三行"];預設的灰底字 cnt為三個所以要有三段文字
- Global $InputTempText[$Cnt];預設灰色文字讀到Memory內
- Global $Flag[$Cnt],$Input[$Cnt];宣告 input 與 Flag 陣列高度
- Global $reg = "HKCUSoftwareDangTest" ;reg 路徑
- Global $NoneaActiveColor = 0x989898;灰色文字
- $GUI = GUICreate ( "Input", 280, 150)
- For $i = 0 To ($Cnt-1)
- $InputTempText[$i] = $DefaultInputData[$i];將灰字傳到 temp裡,當對照組
- $Flag[$i] = 0;標記預設0 = 灰字模式 1 = 實際文字
- $Input[$i] = GUICtrlCreateInput ( $DefaultInputData[$i], 15, 20+($i*30), 250, 20);產生Input GUI
- If RegRead ( $Reg, "InputData"&$i) <> "" And RegRead ( $Reg, "InputData"&$i) <> $DefaultInputData[$i] Then;如果reg不等於 "空白" 或 預設的灰字
- GUICtrlSetData ( $Input[$i], RegRead ( $Reg, "InputData"&$i));載入存檔
- $Flag[$i] = RegRead ( $Reg, "Flag"&$i);讀入Flag
- Else
- GUICtrlSetColor ( -1, $NoneaActiveColor);將預設顏色設為灰字
- EndIf
- Next
- $ExitButton = GUICtrlCreateButton ( "Exit", 200, 125, 60, 20)
- GUICtrlSetState ( -1, $GUI_DEFBUTTON)
- GUISetState ()
- ControlFocus ( $GUI, "", $ExitButton);將EXIT BOX 設為預設啟動按鈕
- While 1
- For $i = 0 To ($Cnt-1)
- _CheckInput ( $GUI, $Input[$i], $InputTempText[$i], $DefaultInputData[$i], $Flag[$i], $i)
- If GUICtrlRead ($Input[$i]) <> $InputTempText[$i] Then;如果Input內容跟預設灰字一樣就不存檔
- _InputBoxSave ( $Input[$i], "InputData"&$i);存檔
- EndIf
- Next
- Switch GUIGetMsg()
- Case $GUI_EVENT_CLOSE
- Exit
- Case $ExitButton
- Exit
- EndSwitch
- WEnd
- Func _CheckInput ( $hWnd, $InputName, $InputTempText, ByRef $DefaultInputData, ByRef $Flag, $i)
- If $Flag = 0 And _IsFocused ( $hWnd, $InputName) And $DefaultInputData = $InputTempText Then
- $Flag = 1
- RegWrite ( $Reg, "Flag"&$i, "REG_SZ", 1)
- GUICtrlSetData ( $InputName, "")
- GUICtrlSetColor ( $InputName, 0x000000)
- $DefaultInputData = ""
- ElseIf $Flag = 1 And Not _IsFocused ( $hWnd, $InputName) And GUICtrlRead ($InputName) = "" Then
- $Flag = 0
- RegWrite ( $Reg, "Flag"&$i, "REG_SZ", 0)
- $DefaultInputData = $InputTempText
- GUICtrlSetData ( $InputName, $DefaultInputData)
- GUICtrlSetColor ( $InputName, $NoneaActiveColor)
- EndIf
- EndFunc
- Func _IsFocused ( $hWnd, $nCID)
- Return ControlGetHandle ( $hWnd, '', $nCID) = ControlGetHandle ( $hWnd, '', ControlGetFocus ($hWnd))
- EndFunc
- Func _InputBoxSave ( $InputName, $RegName);存檔到Reg
- If GUICtrlRead ($InputName) <> RegRead ( $Reg, $RegName) Then
- RegWrite ( $Reg, $RegName, "REG_SZ", GUICtrlRead ($InputName))
- EndIf
- EndFunc
複製代碼 |