找回密码
 加入
搜索
查看: 3918|回复: 5

[AU3基础] 两种方法都完美实现不了左边框复制到左边框的代码(已解决)

[复制链接]
发表于 2011-11-12 22:19:07 | 显示全部楼层 |阅读模式
本帖最后由 sour 于 2011-11-15 23:18 编辑

代码一只能一个一个复制,如果东西多了就很坑爹,但是又不知道怎么让他停留在上次选的下面
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 432, 341, 192, 114)
$List1 = GUICtrlCreateList("11", 96, 32, 73, 201)
$List2 = GUICtrlCreateList("6", 224, 32, 73, 201)
$Button1 = GUICtrlCreateButton("添加>>", 176, 48, 41, 25, $WS_GROUP)
$Button2 = GUICtrlCreateButton("<<添加", 176, 88, 41, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
GUICtrlSetData($List1, "123")
GUICtrlSetData($List1, "1kj")
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        If GUICtrlRead($List1) <> '' Then
                                GUICtrlSetData($List2, GUICtrlRead($List1))
                                _GUICtrlListBox_DeleteString($List1, _GUICtrlListBox_GetCurSel($List1))
                                                        ControlClick("","","[CLASS:ListBox; INSTANCE:1]","left",1,12, 10)
                                                        
                                                        EndIf
                                Case $Button2
                        If GUICtrlRead($List2) <> '' Then
                                GUICtrlSetData($List1, GUICtrlRead($List2))
                                _GUICtrlListBox_DeleteString($List2, _GUICtrlListBox_GetCurSel($List2))
                                                        ControlClick("","","[CLASS:ListBox; INSTANCE:1]","left",1,12, 10)
                        EndIf
        EndSwitch
WEnd
方法2可以多选,左边拉到右边,右边再拉回来就不会删除了,看起来是
$totalnum = _GUICtrlListView_GetItemCount($list1)
的问题
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 432, 341, 192, 114)
$aStyles = BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)
$list1 = GUICtrlCreateListView("名称", 96, 32, 73, 201, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
$list2 = GUICtrlCreateListView("名称", 224, 32, 73, 201, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
;_GUICtrlListView_SetExtendedListViewStyle($list1, $aStyles)
;_GUICtrlListView_SetView($list1, "0")
GUICtrlSetBkColor($list1, 0xffffff)

$Button1 = GUICtrlCreateButton("添加>>", 176, 48, 41, 25, $WS_GROUP)
$Button2 = GUICtrlCreateButton("<<添加", 176, 88, 41, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
 $listteam = GUICtrlCreateListViewItem ("222",$list1)
  ;GUICtrlSetImage($listteam, "shell32.dll", 5)
  $listteam = GUICtrlCreateListViewItem ("333",$list1)
   ;GUICtrlSetImage($listteam, "shell32.dll", 5)
   $listteam = GUICtrlCreateListViewItem ("444",$list1)
    $listteam = GUICtrlCreateListViewItem ("44432",$list1)
         $listteam = GUICtrlCreateListViewItem ("4443",$list1)
          $listteam = GUICtrlCreateListViewItem ("444333",$list1)
            $listteam = GUICtrlCreateListViewItem ("44432",$list2)
         $listteam = GUICtrlCreateListViewItem ("4443",$list2)
          $listteam = GUICtrlCreateListViewItem ("444333",$list2)
    ;GUICtrlSetImage($listteam, "shell32.dll", 5)
        
While 1
        $nMsg = GUIGetMsg ()
        Switch $nMsg
                Case -3
                        Exit
                Case $button1
                        $totalnum = _GUICtrlListView_GetItemCount($list1)
                        $selectcount = _GUICtrlListView_GetSelectedCount($list1)
                        $out = ""
                        For $i = 0 To $totalnum-1
                                If  $selectcount Then
                                        If _GUICtrlListView_GetItemSelected($list1, $i) == True Then
                                          _GUICtrlListView_CopyItems($list1, $list2, 1)


                                        EndIf
                                Else
                                     
                                EndIf
                        Next
                    
                                Case $button2
                        $totalnum = _GUICtrlListView_GetItemCount($list2)
                        $selectcount = _GUICtrlListView_GetSelectedCount($list2)
                        $out = ""
                        For $i = 0 To $totalnum-1
                                If  $selectcount Then
                                        If _GUICtrlListView_GetItemSelected($list2, $i) == True Then
                                                  _GUICtrlListView_CopyItems($list2, $list1, 1)

                                        EndIf
                                Else
                                     
                                EndIf
                        Next
                      
        EndSwitch        
        WEnd
弄得那么复杂,用js好容易啊
发表于 2011-11-12 23:14:03 | 显示全部楼层
多看多学多思。
 楼主| 发表于 2011-11-13 08:55:05 | 显示全部楼层
这个谁有现成的思路么....
这个代码应该很常用才对,不过help里面的太复杂,应该有简单的才对
 楼主| 发表于 2011-11-15 21:07:06 | 显示全部楼层
update一下,有人帮忙么
 楼主| 发表于 2011-11-15 22:00:55 | 显示全部楼层
自己解决了一下,看起来还凑合
就是代码需要那么复杂么
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 432, 341, 192, 114)
$List1 = GUICtrlCreateList("11", 96, 32, 73, 201)
$List2 = GUICtrlCreateList("6", 224, 32, 73, 201)
$Button1 = GUICtrlCreateButton("添加>>", 176, 48, 41, 25, $WS_GROUP)
$Button2 = GUICtrlCreateButton("<<添加", 176, 88, 41, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
GUICtrlSetData($List1, "123")
GUICtrlSetData($List1, "1kj")
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        If GUICtrlRead($List1) <> '' Then
                                GUICtrlSetData($List2, GUICtrlRead($List1))
                                                                ; $iIndex = _GUICtrlListBox_FindString($hListBox, "exa")
    ;_GUICtrlListBox_SetCurSel($hListBox, $iIndex)
                                 $Index=_GUICtrlListBox_GetCurSel($List1)
                                _GUICtrlListBox_DeleteString($List1, $index)
                                                                If $index > 0 Then
                                                                _GUICtrlListBox_ClickItem($list1, $Index-1)
                                                        Else
                                                                _GUICtrlListBox_ClickItem($list1, 0)
                                                                EndIf
                                                        ;ControlClick("","","[CLASS:ListBox; INSTANCE:1]","left",1,12, 10)
                                                        
                                                        EndIf
                                Case $Button2
                        If GUICtrlRead($List2) <> '' Then
                                GUICtrlSetData($List1, GUICtrlRead($List2))
                                                                  $Index=_GUICtrlListBox_GetCurSel($List2)
                                _GUICtrlListBox_DeleteString($List2, $index)
                                                                If $index > 0 Then
                                                                _GUICtrlListBox_ClickItem($list2, $Index-1)
                                                        Else
                                                                _GUICtrlListBox_ClickItem($list2, 0)
                                                                EndIf
                        EndIf
        EndSwitch
WEnd
 楼主| 发表于 2011-11-15 23:19:34 | 显示全部楼层
本帖最后由 sour 于 2011-11-15 23:48 编辑

多选出错的原因是for 的排列要从大到小,否则就会删除错误....
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
Local $sItems, $aItems, $hListBox
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 432, 341, 192, 114)
$List1 = GUICtrlCreateList("11", 96, 32, 73, 201, BitOR($GUI_SS_DEFAULT_LIST, $LBS_MULTIPLESEL))
$List2 = GUICtrlCreateList("6", 224, 32, 73, 201, BitOR($GUI_SS_DEFAULT_LIST, $LBS_MULTIPLESEL))
$Button1 = GUICtrlCreateButton("添加>>", 176, 48, 41, 25, $WS_GROUP)
$Button2 = GUICtrlCreateButton("<<添加", 176, 88, 41, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
GUICtrlSetData($List1, "123")
GUICtrlSetData($List1, "1kj")
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        $aItems = _GUICtrlListBox_GetSelItemsText($List1)
                        For $iI = 1 To $aItems[0]
                                GUICtrlSetData($List2, $aItems[$iI])
                        Next
                        $aItems = _GUICtrlListBox_GetSelItems($List1)
                        For $iI = $aItems[0] To 1 Step -1
                                _GUICtrlListBox_DeleteString($List1, $aItems[$iI])
                        Next
                        If $aItems[1] > 0 Then
                                _GUICtrlListBox_ClickItem($List1, $aItems[1] - 1)
                        Else
                                _GUICtrlListBox_ClickItem($List1, 0)
                        EndIf



                        
                Case $Button2
                        $aItems = _GUICtrlListBox_GetSelItemsText($List2)
                        For $iI = 1 To $aItems[0]
                                GUICtrlSetData($List1, $aItems[$iI])
                        Next
                        $aItems = _GUICtrlListBox_GetSelItems($List2)
                        For $iI = $aItems[0] To 1 Step -1
                                _GUICtrlListBox_DeleteString($List2, $aItems[$iI])
                        Next
                        If $aItems[1] > 0 Then
                                _GUICtrlListBox_ClickItem($List2, $aItems[1] - 1)
                        Else
                                _GUICtrlListBox_ClickItem($List2, 0)
                        EndIf
        EndSwitch
WEnd
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-3-29 18:31 , Processed in 0.081905 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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