[已解决]求助关于捕获listview回车事件
本帖最后由 king8462 于 2011-8-24 16:19 编辑具体流程如下:
首先用键盘输入简码或者用方向键选择listview1中的项目,把相关信息写入到$input5和$input8中,然后按tab键实现把焦点切换到$input10中,输入数量,点确定,读取$input5、$input8和$input10中的数据,写入listview2。怎样捕获listview1中的回车事件(从而省去按tab键),让焦点直接切换到$input10?
这是上次的帖子:
http://www.autoitx.com/thread-26658-1-1.html#NoTrayIcon
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstants.au3>
#include <GUIListView.au3>
#include <Array.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("form1", 1000, 600, -1, -1)
$ListView1 = GUICtrlCreateListView("简码|名称|零售价(元)", 24, 160, 945, 177)
GUICtrlCreateListViewItem("xb|雪碧|3.0", $ListView1)
GUICtrlCreateListViewItem("kkkl|可口可乐|3.1", $ListView1)
GUICtrlCreateListViewItem("glc|果粒橙|3.2", $ListView1)
GUICtrlCreateListViewItem("fd|芬达|3.3", $ListView1)
$Input10 = GUICtrlCreateInput("", 800, 112, 89, 21)
$Button2 = GUICtrlCreateButton("确定", 912, 112, 57, 25)
$Label6 = GUICtrlCreateLabel("名称", 16, 120, 52, 17)
$Label9 = GUICtrlCreateLabel("零售价", 424, 112, 40, 17)
$Label11 = GUICtrlCreateLabel("数量", 752, 112, 28, 17)
$Input5 = GUICtrlCreateInput("", 72, 112, 105, 21)
$Input8 = GUICtrlCreateInput("", 488, 112, 73, 21)
$ListView2 = GUICtrlCreateListView("名称|数量|总价(元)", 24, 352, 945, 241)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events")
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button2
GUICtrlSetState ( $ListView1, $GUI_FOCUS )
$mc=GUICtrlRead($input5)
$jg=GUICtrlRead($input8)
$num=GUICtrlRead($input10)
GUICtrlCreateListViewItem($mc & "|" & $num& "|" & $num * $jg, $ListView2)
GUICtrlSetData($Input10, "")
EndSwitch
WEnd
Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam)
#forceref $hWndGUI, $MsgID, $wParam
Local $NMHDR, $NMLVDISPINFO, $NMLISTVIEW, $event
$NMHDR = DllStructCreate($tagNMHDR, $lParam)
$event = DllStructGetData($NMHDR, 'Code')
If $hWndGUI = $Form1 And $wParam = $ListView1 Then
Select
Case $LVN_ITEMCHANGED
$NMLISTVIEW = DllStructCreate($tagNMLISTVIEW, $lParam)
If BitAND(DllStructGetData($NMLISTVIEW, "Changed"), $LVIF_STATE) = $LVIF_STATE And _
DllStructGetData($NMLISTVIEW, "NewState") <> DllStructGetData($NMLISTVIEW, "OldState") Then OnStateChange()
EndSelect
EndIf
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_Notify_Events
Func OnStateChange()
$cur_sel = _GUICtrlListView_GetNextItem($ListView1) ; current selected
$count_sel = _GUICtrlListView_GetSelectedCount($ListView1)
$count = _GUICtrlListView_GetItemCount($ListView1)
$iIndex = GUICtrlRead($ListView1)
;$ItemText = GUICtrlRead($iIndex)
If ($iIndex) Then
$ItemText = GUICtrlRead($iIndex)
; MsgBox(0, '项目文本:', $ItemText)
$array = StringSplit($ItemText, '|', 1)
;For $i= 1 To $array-1
;MsgBox(0,"",$array[$i])
GUICtrlSetData($Input5, $array)
GUICtrlSetData($Input8,$array)
;Next
EndIf
;GUICtrlSetData($status1, 'Current selected: ' & $cur_sel & ' Total selected: ' & $count_sel & ' Total items: ' & $count)
EndFunc ;==>OnStateChange 过来
,学习,学习。 收下了,谢谢.... 以后真该开个专门讲中文语法的板块了,居然越来越看不明白提问者的问题了,唉! 回复 4# netegg
我说的还不明白? 回复 5# king8462
不用按TAB,点击或改变LISTVIEW1中的项目时直接输入数量,回车加入LISTVIEW2.
具体内容看代码.
#NoTrayIcon
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstants.au3>
#include <GUIListView.au3>
#include <Array.au3>
#Include <GuiEdit.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("form1", 1000, 600, -1, -1)
$ListView1 = GUICtrlCreateListView("简码|名称|零售价(元)", 24, 160, 945, 177)
GUICtrlCreateListViewItem("xb|雪碧|3.0", $ListView1)
GUICtrlCreateListViewItem("kkkl|可口可乐|3.1", $ListView1)
GUICtrlCreateListViewItem("glc|果粒橙|3.2", $ListView1)
GUICtrlCreateListViewItem("fd|芬达|3.3", $ListView1)
$Input10 = _GUICtrlEdit_Create($Form1,"", 800, 112, 89, 21,$ES_NUMBER)
$Button2 = GUICtrlCreateButton("确定", 912, 112, 57, 25,$BS_DEFPUSHBUTTON)
$Label6 = GUICtrlCreateLabel("名称", 16, 120, 52, 17)
$Label9 = GUICtrlCreateLabel("零售价", 424, 112, 40, 17)
$Label11 = GUICtrlCreateLabel("数量", 752, 112, 28, 17)
$Input5 = GUICtrlCreateInput("", 72, 112, 105, 21)
$Input8 = GUICtrlCreateInput("", 488, 112, 73, 21)
$ListView2 = GUICtrlCreateListView("名称|数量|总价(元)", 24, 352, 945, 241)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events")
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button2
GUICtrlSetState($ListView1, $GUI_FOCUS)
$mc = GUICtrlRead($Input5)
$jg = GUICtrlRead($Input8)
$num = _GUICtrlEdit_GetText($Input10)
GUICtrlCreateListViewItem($mc & "|" & $num & "|" & $num * $jg, $ListView2)
GUICtrlSetData($Input10, "")
EndSwitch
WEnd
Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam)
#forceref $hWndGUI, $MsgID, $wParam
Local $hWndFrom,$hWndListView1,$NMHDR, $NMLVDISPINFO, $NMLISTVIEW, $event
$hWndListView = $ListView1
If Not IsHWnd($ListView1) Then $hWndListView = GUICtrlGetHandle($ListView1)
$NMHDR = DllStructCreate($tagNMHDR, $lParam)
$event = DllStructGetData($NMHDR, 'Code')
$hWndFrom = HWnd(DllStructGetData($NMHDR, "hWndFrom"))
Switch $hWndFrom
Case $hWndListView
Switch $event
Case $LVN_ITEMCHANGED
$NMLISTVIEW = DllStructCreate($tagNMLISTVIEW, $lParam)
If BitAND(DllStructGetData($NMLISTVIEW, "Changed"), $LVIF_STATE) = $LVIF_STATE And _
DllStructGetData($NMLISTVIEW, "NewState") <> DllStructGetData($NMLISTVIEW, "OldState") Then OnStateChange()
Case $LVN_KEYDOWN
$tInfo = DllStructCreate($tagNMLVKEYDOWN, $lParam)
If DllStructGetData($tInfo, "VKey")>0x2F And DllStructGetData($tInfo, "VKey")<0x3A Then _GUICtrlEdit_AppendText($Input10,DllStructGetData($tInfo, "VKey")-0x30)
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_Notify_Events
Func OnStateChange()
$cur_sel = _GUICtrlListView_GetNextItem($ListView1) ; current selected
_GUICtrlEdit_SetText ($Input10,"")
GUICtrlSetData($Input5,_GUICtrlListView_GetItemText($ListView1,$cur_sel,1))
GUICtrlSetData($Input8,_GUICtrlListView_GetItemText($ListView1,$cur_sel,2))
EndFunc ;==>OnStateChange
回复 5# king8462
不是说的不明白,是控件结构太乱,看不大清楚 回复 7# netegg
源程序是访问本地服务器的,实例是我修改的(由于涉及商业内容),有些控件删除了,所以看着乱点。 回复 6# 3mile
谢谢!
还有个小问题,小键盘的数字无法输入,不知道原因为何? 请 3mile帮忙再解决下啊! 回复 10# king8462
#NoTrayIcon
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstants.au3>
#include <GUIListView.au3>
#include <Array.au3>
#include <GuiEdit.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("form1", 1000, 600, -1, -1)
$ListView1 = GUICtrlCreateListView("简码|名称|零售价(元)", 24, 160, 945, 177)
GUICtrlCreateListViewItem("xb|雪碧|3.0", $ListView1)
GUICtrlCreateListViewItem("kkkl|可口可乐|3.1", $ListView1)
GUICtrlCreateListViewItem("glc|果粒橙|3.2", $ListView1)
GUICtrlCreateListViewItem("fd|芬达|3.3", $ListView1)
$Input10 = _GUICtrlEdit_Create($Form1, "", 800, 112, 89, 21, $ES_NUMBER)
$Button2 = GUICtrlCreateButton("确定", 912, 112, 57, 25, $BS_DEFPUSHBUTTON)
$Label6 = GUICtrlCreateLabel("名称", 16, 120, 52, 17)
$Label9 = GUICtrlCreateLabel("零售价", 424, 112, 40, 17)
$Label11 = GUICtrlCreateLabel("数量", 752, 112, 28, 17)
$Input5 = GUICtrlCreateInput("", 72, 112, 105, 21)
$Input8 = GUICtrlCreateInput("", 488, 112, 73, 21)
$ListView2 = GUICtrlCreateListView("名称|数量|总价(元)", 24, 352, 945, 241)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events")
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button2
GUICtrlSetState($ListView1, $GUI_FOCUS)
$mc = GUICtrlRead($Input5)
$jg = GUICtrlRead($Input8)
$num = _GUICtrlEdit_GetText($Input10)
GUICtrlCreateListViewItem($mc & "|" & $num & "|" & $num * $jg, $ListView2)
GUICtrlSetData($Input10, "")
EndSwitch
WEnd
Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam)
#forceref $hWndGUI, $MsgID, $wParam
Local $hWndFrom, $hWndListView1, $NMHDR, $NMLVDISPINFO, $NMLISTVIEW, $event
$hWndListView = $ListView1
If Not IsHWnd($ListView1) Then $hWndListView = GUICtrlGetHandle($ListView1)
$NMHDR = DllStructCreate($tagNMHDR, $lParam)
$event = DllStructGetData($NMHDR, 'Code')
$hWndFrom = HWnd(DllStructGetData($NMHDR, "hWndFrom"))
Switch $hWndFrom
Case $hWndListView
Switch $event
Case $LVN_ITEMCHANGED
$NMLISTVIEW = DllStructCreate($tagNMLISTVIEW, $lParam)
If BitAND(DllStructGetData($NMLISTVIEW, "Changed"), $LVIF_STATE) = $LVIF_STATE And _
DllStructGetData($NMLISTVIEW, "NewState") <> DllStructGetData($NMLISTVIEW, "OldState") Then OnStateChange()
Case $LVN_KEYDOWN
$tInfo = DllStructCreate($tagNMLVKEYDOWN, $lParam)
$Key=DllStructGetData($tInfo, "VKey")
Switch $Key
Case 0x30 To 0x39
_GUICtrlEdit_AppendText($Input10, DllStructGetData($tInfo, "VKey") - 0x30)
Case 0x60 to 0x69
_GUICtrlEdit_AppendText($Input10, DllStructGetData($tInfo, "VKey") - 0x60)
EndSwitch
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_Notify_Events
Func OnStateChange()
$cur_sel = _GUICtrlListView_GetNextItem($ListView1) ; current selected
_GUICtrlEdit_SetText($Input10, "")
GUICtrlSetData($Input5, _GUICtrlListView_GetItemText($ListView1, $cur_sel, 1))
GUICtrlSetData($Input8, _GUICtrlListView_GetItemText($ListView1, $cur_sel, 2))
EndFunc ;==>OnStateChange
本帖最后由 powerofos 于 2011-8-22 23:25 编辑
佩服3mile~~
雷锋精神,治病救人~~
看了下楼主的东东,估计是个记录批发饮料的东东?或者是简单的饮料进出仓管理器?
个人觉得input10的输入激活,使用hotkeyset占有个组合键较为稳妥,这样即使listview不是焦点状态下也可以快速向input10输入数量。 膜拜3mile.... 再次感谢! 还是很不错的噢,,顶起来的
http://www.baiuh.com/xzs1.jpg
页:
[1]
2