Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

List view error

$
0
0
This is my code :
[ autoit ]         
#include #include #include #include #include #include #include $IniFile = @ScriptDir & "\Setting.ini" If FileExists($IniFile) = 0 Then FileOpen($IniFile, 2 + 8 + 128) Else EndIf Global $Style = BitOR($WS_CHILD, $WS_VISIBLE, $ES_AUTOHSCROLL, $ES_LEFT), $hHook, $hStub_KeyProc Global $hEdit, $hDC, $hBrush, $Item = -1, $SubItem = 0, $iSubItemText, $tSubitem, $tiSubitemtext, $currentcol, $hEdit1, $tItem _GUI() Func _GUI() Global $GUI = GUICreate("THỐNG KÊ CẤP PHÁT", @DesktopWidth - 380, @DesktopHeight - 250, -1, -1) Global $FileMenu = GUICtrlCreateMenu("&File") Global $mSave = GUICtrlCreateMenuItem("Lưu và xuất thành Excel", $FileMenu) Global $mExit = GUICtrlCreateMenuItem("Exit", $FileMenu) Global $Option = GUICtrlCreateMenu("&Options") Global $mConfig = GUICtrlCreateMenuItem("Tùy chỉnh", $Option) Global $Start = GUICtrlCreateButton("BẮT ĐẦU", 88, 400, 121, 49) GUICtrlSetFont(-1, 12, 800, 0, "Times New Roman") Global $Export = GUICtrlCreateButton("XUẤT EXCEL", 408, 400, 121, 49) GUICtrlSetFont(-1, 12, 800, 0, "Times New Roman") Global $Exit = GUICtrlCreateButton("KẾT THÚC", 720, 400, 121, 49) GUICtrlSetFont(-1, 12, 800, 0, "Times New Roman") Create_Listview() GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") GUIRegisterMsg($WM_SIZE, "WM_SIZE") OnAutoItExitRegister("Cleanup") $hStub_KeyProc = DllCallbackRegister("_KeyProc", "long", "int;wparam;lparam") $hmod = _WinAPI_GetModuleHandle(0) $hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($hStub_KeyProc), $hmod) While 1 $Msg = GUIGetMsg() Switch $Msg Case $GUI_EVENT_CLOSE Exit Case $mConfig _OptionGUI() EndSwitch WEnd EndFunc Func _OptionGUI() GUISetState(@SW_DISABLE, $GUI) Global $OptionGUI = GUICreate("Tùy chỉnh", 288, 329, -1, -1, BitXOR($GUI_SS_DEFAULT_GUI, $WS_MINIMIZEBOX), Not ($WS_EX_OVERLAPPEDWINDOW), $GUI) $OK = GUICtrlCreateButton("OK", 16, 264, 115, 41) GUICtrlSetFont(-1, 12, 800, 0, "Times New Roman") $HuyBo = GUICtrlCreateButton("Hủy Bỏ", 152, 264, 115, 41) GUICtrlSetFont(-1, 12, 800, 0, "Times New Roman") GUICtrlCreateGroup(" Thiết lập ", 16, 16, 257, 233) GUICtrlSetFont(-1, 10, 800, 0, "Times New Roman") GUICtrlCreateLabel("Số nhân viên", 32, 48, 73, 19) Global $Nhanvien = GUICtrlCreateInput("", 112, 48, 145, 23) GUICtrlCreateLabel("Tên mặt hàng", 32, 88, 78, 19) Global $Mathang = GUICtrlCreateInput("", 112, 88, 145, 23) GUICtrlCreateLabel("Thời hạn", 40, 128, 52, 19) Global $Thoihan = GUICtrlCreateInput("", 112, 128, 145, 23) GUICtrlCreateLabel("Số lượng/ lần", 32, 168, 76, 19) Global $Soluong = GUICtrlCreateInput("", 112, 168, 145, 23, $ES_NUMBER) GUICtrlSetColor(-1, 0xFF0000) Global $Them = GUICtrlCreateButton("Thêm", 40, 208, 75, 25) GUICtrlSetTip($Them, "Thêm mặt hàng vào chương trình") Global $Add = GUICtrlCreateButton("+", 176, 208, 35, 25) GUICtrlSetTip($Add, "Thêm một mặt hàng khác") GUICtrlSetFont(-1, 18, 800, 0, "Times New Roman") GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE GUISetState(@SW_ENABLE, $GUI) GUIDelete($OptionGUI) ExitLoop Case $OK _Set_Settings() EndSwitch WEnd EndFunc ;==>_OptionGUI Func _Set_Settings() If GUICtrlRead($Nhanvien) Or GUICtrlRead($Mathang) Or GUICtrlRead($Thoihan) Or GUICtrlRead($Soluong) = "" Then MsgBox(48, "", "Không được để trống thông tin", 0, $OptionGUI) IniWrite($IniFile, "Information", "Nhanvien", GUICtrlRead($Nhanvien)) IniWrite($IniFile, "Information", "Mathang", GUICtrlRead($Mathang)) IniWrite($IniFile, "Information", "Thoihan", GUICtrlRead($Thoihan)) IniWrite($IniFile, "Information", "Soluong", GUICtrlRead($Soluong)) EndFunc Func Cleanup() _WinAPI_UnhookWindowsHookEx($hHook) DllCallbackFree($hStub_KeyProc) EndFunc ;==>Cleanup Func Create_Listview() Local $i, $cInfo Global $hListView = _GUICtrlListView_Create($GUI, "", 10, 10, @DesktopWidth - 400, @DesktopHeight - 400, BitOR($LVS_EDITLABELS, $LVS_REPORT)) _GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_GRIDLINES) _GUICtrlListView_AddColumn($hListView, "Họ và tên", 175, -1) _GUICtrlListView_AddColumn($hListView, "Ngày làm việc", 175, -1) _GUICtrlListView_AddColumn($hListView, "", 175, -1) _GUICtrlListView_AddColumn($hListView, "", 175, -1) _GUICtrlListView_AddColumn($hListView, "", 175, -1) For $i = 1 To 10 _GUICtrlListView_AddItem($hListView, "") _GUICtrlListView_AddSubItem($hListView, $i - 1, "", 1) _GUICtrlListView_AddSubItem($hListView, $i - 1, "", 2) _GUICtrlListView_AddSubItem($hListView, $i - 1, "", 3) Next EndFunc ;==>Create_Listview Func WM_SIZE($hWnd, $Msg, $wParam, $lParam) Local $index = -1, $yChar, $xChar, $xClientMax, $xClient, $yClient, $ivMax For $x = 0 To UBound($aSB_WindowInfo) - 1 If $aSB_WindowInfo[$x][0] = $hWnd Then $index = $x $xClientMax = $aSB_WindowInfo[$index][1] $xChar = $aSB_WindowInfo[$index][2] $yChar = $aSB_WindowInfo[$index][3] $ivMax = $aSB_WindowInfo[$index][7] ExitLoop EndIf Next If $index = -1 Then Return 0 Local $tSCROLLINFO = DllStructCreate($tagSCROLLINFO) $xClient = BitAND($lParam, 0x0000FFFF) $yClient = BitShift($lParam, 16) $aSB_WindowInfo[$index][4] = $xClient $aSB_WindowInfo[$index][5] = $yClient DllStructSetData($tSCROLLINFO, "fMask", BitOR($SIF_RANGE, $SIF_PAGE)) DllStructSetData($tSCROLLINFO, "nMin", 0) DllStructSetData($tSCROLLINFO, "nMax", $ivMax) DllStructSetData($tSCROLLINFO, "nPage", $yClient / $yChar) _GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO) DllStructSetData($tSCROLLINFO, "fMask", BitOR($SIF_RANGE, $SIF_PAGE)) DllStructSetData($tSCROLLINFO, "nMin", 0) DllStructSetData($tSCROLLINFO, "nMax", 2 + $xClientMax / $xChar) DllStructSetData($tSCROLLINFO, "nPage", $xClient / $xChar) _GUIScrollBars_SetScrollInfo($hWnd, $SB_HORZ, $tSCROLLINFO) Return $GUI_RUNDEFMSG EndFunc ;==>WM_SIZE Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $tNMHDR, $hWndFrom, $iCode, $col_width, $cInfo, $iIDFrom, $tInfo, $iLen, $aRect, $hEdit1 $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom") $iCode = DllStructGetData($tNMHDR, "Code") $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") Switch $hWndFrom Case $hListView Switch $iCode Case $LVN_COLUMNCLICK ; A column was clicked $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam) $currentcol = DllStructGetData($tInfo, "SubItem") $cInfo = _GUICtrlListView_GetColumn($hListView, $currentcol) GUICtrlSetData($hEdit1, $cInfo[5]) Case $NM_DBLCLK Local $aHit = _GUICtrlListView_SubItemHitTest($hListView) If ($aHit[0] <> -1) And ($aHit[1] > 0) Then $Item = $aHit[0] $SubItem = $aHit[1] $iSubItemText = _GUICtrlListView_GetItemText($hListView, $Item, $SubItem) $iLen = _GUICtrlListView_GetStringWidth($hListView, $iSubItemText) If $iLen = 0 Then $iLen = 20 EndIf $aRect = _GUICtrlListView_GetSubItemRect($hListView, $Item, $SubItem) $hEdit = _GUICtrlEdit_Create($GUI, $iSubItemText, $aRect[0] + 10, $aRect[1] + 10, _GUICtrlListView_GetColumnWidth($hListView, $SubItem), 17, $Style) _GUICtrlEdit_SetSel($hEdit, 0, -1) _WinAPI_SetFocus($hEdit) $hDC = _WinAPI_GetWindowDC($hEdit) $hBrush = _WinAPI_CreateSolidBrush(0) FrameRect($hDC, 0, 0, _GUICtrlListView_GetColumnWidth($hListView, $SubItem), 17, $hBrush) ElseIf ($aHit[0] <> -1) And ($aHit[1] = 0) Then $Item = $aHit[0] $SubItem = $aHit[1] $iSubItemText = _GUICtrlListView_GetItemText($hListView, $Item) $iLen = _GUICtrlListView_GetStringWidth($hListView, $iSubItemText) $aRect = _GUICtrlListView_GetItemRect($hListView, $Item) $hEdit = _GUICtrlEdit_Create($GUI, $iSubItemText, $aRect[0] + 6, $aRect[1] + 10, _GUICtrlListView_GetColumnWidth($hListView, $SubItem), 17, $Style) _GUICtrlEdit_SetSel($hEdit, 0, -1) _WinAPI_SetFocus($hEdit) $hDC = _WinAPI_GetWindowDC($hEdit) $hBrush = _WinAPI_CreateSolidBrush(0) FrameRect($hDC, 0, 0, _GUICtrlListView_GetColumnWidth($hListView, $SubItem), 17, $hBrush) EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func _KeyProc($nCode, $wParam, $lParam) Local $tKEYHOOKS $tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam) If $nCode < 0 Then Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam) EndIf If $wParam = $WM_KEYDOWN Then EvaluateKey(DllStructGetData($tKEYHOOKS, "vkCode")) Else Local $flags = DllStructGetData($tKEYHOOKS, "flags") Switch $flags Case $LLKHF_ALTDOWN ;~ ConsoleWrite("$LLKHF_ALTDOWN" & @CRLF) Case $LLKHF_EXTENDED ;~ ConsoleWrite("$LLKHF_EXTENDED" & @CRLF) Case $LLKHF_INJECTED ;~ ConsoleWrite("$LLKHF_INJECTED" & @CRLF) Case $LLKHF_UP ;~ ConsoleWrite("$LLKHF_UP: scanCode - " & DllStructGetData($tKEYHOOKS, "scanCode") & @TAB & "vkCode - " & DllStructGetData($tKEYHOOKS, "vkCode") & @CRLF) EndSwitch EndIf Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam) EndFunc ;==>_KeyProc Func EvaluateKey($keycode) Local $iLen, $aRect, $tItem If $keycode = 13 Then settext() $Item = -1 $SubItem = 0 ElseIf $keycode = 38 Then ;up arrow If $Item <> -1 Then $tItem = $Item $tSubitem = $SubItem $tiSubitemtext = $iSubItemText EndIf settext() If $tItem > 0 Then $tItem -= 1 Else $tItem = 19 EndIf $tiSubitemtext = _GUICtrlListView_GetItemText($hListView, $tItem, $tSubitem) $iLen = _GUICtrlListView_GetStringWidth($hListView, $tiSubitemtext) $aRect = _GUICtrlListView_GetSubItemRect($hListView, $tItem, $tSubitem) $hEdit = _GUICtrlEdit_Create($GUI, $tiSubitemtext, $aRect[0] + 10, $aRect[1] + 10, _GUICtrlListView_GetColumnWidth($hListView, $tSubitem), 17, $Style) _GUICtrlEdit_SetSel($hEdit, 0, -1) _WinAPI_SetFocus($hEdit) $hDC = _WinAPI_GetWindowDC($hEdit) $hBrush = _WinAPI_CreateSolidBrush(0) FrameRect($hDC, 0, 0, _GUICtrlListView_GetColumnWidth($hListView, $tSubitem), 17, $hBrush) ElseIf $keycode = 40 Then ;down arrow If $Item <> -1 Then $tItem = $Item $tSubitem = $SubItem $tiSubitemtext = $iSubItemText EndIf settext() If $tItem < 19 Then $tItem += 1 Else $tItem = 0 EndIf $tiSubitemtext = _GUICtrlListView_GetItemText($hListView, $tItem, $tSubitem) $iLen = _GUICtrlListView_GetStringWidth($hListView, $tiSubitemtext) $aRect = _GUICtrlListView_GetSubItemRect($hListView, $tItem, $tSubitem) $hEdit = _GUICtrlEdit_Create($GUI, $tiSubitemtext, $aRect[0] + 10, $aRect[1] + 10, _GUICtrlListView_GetColumnWidth($hListView, $tSubitem), 17, $Style) _GUICtrlEdit_SetSel($hEdit, 0, -1) _WinAPI_SetFocus($hEdit) $hDC = _WinAPI_GetWindowDC($hEdit) $hBrush = _WinAPI_CreateSolidBrush(0) FrameRect($hDC, 0, 0, _GUICtrlListView_GetColumnWidth($hListView, $tSubitem), 17, $hBrush) ElseIf $keycode = 37 Then ;left arrow If $Item <> -1 Then $tItem = $Item $tSubitem = $SubItem $tiSubitemtext = $iSubItemText EndIf settext() If $tSubitem > 0 Then $tSubitem -= 1 Else $tSubitem = _GUICtrlListView_GetColumnCount($hListView) - 1 EndIf $tiSubitemtext = _GUICtrlListView_GetItemText($hListView, $tItem, $tSubitem) $iLen = _GUICtrlListView_GetStringWidth($hListView, $tiSubitemtext) $aRect = _GUICtrlListView_GetSubItemRect($hListView, $tItem, $tSubitem) $hEdit = _GUICtrlEdit_Create($GUI, $tiSubitemtext, $aRect[0] + 10, $aRect[1] + 10, _GUICtrlListView_GetColumnWidth($hListView, $tSubitem), 17, $Style) _GUICtrlEdit_SetSel($hEdit, 0, -1) _WinAPI_SetFocus($hEdit) $hDC = _WinAPI_GetWindowDC($hEdit) $hBrush = _WinAPI_CreateSolidBrush(0) FrameRect($hDC, 0, 0, _GUICtrlListView_GetColumnWidth($hListView, $tSubitem), 17, $hBrush) ElseIf $keycode = 39 Then ;right arrow If $Item <> -1 Then $tItem = $Item $tSubitem = $SubItem $tiSubitemtext = $iSubItemText EndIf settext() If $tSubitem < _GUICtrlListView_GetColumnCount($hListView) - 1 Then $tSubitem += 1 Else $tSubitem = 0 EndIf $tiSubitemtext = _GUICtrlListView_GetItemText($hListView, $tItem, $tSubitem) $iLen = _GUICtrlListView_GetStringWidth($hListView, $tiSubitemtext) $aRect = _GUICtrlListView_GetSubItemRect($hListView, $tItem, $tSubitem) $hEdit = _GUICtrlEdit_Create($GUI, $tiSubitemtext, $aRect[0] + 10, $aRect[1] + 10, _GUICtrlListView_GetColumnWidth($hListView, $tSubitem), 17, $Style) _GUICtrlEdit_SetSel($hEdit, 0, -1) _WinAPI_SetFocus($hEdit) $hDC = _WinAPI_GetWindowDC($hEdit) $hBrush = _WinAPI_CreateSolidBrush(0) FrameRect($hDC, 0, 0, _GUICtrlListView_GetColumnWidth($hListView, $tSubitem), 17, $hBrush) ElseIf $keycode = 9 Then ;tab If $Item <> -1 Then $tItem = $Item $tSubitem = $SubItem $tiSubitemtext = $iSubItemText EndIf settext() If $tSubitem < _GUICtrlListView_GetColumnCount($hListView) - 1 Then $tSubitem += 1 Else $tSubitem = 0 If $tItem < 19 Then $tItem += 1 Else $tItem = 0 EndIf EndIf $tiSubitemtext = _GUICtrlListView_GetItemText($hListView, $tItem, $tSubitem) $iLen = _GUICtrlListView_GetStringWidth($hListView, $tiSubitemtext) $aRect = _GUICtrlListView_GetSubItemRect($hListView, $tItem, $tSubitem) $hEdit = _GUICtrlEdit_Create($Gui, $tiSubitemtext, $aRect[0] + 2, $aRect[1] + 2, _GUICtrlListView_GetColumnWidth($hListView, $tSubitem), 17, $Style) _GUICtrlEdit_SetSel($hEdit, 0, -1) _WinAPI_SetFocus($hEdit) $hDC = _WinAPI_GetWindowDC($hEdit) $hBrush = _WinAPI_CreateSolidBrush(0) FrameRect($hDC, 0, 0, _GUICtrlListView_GetColumnWidth($hListView, $tSubitem), 17, $hBrush) EndIf EndFunc ;==>EvaluateKey Func FrameRect($hDC, $nLeft, $nTop, $nRight, $nBottom, $hBrush) Local $stRect = DllStructCreate("int;int;int;int") DllStructSetData($stRect, 1, $nLeft) DllStructSetData($stRect, 2, $nTop) DllStructSetData($stRect, 3, $nRight) DllStructSetData($stRect, 4, $nBottom) DllCall("user32.dll", "int", "FrameRect", "hwnd", $hDC, "ptr", DllStructGetPtr($stRect), "hwnd", $hBrush) EndFunc ;==>FrameRect Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam) Local $iCode = BitShift($wParam, 16) Switch $lParam Case $hEdit Switch $iCode Case $EN_KILLFOCUS settext() $Item = -1 $SubItem = 0 EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND Func settext() Local $iText = _GUICtrlEdit_GetText($hEdit) If $Item <> -1 Then _GUICtrlListView_SetItemText($hListView, $Item, $iText, $SubItem) Else _GUICtrlListView_SetItemText($hListView, $tItem, $iText, $tSubitem) EndIf _WinAPI_DeleteObject($hBrush) _WinAPI_ReleaseDC($hEdit, $hDC) _WinAPI_DestroyWindow($hEdit) EndFunc

My code is error now, I can't use Tab, up arrow, down arrow, left arrow between 2 Subitem in Listview control. I try to fix this error but I can't find anything, and I think this error is come from EvaluateKey(). Please help me, I will be very grateful

Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>