【已解决】关于独立窗口使用combo组件编辑listview表格的问题
本帖最后由 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 = [['{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, $sRd, $aItem)
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 = [$index, $SubItem]
Local $sDef ;设置菜单
Global $sData = _GUICtrlListView_GetItemText($hListView1, $index, $SubItem)
GUICtrlSetPos($iCombo, $aRect + 204, $aRect + 8, $aRect - $aRect)
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 = [$index, $SubItem]
Local $sDef = ('1|2|3') ;设置菜单
Global $sData = _GUICtrlListView_GetItemText($hListView2, $index, $SubItem)
GUICtrlSetPos($iCombo, $aRect + 4, $aRect + 2, $aRect - $aRect)
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 = [['{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, $sRd, $aItem)
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 = [$index, $SubItem]
Local $sDef ;设置菜单
Global $sData = _GUICtrlListView_GetItemText($hListView1, $index, $SubItem)
GUICtrlSetPos($iCombo, $aRect + 204, $aRect + 8, $aRect - $aRect)
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 = [$index, $SubItem]
Local $sDef = ('1|2|3') ;设置菜单
Global $sData = _GUICtrlListView_GetItemText($hListView2, $index, $SubItem)
GUICtrlSetPos($iCombo2, $aRect + 4, $aRect + 2, $aRect - $aRect)
GUICtrlSetData($iCombo2, '|' & $sData&'|'&$sDef , $sData)
GUICtrlSetState($iCombo2, 256)
EndSwitch
EndSwitch
EndFunc ;==>_WM_NOTIFY
Func _Exit()
Exit
EndFunc ;==>_Exit
anythinging 发表于 2021-4-11 19:26
由于之前没学过编程基础,是从0开始学au3,不知有多少我这样的朋友?
现在总是缺乏信心,多谢各位的指点! ...
我就是0基础 每次点击树TreeA1 都会创建一次子窗口1及其列表,点多少次创建多少次……老问题多次提醒,不再重复解释。
创建子窗口2之后,虽然新建了$iCombo2 没问题,但 _UdpData 都是1的数据,回车也不会响应。
之前给你的例子,listview是设置了字体的,实质是为了约束ComboBox坐标,可能在你自己的电脑看不出问题。
还有在第一列弹出的ComboBox宽度也不对,这些之前都有示例,可惜……
问题不少。 本帖最后由 anythinging 于 2021-4-11 15:44 编辑
afan 发表于 2021-4-11 15:21
每次点击树TreeA1 都会创建一次子窗口1及其列表,点多少次创建多少次……老问题多次提醒,不再重复解释。 ...
感谢回复,我发的是精简下来的代码,主要是表现listview在新生成的窗口中双击修改定位的情况原代码的treeA1,treeA2打开前会删除之前的子窗口,再新建一个同名子窗口及加载listview
update部份没改,我尝试解决下
第一列弹出的宽度问题,之前您特意指点过,暂时没加上去 本帖最后由 anythinging 于 2021-4-11 16:39 编辑
这个是我更新过的代码
1、更新updata,支持2个listview回车确认,用了2个$aAccelKeys分别实现2个listvew的响应,是否有更好的方法?
2、座标修正
3、双击第1列屏蔽(偷懒了,实际 使用中我把第1列设置为序号了,就不需要修改了)
4、之前都是用的子窗口+表格,想请教同时有子窗口+表格 和独立窗口+表格的情况下,能否只用一个icombo?
5、Dim $iCombo = GUICtrlCreateCombo('', -100, -100)和$aAccelKeys = 这2句代码是否是只在主窗口及子gui中生效?
更正代码如下
#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
Global $num
Opt("GUIOnEventMode", 1)
CreateGUI()
CreateGUISub1()
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 = [['{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")
Dim $iCombo = GUICtrlCreateCombo('', -100, -100)
_ListView1()
$num = 1
EndFunc ;==>CreateGUISub
Func CreateGUISub2();------------------------- 子窗口 2 ------------------------------
$hGuiSub = GUICreate("子窗口2", 1000, 600, -1,-1)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Sub1Close")
GUISetBkColor(0x4682B4)
GUISetState()
Local $id2 = GUICtrlCreateDummy()
GUICtrlSetOnEvent(-1, '_UdpData')
Local $aAccelKeys = [['{Enter}', $id2]]
GUISetAccelerators($aAccelKeys)
Dim $iCombo2 = GUICtrlCreateCombo('', -100, -100)
_ListView2()
$num = 2
EndFunc ;==>CreateGUISub
While 1
Sleep(10)
WEnd
Func TreeA1()
If IsArray($aItem) Then
_UdpData()
EndIf
GUIDelete($hGuiSub)
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
Switch $num
Case 1
Local $sRd = GUICtrlRead($iCombo), $sData = ''
_GUICtrlListView_SetItemText($hListView1, $aItem, $sRd, $aItem)
GUICtrlSetPos($iCombo, -1000, -100)
Case 2
Local $sRd = GUICtrlRead($iCombo2), $sData = ''
_GUICtrlListView_SetItemText($hListView2, $aItem, $sRd, $aItem)
GUICtrlSetPos($iCombo2, -1000, -100)
EndSwitch
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')
If $SubItem = 0 Then Return
Dim $aItem = 0
Local $aRect = _GUICtrlListView_GetSubItemRect($hListView1, $index, $SubItem)
Dim $aItem = [$index, $SubItem]
Local $sDef ;设置菜单
Global $sData = _GUICtrlListView_GetItemText($ListView1, $index, $SubItem)
GUICtrlSetPos($iCombo, $aRect + 4, $aRect + 8, $aRect - $aRect)
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')
If $SubItem = 0 Then Return
Dim $aItem = 0
Local $aRect = _GUICtrlListView_GetSubItemRect($hListView2, $index, $SubItem)
Dim $aItem = [$index, $SubItem]
Local $sDef = ('1|2|3') ;设置菜单
Global $sData = _GUICtrlListView_GetItemText($hListView2, $index, $SubItem)
GUICtrlSetPos($iCombo2, $aRect + 4, $aRect + 2, $aRect - $aRect)
GUICtrlSetData($iCombo2, '|' & $sData&'|'&$sDef , $sData)
GUICtrlSetState($iCombo2, 256)
EndSwitch
EndSwitch
EndFunc ;==>_WM_NOTIFY
Func _Exit()
Exit
EndFunc ;==>_Exit
1、更新updata,支持2个listview回车确认,用了2个$aAccelKeys分别实现2个listvew的响应,是否有更好的方法?
没有更好的方法(定义为函数调用也行),独立的窗口都要单独设置快捷键。
3、双击第1列屏蔽(偷懒了,实际 使用中我把第1列设置为序号了,就不需要修改了)
屏蔽是正解,不需要的操作一定要拦截。
4、之前都是用的子窗口+表格,想请教同时有子窗口+表格 和独立窗口+表格的情况下,能否只用一个icombo?
控件不能跨窗口单独显示。为什么要只用一个?
5、Dim $iCombo = GUICtrlCreateCombo('', -100, -100)和$aAccelKeys = 这2句代码是否是只在主窗口及子gui中生效?
上贴的问题还没搞清楚?GUICtrlCreate* 一定要有窗口,没有窗口单独创建控件一定会失败。如果你进行某个操作时新创建了窗口,之后关闭时又删除了该窗口,此时任何GUICtrlCreate*都会失败。它可不会自行找到主窗口去创建,需要你指定,比如用 GUISwitch(主窗口) afan 发表于 2021-4-11 18:48
1、更新updata,支持2个listview回车确认,用了2个$aAccelKeys分别实现2个listvew的响应,是否有更好 ...
请教A版四楼的代码没什么大问题了吧?想以后我就当模板用了 anythinging 发表于 2021-4-11 19:18
请教A版四楼的代码没什么大问题了吧?想以后我就当模板用了
问题我基本上在上面都提到了,解决了当然可以。
符合自己的编程习惯就不错 由于之前没学过编程基础,是从0开始学au3,不知有多少我这样的朋友?
现在总是缺乏信心,多谢各位的指点!给我继续学习下去的勇气 其实还有一件事挺担忧的,指点问题的基本就是A版、chzj589等少数,如果没有几位的指点,象我这种新人可以说是寸步难行,恐怕早早放弃了。
祝论坛的所有朋友都开开心心,笑口常开!
本帖最后由 anythinging 于 2021-4-11 21:32 编辑
请教A版,有个疑惑的地方不理解,就是弹出菜单是正常的。它是创建在主gui或其子gui1中,而在新建的gui2中却能正常调用,只有icombo的下拉菜单不行。开始就是因为这个地方,让我以为是icombo的下拉菜单问题是调用的方法不对,还请解惑。
Local $context = GUICtrlCreateContextMenu(GUICtrlCreateDummy())
Dim $hMenu = GUICtrlGetHandle($context)
GUICtrlCreateMenuItem('男', $context)
GUICtrlCreateMenuItem('女', $context)
Local $iid = _GUICtrlMenu_TrackPopupMenu($hMenu, $hGui, -1, -1, 1, 1, 2)
If $iid Then _GUICtrlListView_SetItemText($hListView1, $index, _GUICtrlMenu_GetItemText($hMenu, $iid, False), 2)
Local $iid = _GUICtrlMenu_TrackPopupMenu($hMenu, $hGui, -1, -1, 1, 1, 2)
If $iid Then _GUICtrlListView_SetItemText($hListView2, $index, _GUICtrlMenu_GetItemText($hMenu, $iid, False), 2)
我测试了下,发现反复调用会有问题,开始2个窗口都能弹出 ,但最终会只有一个窗口能弹出。是否验证了控件只对应一个窗口及其子窗口?
弹出菜单更适合用弹出窗口来描述,它不是常规的控件。
ComboBox 是下拉列表,列表(List) 和 菜单(Menu) 是完全不同类别的东西 感谢指点,虽然 不明白其中道 理,但要学的东西确实很多。 anythinging 发表于 2021-4-11 19:34
其实还有一件事挺担忧的,指点问题的基本就是A版、chzj589等少数,如果没有几位的指点,象我这种新人可以说 ...
想学就要有信心,你的基础应该不会比我低。
说一点我的想法,象你的例子,列表1测试己通过。复制列表1的代码建立新代码,在SciTE编辑器打开,点击编辑器的<搜索>下拉<替换>,把$Listview1全部替换$Listview2,然后测试运行情况。这样那里有问题就方便修改解决。
运行通过后,两个代码再合并。新增代码也这样操作。
页:
[1]