|
本帖最后由 anythinging 于 2021-4-14 13:53 编辑
各位朋友 ,我在编辑listview表格时遇到个问题,其中有几个表格内容比较多,需要独立弹出窗口再加载listview进入编辑等操作,在新窗口中弹出菜单操作正常,但通过icombo编辑的时候会无法定位到新弹出的listview中。尝试过更改创建icombo在主窗口或子窗口置等方法没有效果。
最后在新弹出的窗口创建并调用icombo2解决了,想求证下是此方法是否够正规,另请教教科书的方法?谢谢!
问题代码:编辑listview2时无法定位#NoTrayIcon
#include <WinAPI.au3>
#include <WinAPIEx.au3>
#include <TreeViewConstants.au3>
#include <GuiMenu.au3>
#include <GuiListView.au3>
#include <GuiStatusBar.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $hGui, $hGuiSub
Global $hGui, $ListView1, $hListView1, $ListView2, $hListView2, $aItem, $iInput, $iCombo,$iCombo2
Global $hMenu
Opt("GUIOnEventMode", 1)
CreateGUI()
;~ CreateGUISub2()
Func CreateGUI()
$hGui = GUICreate("主窗口", 1200, 600, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_SIZEBOX))
GUISetOnEvent($GUI_EVENT_CLOSE, "_EXIT")
GUISetState()
Local $idTreeview = GUICtrlCreateTreeView(2, 3, 200, 400, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
Local $idTreeviewA1 = GUICtrlCreateTreeViewItem("TreeA1", $idTreeview)
GUICtrlSetOnEvent(-1, 'TreeA1')
Local $idTreeviewA2 = GUICtrlCreateTreeViewItem("TreeA2", $idTreeview)
GUICtrlSetOnEvent(-1, 'TreeA2')
Local $id1 = GUICtrlCreateDummy()
GUICtrlSetOnEvent(-1, '_UdpData')
Local $aAccelKeys[1][2] = [['{Enter}', $id1]]
GUISetAccelerators($aAccelKeys)
Dim $iCombo = GUICtrlCreateCombo('', -100, -100)
Dim $iCombo2 = GUICtrlCreateCombo('', -100, -100)
GUIRegisterMsg(0x004E, '_WM_NOTIFY') ;$WM_NOTIFY = 0x004E
Local $context = GUICtrlCreateContextMenu(GUICtrlCreateDummy())
Dim $hMenu = GUICtrlGetHandle($context)
GUICtrlCreateMenuItem('男', $context)
GUICtrlCreateMenuItem('女', $context)
EndFunc ;==>CreateGUI
Func CreateGUISub1();------------------------- 子窗口 1 ------------------------------
$hGuiSub = GUICreate("子窗口1", 1000, 600, 201, 1, $WS_CHILD, $WS_EX_CLIENTEDGE, $hGui)
GUISetBkColor(0x4682B4)
GUISetState()
GUISetOnEvent($GUI_EVENT_CLOSE, "_Sub1Close")
_ListView1()
EndFunc ;==>CreateGUISub1
Func CreateGUISub2();------------------------- 子窗口 2 ------------------------------
$hGuiSub = GUICreate("子窗口2", 1000, 600, -1,-1)
GUISetBkColor(0x4682B4)
GUISetState()
GUISetOnEvent($GUI_EVENT_CLOSE, "_Sub1Close")
_ListView2()
EndFunc ;==>CreateGUISub1
While 1
Sleep(10)
WEnd
Func TreeA1()
If IsArray($aItem) Then
_UdpData()
EndIf
;~ GUIDelete($hGuiSub)
;~ GUISetState(@SW_DISABLE,$hGui)
CreateGUISub1()
EndFunc ;==>TreeA1
Func TreeA2()
If IsArray($aItem) Then
_UdpData()
EndIf
;~ GUIDelete($hGuiSub)
GUISetState(@SW_DISABLE,$hGui)
CreateGUISub2()
EndFunc ;==>TreeA2
Func _ListView1()
Dim $ListView1 = GUICtrlCreateListView('用户名1 | 密码1 |性别|管理', 1, 2, 596, 350)
Dim $hListView1 = GUICtrlGetHandle(-1)
For $i = 1 To 10
GUICtrlCreateListViewItem('' & $i & '|111111|男|删除', $ListView1)
Next
EndFunc ;==>_ListView1
Func _ListView2()
Dim $ListView2 = GUICtrlCreateListView('用户名2 | 密码2 |性别|管理', 1, 2, 596, 350)
Dim $hListView2 = GUICtrlGetHandle(-1)
For $i = 1 To 10
GUICtrlCreateListViewItem('' & $i & '|222222|女|删除', $ListView2)
Next
EndFunc ;==>_ListView2
Func _Sub1Close()
GUISetState(@SW_ENABLE,$hGui)
GUIDelete($hGuiSub)
EndFunc ;==>_Sub1Close
Func _UdpData()
If Not IsArray($aItem) Then Return
Local $sRd = GUICtrlRead($iCombo), $sData = ''
_GUICtrlListView_SetItemText($hListView1, $aItem[0], $sRd, $aItem[1])
GUICtrlSetPos($iCombo, -1000, -100)
Dim $aItem = 0
EndFunc ;==>_UdpData
Func _WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch DllStructGetData($tNMHDR, 'hWndFrom')
Case $hListView1
Switch $iCode
Case -2 ;$NM_CLICK = -2
If IsArray($aItem) Then
_UdpData()
EndIf
Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
Local $index = DllStructGetData($tInfo, 'Index')
Local $SubItem = DllStructGetData($tInfo, 'SubItem')
If $SubItem = 2 Then
Local $iid = _GUICtrlMenu_TrackPopupMenu($hMenu, $hGui, -1, -1, 1, 1, 2)
If $iid Then _GUICtrlListView_SetItemText($hListView1, $index, _GUICtrlMenu_GetItemText($hMenu, $iid, False), 2)
EndIf
Case -3 ;$NM_DBLCLK = -3
Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
Local $index = DllStructGetData($tInfo, 'Index')
Local $SubItem = DllStructGetData($tInfo, 'SubItem')
Dim $aItem = 0
Local $aRect = _GUICtrlListView_GetSubItemRect($hListView1, $index, $SubItem)
Dim $aItem[2] = [$index, $SubItem]
Local $sDef ;设置菜单
Global $sData = _GUICtrlListView_GetItemText($hListView1, $index, $SubItem)
GUICtrlSetPos($iCombo, $aRect[0] + 204, $aRect[1] + 8, $aRect[2] - $aRect[0])
GUICtrlSetData($iCombo, '|' & $sData, $sData)
GUICtrlSetState($iCombo, 256)
EndSwitch
Case $hListView2
Switch $iCode
Case -2 ;$NM_CLICK = -2
If IsArray($aItem) Then
_UdpData()
EndIf
Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
Local $index = DllStructGetData($tInfo, 'Index')
Local $SubItem = DllStructGetData($tInfo, 'SubItem')
If $SubItem = 2 Then
Local $iid = _GUICtrlMenu_TrackPopupMenu($hMenu, $hGui, -1, -1, 1, 1, 2)
If $iid Then _GUICtrlListView_SetItemText($hListView2, $index, _GUICtrlMenu_GetItemText($hMenu, $iid, False), 2)
EndIf
Case -3 ;$NM_DBLCLK = -3
Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
Local $index = DllStructGetData($tInfo, 'Index')
Local $SubItem = DllStructGetData($tInfo, 'SubItem')
Dim $aItem = 0
Local $aRect = _GUICtrlListView_GetSubItemRect($hListView2, $index, $SubItem)
Dim $aItem[2] = [$index, $SubItem]
Local $sDef = ('1|2|3') ;设置菜单
Global $sData = _GUICtrlListView_GetItemText($hListView2, $index, $SubItem)
GUICtrlSetPos($iCombo, $aRect[0] + 4, $aRect[1] + 2, $aRect[2] - $aRect[0])
GUICtrlSetData($iCombo, '|' & $sData&'|'&$sDef , $sData)
GUICtrlSetState($iCombo, 256)
EndSwitch
EndSwitch
EndFunc ;==>_WM_NOTIFY
Func _Exit()
Exit
EndFunc ;==>_Exit
解决代码求证:使用icombo2#NoTrayIcon
#include <WinAPI.au3>
#include <WinAPIEx.au3>
#include <TreeViewConstants.au3>
#include <GuiMenu.au3>
#include <GuiListView.au3>
#include <GuiStatusBar.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $hGui, $hGuiSub
Global $hGui, $ListView1, $hListView1, $ListView2, $hListView2, $aItem, $iInput, $iCombo,$iCombo2
Global $hMenu
Opt("GUIOnEventMode", 1)
CreateGUI()
;~ CreateGUISub2()
Func CreateGUI()
$hGui = GUICreate("主窗口", 1200, 600, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_SIZEBOX))
GUISetOnEvent($GUI_EVENT_CLOSE, "_EXIT")
GUISetState()
Local $idTreeview = GUICtrlCreateTreeView(2, 3, 200, 400, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
Local $idTreeviewA1 = GUICtrlCreateTreeViewItem("TreeA1", $idTreeview)
GUICtrlSetOnEvent(-1, 'TreeA1')
Local $idTreeviewA2 = GUICtrlCreateTreeViewItem("TreeA2", $idTreeview)
GUICtrlSetOnEvent(-1, 'TreeA2')
Local $id1 = GUICtrlCreateDummy()
GUICtrlSetOnEvent(-1, '_UdpData')
Local $aAccelKeys[1][2] = [['{Enter}', $id1]]
GUISetAccelerators($aAccelKeys)
Dim $iCombo = GUICtrlCreateCombo('', -100, -100)
GUIRegisterMsg(0x004E, '_WM_NOTIFY') ;$WM_NOTIFY = 0x004E
Local $context = GUICtrlCreateContextMenu(GUICtrlCreateDummy())
Dim $hMenu = GUICtrlGetHandle($context)
GUICtrlCreateMenuItem('男', $context)
GUICtrlCreateMenuItem('女', $context)
EndFunc ;==>CreateGUI
Func CreateGUISub1();------------------------- 子窗口 1 ------------------------------
$hGuiSub = GUICreate("子窗口1", 1000, 600, 201, 1, $WS_CHILD, $WS_EX_CLIENTEDGE, $hGui)
GUISetBkColor(0x4682B4)
GUISetState()
GUISetOnEvent($GUI_EVENT_CLOSE, "_Sub1Close")
_ListView1()
EndFunc ;==>CreateGUISub1
Func CreateGUISub2();------------------------- 子窗口 2 ------------------------------
$hGuiSub = GUICreate("子窗口2", 1000, 600, -1,-1)
GUISetBkColor(0x4682B4)
GUISetState()
GUISetOnEvent($GUI_EVENT_CLOSE, "_Sub1Close")
Dim $iCombo2 = GUICtrlCreateCombo('', -100, -100)
_ListView2()
EndFunc ;==>CreateGUISub1
While 1
Sleep(10)
WEnd
Func TreeA1()
If IsArray($aItem) Then
_UdpData()
EndIf
;~ GUIDelete($hGuiSub)
;~ GUISetState(@SW_DISABLE,$hGui)
CreateGUISub1()
EndFunc ;==>TreeA1
Func TreeA2()
If IsArray($aItem) Then
_UdpData()
EndIf
;~ GUIDelete($hGuiSub)
GUISetState(@SW_DISABLE,$hGui)
CreateGUISub2()
EndFunc ;==>TreeA2
Func _ListView1()
Dim $ListView1 = GUICtrlCreateListView('用户名1 | 密码1 |性别|管理', 1, 2, 596, 350)
Dim $hListView1 = GUICtrlGetHandle(-1)
For $i = 1 To 10
GUICtrlCreateListViewItem('' & $i & '|111111|男|删除', $ListView1)
Next
EndFunc ;==>_ListView1
Func _ListView2()
Dim $ListView2 = GUICtrlCreateListView('用户名2 | 密码2 |性别|管理', 1, 2, 596, 350)
Dim $hListView2 = GUICtrlGetHandle(-1)
For $i = 1 To 10
GUICtrlCreateListViewItem('' & $i & '|222222|女|删除', $ListView2)
Next
EndFunc ;==>_ListView2
Func _Sub1Close()
GUISetState(@SW_ENABLE,$hGui)
GUIDelete($hGuiSub)
EndFunc ;==>_Sub1Close
Func _UdpData()
If Not IsArray($aItem) Then Return
Local $sRd = GUICtrlRead($iCombo), $sData = ''
_GUICtrlListView_SetItemText($hListView1, $aItem[0], $sRd, $aItem[1])
GUICtrlSetPos($iCombo, -1000, -100)
Dim $aItem = 0
EndFunc ;==>_UdpData
Func _WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch DllStructGetData($tNMHDR, 'hWndFrom')
Case $hListView1
Switch $iCode
Case -2 ;$NM_CLICK = -2
If IsArray($aItem) Then
_UdpData()
EndIf
Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
Local $index = DllStructGetData($tInfo, 'Index')
Local $SubItem = DllStructGetData($tInfo, 'SubItem')
If $SubItem = 2 Then
Local $iid = _GUICtrlMenu_TrackPopupMenu($hMenu, $hGui, -1, -1, 1, 1, 2)
If $iid Then _GUICtrlListView_SetItemText($hListView1, $index, _GUICtrlMenu_GetItemText($hMenu, $iid, False), 2)
EndIf
Case -3 ;$NM_DBLCLK = -3
Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
Local $index = DllStructGetData($tInfo, 'Index')
Local $SubItem = DllStructGetData($tInfo, 'SubItem')
Dim $aItem = 0
Local $aRect = _GUICtrlListView_GetSubItemRect($hListView1, $index, $SubItem)
Dim $aItem[2] = [$index, $SubItem]
Local $sDef ;设置菜单
Global $sData = _GUICtrlListView_GetItemText($hListView1, $index, $SubItem)
GUICtrlSetPos($iCombo, $aRect[0] + 204, $aRect[1] + 8, $aRect[2] - $aRect[0])
GUICtrlSetData($iCombo, '|' & $sData, $sData)
GUICtrlSetState($iCombo, 256)
EndSwitch
Case $hListView2
Switch $iCode
Case -2 ;$NM_CLICK = -2
If IsArray($aItem) Then
_UdpData()
EndIf
Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
Local $index = DllStructGetData($tInfo, 'Index')
Local $SubItem = DllStructGetData($tInfo, 'SubItem')
If $SubItem = 2 Then
Local $iid = _GUICtrlMenu_TrackPopupMenu($hMenu, $hGui, -1, -1, 1, 1, 2)
If $iid Then _GUICtrlListView_SetItemText($hListView2, $index, _GUICtrlMenu_GetItemText($hMenu, $iid, False), 2)
EndIf
Case -3 ;$NM_DBLCLK = -3
Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
Local $index = DllStructGetData($tInfo, 'Index')
Local $SubItem = DllStructGetData($tInfo, 'SubItem')
Dim $aItem = 0
Local $aRect = _GUICtrlListView_GetSubItemRect($hListView2, $index, $SubItem)
Dim $aItem[2] = [$index, $SubItem]
Local $sDef = ('1|2|3') ;设置菜单
Global $sData = _GUICtrlListView_GetItemText($hListView2, $index, $SubItem)
GUICtrlSetPos($iCombo2, $aRect[0] + 4, $aRect[1] + 2, $aRect[2] - $aRect[0])
GUICtrlSetData($iCombo2, '|' & $sData&'|'&$sDef , $sData)
GUICtrlSetState($iCombo2, 256)
EndSwitch
EndSwitch
EndFunc ;==>_WM_NOTIFY
Func _Exit()
Exit
EndFunc ;==>_Exit
|
|