回复 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
|