找回密码  加入

AUTOIT CN

搜索
查看: 221|回复: 1

[GUI管理] 自己已解决 如何向上或向下移动所选控件

[复制链接]
发表于 2018-10-2 19:01:19 | 显示全部楼层 |阅读模式
本帖最后由 Mixrelax 于 2018-10-2 22:30 编辑
  1. #include <ButtonConstants.au3>
  2. #include <GUIConstantsEx.au3>
  3. #include <GuiListView.au3>
  4. #include <ListViewConstants.au3>
  5. #include <WindowsConstants.au3>
  6. Opt("GUIOnEventMode", 1)
  7. Global $text = GUICreate("测试", 516, 198, 278, 184, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_WINDOWEDGE))
  8. GUISetBkColor(0xA6CAF0)
  9. GUISetOnEvent($GUI_EVENT_CLOSE, "textClose")
  10. GUISetOnEvent($GUI_EVENT_DROPPED, "dropped")
  11. Global $File_ListView = GUICtrlCreateListView("名称|路径", 38, 21, 364, 150, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
  12. GUICtrlSetBkColor(-1, 0xC0DCC0)
  13. GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)
  14. GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 50)
  15. GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKMENUBAR) ;设置控件的大小调整方式
  16. GUICtrlSetState(-1, $GUI_DROPACCEPTED)
  17. _GUICtrlListView_SetColumnWidth($File_ListView, 0, 100)
  18. _GUICtrlListView_SetColumnWidth($File_ListView, 1, 150)
  19. $menu_C = GUICtrlCreateContextMenu($File_ListView) ;创建上下文菜单(右键)
  20. $menu_Remove_Item = GUICtrlCreateMenuItem("删除指定行[&Z]", $menu_C) ;创建一个菜单项目控件
  21. GUICtrlSetOnEvent(-1, "menu_Remove_ItemClick")
  22. $menu_Empty = GUICtrlCreateMenuItem("清空列表[&Q]", $menu_C) ;创建一个菜单项目控件
  23. GUICtrlSetLimit(-1, 4)
  24. GUICtrlSetOnEvent(-1, "menu_EmptyClick")
  25. Global $up = GUICtrlCreateButton("向上移动", 417, 42, 72, 41)
  26. GUICtrlSetFont(-1, 9, 400, 0, "新宋体")
  27. GUICtrlSetOnEvent(-1, "upClick")
  28. Global $down = GUICtrlCreateButton("向下移动", 417, 113, 72, 41)
  29. GUICtrlSetFont(-1, 9, 400, 0, "新宋体")
  30. GUICtrlSetOnEvent(-1, "downClick")
  31. GUISetState(@SW_SHOW)
  32. #EndRegion ### END Koda GUI section ###
  33. Global $aDroppedFiles[1]
  34. Global Const $TME_CANCEL = 0x80000000
  35. Global Const $TME_HOVER = 0x00000001
  36. Global Const $TME_LEAVE = 0x00000002
  37. Global Const $TME_NONCLIENT = 0x00000010
  38. Global Const $TME_QUERY = 0x40000000
  39. GUIRegisterMsg($WM_DROPFILES, "WM_DROPFILES")

  40. While 1
  41.         Sleep(100)
  42. WEnd

  43. Func downClick() ;向下移动
  44. ;~ DoSomething
  45. EndFunc   ;==>downClick

  46. Func upClick() ;向上移动
  47. ;~ DoSomething

  48. EndFunc   ;==>upClick


  49. Func menu_Remove_ItemClick()
  50.         _GUICtrlListView_DeleteItemsSelected(GUICtrlGetHandle($File_ListView)) ;删除指定行
  51. EndFunc   ;==>menu_Remove_ItemClick
  52. Func menu_EmptyClick()
  53.         _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($File_ListView)) ;清空列表
  54. EndFunc   ;==>menu_EmptyClick

  55. Func dropped() ;文件拖放结束
  56.         For $i = 1 To UBound($aDroppedFiles) - 1
  57.                 $file = StringSplit($aDroppedFiles[$i], "")
  58.                 $file = $file[$file[0]]
  59.                 GUICtrlCreateListViewItem($file & "|" & $aDroppedFiles[$i], $File_ListView)
  60.         Next
  61.         GUICtrlSendMsg($File_ListView, $LVM_SETCOLUMNWIDTH, 0, -1)
  62. EndFunc   ;==>dropped

  63. Func WM_DROPFILES($hWnd, $msgID, $wParam, $lParam)
  64.         Local $nSize, $pFileName
  65.         Local $nAmt = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", 0xFFFFFFFF, "ptr", 0, "int", 255)

  66.         $aDroppedFiles = 0
  67.         Dim $aDroppedFiles[$nAmt[0] + 1]

  68.         For $i = 0 To $nAmt[0] - 1
  69.                 $nSize = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", 0, "int", 0)
  70.                 $nSize = $nSize[0] + 1
  71.                 $pFileName = DllStructCreate("char[" & $nSize & "]")
  72.                 DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", _
  73.                                 DllStructGetPtr($pFileName), "int", $nSize)
  74.                 $aDroppedFiles[0] += 1
  75.                 $aDroppedFiles[$aDroppedFiles[0]] = DllStructGetData($pFileName, 1)
  76.                 $pFileName = 0
  77.         Next
  78.         ReDim $aDroppedFiles[$aDroppedFiles[0] + 1]
  79. EndFunc   ;==>WM_DROPFILES

  80. Func textClose() ;关闭窗体
  81.         Exit
  82. EndFunc   ;==>textClose
复制代码
  1. #include <ButtonConstants.au3>
  2. #include <GUIConstantsEx.au3>
  3. #include <GuiListView.au3>
  4. #include <ListViewConstants.au3>
  5. #include <WindowsConstants.au3>
  6. Opt("GUIOnEventMode", 1)
  7. Global $text = GUICreate("测试", 516, 198, 278, 184, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_WINDOWEDGE))
  8. GUISetBkColor(0xA6CAF0)
  9. GUISetOnEvent($GUI_EVENT_CLOSE, "textClose")
  10. GUISetOnEvent($GUI_EVENT_DROPPED, "dropped")
  11. Global $File_ListView = GUICtrlCreateListView("名称|路径", 38, 21, 364, 150, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
  12. GUICtrlSetBkColor(-1, 0xC0DCC0)
  13. GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)
  14. GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 50)
  15. GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKMENUBAR) ;设置控件的大小调整方式
  16. GUICtrlSetState(-1, $GUI_DROPACCEPTED)
  17. _GUICtrlListView_SetColumnWidth($File_ListView, 0, 100)
  18. _GUICtrlListView_SetColumnWidth($File_ListView, 1, 150)
  19. $menu_C = GUICtrlCreateContextMenu($File_ListView) ;创建上下文菜单(右键)
  20. $menu_Remove_Item = GUICtrlCreateMenuItem("删除指定行[&Z]", $menu_C) ;创建一个菜单项目控件
  21. GUICtrlSetOnEvent(-1, "menu_Remove_ItemClick")
  22. $menu_Empty = GUICtrlCreateMenuItem("清空列表[&Q]", $menu_C) ;创建一个菜单项目控件
  23. GUICtrlSetLimit(-1, 4)
  24. GUICtrlSetOnEvent(-1, "menu_EmptyClick")
  25. Global $up = GUICtrlCreateButton("向上移动", 417, 42, 72, 41)
  26. GUICtrlSetFont(-1, 9, 400, 0, "新宋体")
  27. GUICtrlSetOnEvent(-1, "upClick")
  28. Global $down = GUICtrlCreateButton("向下移动", 417, 113, 72, 41)
  29. GUICtrlSetFont(-1, 9, 400, 0, "新宋体")
  30. GUICtrlSetOnEvent(-1, "downClick")
  31. GUISetState(@SW_SHOW)
  32. Global $aDroppedFiles[1]
  33. Global Const $TME_CANCEL = 0x80000000
  34. Global Const $TME_HOVER = 0x00000001
  35. Global Const $TME_LEAVE = 0x00000002
  36. Global Const $TME_NONCLIENT = 0x00000010
  37. Global Const $TME_QUERY = 0x40000000
  38. GUIRegisterMsg($WM_DROPFILES, "WM_DROPFILES")

  39. While 1
  40.         Sleep(100)
  41. WEnd

  42. Func downClick() ;向下移动
  43.         $select_item_index = _GUICtrlListView_GetSelectionMark($File_ListView)
  44.         $select_item_index_text = _GUICtrlListView_GetItemTextString($File_ListView, $select_item_index)
  45.         If $select_item_index <>_GUICtrlListView_GetItemCount($File_ListView) Then
  46.                 _GUICtrlListView_DeleteItem($File_ListView, $select_item_index)
  47.                 $select_item_index = _GUICtrlListView_InsertItem($File_ListView, $select_item_index_text, $select_item_index + 1)
  48.                 _GUICtrlListView_ClickItem($File_ListView, $select_item_index, "left", False)
  49.         EndIf
  50. EndFunc   ;==>downClick

  51. Func upClick() ;向上移动
  52.         $select_item_index = _GUICtrlListView_GetSelectionMark($File_ListView)
  53.         $select_item_index_text = _GUICtrlListView_GetItemTextString($File_ListView, $select_item_index)
  54.         If $select_item_index <> 0 Then
  55.                 _GUICtrlListView_DeleteItem($File_ListView, $select_item_index)
  56.                 $select_item_index = _GUICtrlListView_InsertItem($File_ListView, $select_item_index_text, $select_item_index - 1)
  57.                 _GUICtrlListView_ClickItem($File_ListView, $select_item_index, "left", False)
  58.         EndIf
  59. EndFunc   ;==>upClick


  60. Func menu_Remove_ItemClick()
  61.         _GUICtrlListView_DeleteItemsSelected(GUICtrlGetHandle($File_ListView)) ;删除指定行
  62. EndFunc   ;==>menu_Remove_ItemClick
  63. Func menu_EmptyClick()
  64.         _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($File_ListView)) ;清空列表
  65. EndFunc   ;==>menu_EmptyClick

  66. Func dropped() ;文件拖放结束
  67.         For $i = 1 To UBound($aDroppedFiles) - 1
  68.                 $file = StringSplit($aDroppedFiles[$i], "")
  69.                 $file = $file[$file[0]]
  70.                 GUICtrlCreateListViewItem($file & "|" & $aDroppedFiles[$i], $File_ListView)
  71.         Next
  72.         GUICtrlSendMsg($File_ListView, $LVM_SETCOLUMNWIDTH, 0, -1)
  73. EndFunc   ;==>dropped

  74. Func WM_DROPFILES($hWnd, $msgID, $wParam, $lParam)
  75.         Local $nSize, $pFileName
  76.         Local $nAmt = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", 0xFFFFFFFF, "ptr", 0, "int", 255)

  77.         $aDroppedFiles = 0
  78.         Dim $aDroppedFiles[$nAmt[0] + 1]

  79.         For $i = 0 To $nAmt[0] - 1
  80.                 $nSize = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", 0, "int", 0)
  81.                 $nSize = $nSize[0] + 1
  82.                 $pFileName = DllStructCreate("char[" & $nSize & "]")
  83.                 DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", _
  84.                                 DllStructGetPtr($pFileName), "int", $nSize)
  85.                 $aDroppedFiles[0] += 1
  86.                 $aDroppedFiles[$aDroppedFiles[0]] = DllStructGetData($pFileName, 1)
  87.                 $pFileName = 0
  88.         Next
  89.         ReDim $aDroppedFiles[$aDroppedFiles[0] + 1]
  90. EndFunc   ;==>WM_DROPFILES

  91. Func textClose() ;关闭窗体
  92.         Exit
  93. EndFunc   ;==>textClose
复制代码
  1. Func downClick() ;向下移动
  2.         $select_item_index = _GUICtrlListView_GetSelectionMark($File_ListView)
  3.         $select_item_index_text = _GUICtrlListView_GetItemTextString($File_ListView, $select_item_index)
  4.         If $select_item_index <>_GUICtrlListView_GetItemCount($File_ListView) Then
  5.                 _GUICtrlListView_DeleteItem($File_ListView, $select_item_index)
  6.                 $select_item_index = _GUICtrlListView_InsertItem($File_ListView, $select_item_index_text, $select_item_index + 1)
  7.                 _GUICtrlListView_ClickItem($File_ListView, $select_item_index, "left", False)
  8.         EndIf
  9. EndFunc   ;==>downClick

  10. Func upClick() ;向上移动
  11.         $select_item_index = _GUICtrlListView_GetSelectionMark($File_ListView)
  12.         $select_item_index_text = _GUICtrlListView_GetItemTextString($File_ListView, $select_item_index)
  13.         If $select_item_index <> 0 Then
  14.                 _GUICtrlListView_DeleteItem($File_ListView, $select_item_index)
  15.                 $select_item_index = _GUICtrlListView_InsertItem($File_ListView, $select_item_index_text, $select_item_index - 1)
  16.                 _GUICtrlListView_ClickItem($File_ListView, $select_item_index, "left", False)
  17.         EndIf
  18. EndFunc   ;==>upClick
复制代码

发表于 2018-10-3 09:05:54 | 显示全部楼层
伟大领袖毛主席说过:自己动手,丰衣足食
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|小黑屋|手机版|AUTOIT CN ( 鲁ICP备15028933号-3 )谷歌 百度

GMT+8, 2018-12-10 05:31 , Processed in 0.081507 second(s), 14 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表