找回密码
 加入
搜索
查看: 1472|回复: 1

[网络通信] 自己已解决 如何向上或向下移动所选控件

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

While 1
        Sleep(100)
WEnd

Func downClick() ;向下移动
;~ DoSomething
EndFunc   ;==>downClick

Func upClick() ;向上移动
;~ DoSomething

EndFunc   ;==>upClick


Func menu_Remove_ItemClick()
        _GUICtrlListView_DeleteItemsSelected(GUICtrlGetHandle($File_ListView)) ;删除指定行
EndFunc   ;==>menu_Remove_ItemClick
Func menu_EmptyClick()
        _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($File_ListView)) ;清空列表
EndFunc   ;==>menu_EmptyClick

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

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

        $aDroppedFiles = 0
        Dim $aDroppedFiles[$nAmt[0] + 1]

        For $i = 0 To $nAmt[0] - 1
                $nSize = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", 0, "int", 0)
                $nSize = $nSize[0] + 1
                $pFileName = DllStructCreate("char[" & $nSize & "]")
                DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", _
                                DllStructGetPtr($pFileName), "int", $nSize)
                $aDroppedFiles[0] += 1
                $aDroppedFiles[$aDroppedFiles[0]] = DllStructGetData($pFileName, 1)
                $pFileName = 0
        Next
        ReDim $aDroppedFiles[$aDroppedFiles[0] + 1]
EndFunc   ;==>WM_DROPFILES

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

While 1
        Sleep(100)
WEnd

Func downClick() ;向下移动
        $select_item_index = _GUICtrlListView_GetSelectionMark($File_ListView)
        $select_item_index_text = _GUICtrlListView_GetItemTextString($File_ListView, $select_item_index)
        If $select_item_index <>_GUICtrlListView_GetItemCount($File_ListView) Then
                _GUICtrlListView_DeleteItem($File_ListView, $select_item_index)
                $select_item_index = _GUICtrlListView_InsertItem($File_ListView, $select_item_index_text, $select_item_index + 1)
                _GUICtrlListView_ClickItem($File_ListView, $select_item_index, "left", False)
        EndIf
EndFunc   ;==>downClick

Func upClick() ;向上移动
        $select_item_index = _GUICtrlListView_GetSelectionMark($File_ListView)
        $select_item_index_text = _GUICtrlListView_GetItemTextString($File_ListView, $select_item_index)
        If $select_item_index <> 0 Then
                _GUICtrlListView_DeleteItem($File_ListView, $select_item_index)
                $select_item_index = _GUICtrlListView_InsertItem($File_ListView, $select_item_index_text, $select_item_index - 1)
                _GUICtrlListView_ClickItem($File_ListView, $select_item_index, "left", False)
        EndIf
EndFunc   ;==>upClick


Func menu_Remove_ItemClick()
        _GUICtrlListView_DeleteItemsSelected(GUICtrlGetHandle($File_ListView)) ;删除指定行
EndFunc   ;==>menu_Remove_ItemClick
Func menu_EmptyClick()
        _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($File_ListView)) ;清空列表
EndFunc   ;==>menu_EmptyClick

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

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

        $aDroppedFiles = 0
        Dim $aDroppedFiles[$nAmt[0] + 1]

        For $i = 0 To $nAmt[0] - 1
                $nSize = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", 0, "int", 0)
                $nSize = $nSize[0] + 1
                $pFileName = DllStructCreate("char[" & $nSize & "]")
                DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", _
                                DllStructGetPtr($pFileName), "int", $nSize)
                $aDroppedFiles[0] += 1
                $aDroppedFiles[$aDroppedFiles[0]] = DllStructGetData($pFileName, 1)
                $pFileName = 0
        Next
        ReDim $aDroppedFiles[$aDroppedFiles[0] + 1]
EndFunc   ;==>WM_DROPFILES

Func textClose() ;关闭窗体
        Exit
EndFunc   ;==>textClose
Func downClick() ;向下移动
        $select_item_index = _GUICtrlListView_GetSelectionMark($File_ListView)
        $select_item_index_text = _GUICtrlListView_GetItemTextString($File_ListView, $select_item_index)
        If $select_item_index <>_GUICtrlListView_GetItemCount($File_ListView) Then
                _GUICtrlListView_DeleteItem($File_ListView, $select_item_index)
                $select_item_index = _GUICtrlListView_InsertItem($File_ListView, $select_item_index_text, $select_item_index + 1)
                _GUICtrlListView_ClickItem($File_ListView, $select_item_index, "left", False)
        EndIf
EndFunc   ;==>downClick

Func upClick() ;向上移动
        $select_item_index = _GUICtrlListView_GetSelectionMark($File_ListView)
        $select_item_index_text = _GUICtrlListView_GetItemTextString($File_ListView, $select_item_index)
        If $select_item_index <> 0 Then
                _GUICtrlListView_DeleteItem($File_ListView, $select_item_index)
                $select_item_index = _GUICtrlListView_InsertItem($File_ListView, $select_item_index_text, $select_item_index - 1)
                _GUICtrlListView_ClickItem($File_ListView, $select_item_index, "left", False)
        EndIf
EndFunc   ;==>upClick
发表于 2018-10-3 09:05:54 | 显示全部楼层
伟大领袖毛主席说过:自己动手,丰衣足食
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-11-16 15:39 , Processed in 0.073231 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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