#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <GuiEdit.au3>
#include <GuiListBox.au3>
#include <GuiListView.au3>
#include <GuiButton.au3>
#include <File.au3>
#include <Array.au3>
#include <WinAPISys.au3>
Global $text1, $text2, $text3, $temp
Local $GUI_Form1 = GUICreate("筆錄軟體", 1190, 625, 226, 144)
GUICtrlCreateLabel("審問:", 10, 10, 40, 15)
Global $GUI_ListView1 = GUICtrlCreateListView("審問範例|回答1|回答2|回答3", 10, 30, 530, 300)
_GUICtrlListView_SetColumnWidth($GUI_ListView1, 0, 350)
GUICtrlCreateLabel("可選回答:", 10, 340, 60, 15)
Global $GUI_ListView2 = GUICtrlCreateListView("回答範例", 10, 360, 530, 130)
_GUICtrlListView_SetColumnWidth($GUI_ListView2, 0, 500)
GUICtrlCreateLabel("自行輸入:", 10,500, 60, 15)
Global $Edit1 = GUICtrlCreateEdit("", 10, 520, 537, 97)
GUICtrlCreateLabel("審問筆錄:", 660,10, 60, 15)
Global $Edit2 = GUICtrlCreateEdit("", 660, 30, 520, 580)
GUICtrlSetData($Edit2, "")
$Button1 = GUICtrlCreateButton("選擇文件", 560, 32, 65, 33)
$Button2 = GUICtrlCreateButton("加入右侧", 565, 550, 65, 33)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ;註冊滑鼠點擊狀態
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE ;關閉視窗
Exit
Case $Button1 ;開啟樣板
Open_file()
Case $Button2 ;帶入手動編輯
If GUICtrlRead($Edit1) <> "" Then ;確保$Edit1是有文字輸入
$Index1 = _GUICtrlListView_GetSelectedIndices($GUI_ListView1)
If Not StringLen($Index1) Then;
MsgBox(0, "", "未選擇審問範例")
Else
$text1 = GUICtrlRead($Edit2)
$text2 = "問:" & _GUICtrlListView_GetItemText($GUI_ListView1, Number($Index1), 0) & @CRLF
$text3 = "答:" & GUICtrlRead($Edit1)& @CRLF
$text4 = $text1 & $text2 & $text3
GUICtrlSetData($Edit2, $text4)
EndIf
EndIf
EndSwitch
WEnd
Func Open_file() ;開啟樣檔
Local $a_cvs,$s_temp
_GUICtrlListView_DeleteAllItems($GUI_ListView1) ;刪除舊LIST資料
$s_Path = FileOpenDialog("Select CVS File", @ScriptDir, "All (*.csv)") ;開啟舊檔
If @error Then
MsgBox(4096, "", "未選擇檔案")
Else
_FileReadToArray($s_Path, $a_cvs) ;將檔案讀取到陣列
;_ArrayDisplay($a_cvs)
For $i = 1 To UBound($a_cvs) - 1 ;以下兩行將cvs格式轉成listview格式並顯示
$s_temp = StringReplace($a_cvs[$i], ",", "|")
GUICtrlCreateListViewItem($s_temp, $GUI_ListView1)
Next
EndIf
EndFunc
Func WM_NOTIFY($hWndGUI, $MsgID, $WParam, $LParam)
Local $tagNMHDR, $Event, $hWndFrom, $IDFrom
Local $tagNMHDR = DllStructCreate("int;int;int", $LParam)
If @error Then Return $GUI_RUNDEFMSG
$IDFrom = DllStructGetData($tagNMHDR, 2)
$Event = DllStructGetData($tagNMHDR, 3)
$tagNMHDR = 0
Switch $IDFrom;选择产生事件的控件
Case $GUI_ListView1
Switch $Event; 選擇產生的事件
Case $NM_CLICK ; 左鍵
Case $NM_DBLCLK ; 左鍵雙擊
$Index1 = _GUICtrlListView_GetSelectedIndices($GUI_ListView1)
If Not StringLen($Index1) Then; 这里用以判断是否选定了ListViewItem
MsgBox(0, "", "未選擇")
Return
EndIf
_GUICtrlListView_DeleteAllItems($GUI_ListView2)
$text1 = "問:" & _GUICtrlListView_GetItemText($GUI_ListView1, Number($Index1), 0) & @CRLF
;MsgBox(0,"$text1",$text1)
GUICtrlCreateListViewItem(_GUICtrlListView_GetItemText($GUI_ListView1, Number($Index1), 1), $GUI_ListView2)
GUICtrlCreateListViewItem(_GUICtrlListView_GetItemText($GUI_ListView1, Number($Index1), 2), $GUI_ListView2)
GUICtrlCreateListViewItem(_GUICtrlListView_GetItemText($GUI_ListView1, Number($Index1), 3), $GUI_ListView2)
Case $NM_RCLICK ; 右鍵
EndSwitch
Case $GUI_ListView2
Switch $Event; 選擇產生的事件
Case $NM_CLICK ; 左鍵
Case $NM_DBLCLK ; 左鍵雙擊
$Index2 = _GUICtrlListView_GetSelectedIndices($GUI_ListView2)
If Not StringLen($Index2) Then; 这里用以判断是否选定了ListViewItem
MsgBox(0, "", "未選擇")
Return
EndIf
$text2 = $text1 & "答:" & _GUICtrlListView_GetItemText($GUI_ListView2, Number($Index2),0) & @CRLF
;MsgBox(0, "", $text2)
$text3 = GUICtrlRead($Edit2)
$text2 = $text3 & $text2
GUICtrlSetData($Edit2, $text2)
Case $NM_RCLICK ; 右鍵
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY