|
发表于 2021-4-11 13:31:22
|
|
本帖最后由 anythinging 于 2021-4-14 13:53 编辑
各位朋友 ,我在编辑listview表格时遇到个问题,其中有几个表格内容比较多,需要独立弹出窗口再加载listview进入编辑等操作,在新窗口中弹出菜单操作正常,但通过icombo编辑的时候会无法定位到新弹出的listview中。尝试过更改创建icombo在主窗口或子窗口置等方法没有效果。
最后在新弹出的窗口创建并调用icombo2解决了,想求证下是此方法是否够正规,另请教教科书的方法?谢谢!
问题代码:编辑listview2时无法定位
- #notrayicon
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- 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
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- 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
复制代码
|
|