找回密码
 加入
搜索
查看: 7281|回复: 12

[AU3基础] [已解决]怎样获取到多个U盘盘符?帮忙修改下代码

 火.. [复制链接]
发表于 2011-5-17 12:44:57 | 显示全部楼层 |阅读模式
本帖最后由 515276542 于 2011-5-19 08:39 编辑

怎样获取到多个U盘盘符?
现在插着两个U盘也只能获取到一个U盘的盘符,帮忙修改下代码
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 294, 187, 192, 124)
$Edit1 = GUICtrlCreateEdit("", 16, 16, 265, 113)
GUICtrlSetBkColor($Edit1,0xFFFFFF)
GUICtrlSetState($Edit1, $GUI_DISABLE)
GUICtrlSetData(-1, "")
$Button1 = GUICtrlCreateButton("获取U盘", 152, 152, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
        Case $Button1
                        move()
        EndSwitch
WEnd

Func move()
        $zi = "  已连接的设备盘符为 ==>  "
        $drive = DriveGetDrive( "REMOVABLE" );获取一个含有指定驱动器盘符, "REMOVABLE(可移动驱动器)"
        If Not @error Then
                For $i = 1 to $drive[0]
                        $daxie = StringUpper($drive[$i]);将小写盘符转换大写
                        GUICtrlSetData ( $Edit1,$zi & $daxie);修改指定控件的数据,$Edit2是那个输入框
;~                     MsgBox(64,"发现设备","已连接的设备盘符为  " & $daxie,"",$Form1);显示一个简单的对话框
                Next
        Else
                MsgBox(16,"警告!","未发现有U盘。","",$Form1);显示一个简单的对话框
        EndIf
EndFunc

评分

参与人数 1金钱 +10 收起 理由
tryhi + 10

查看全部评分

发表于 2011-5-17 12:58:01 | 显示全部楼层
第31行改为:_GUICtrlEdit_AppendText($Edit1,@crlf&$zi&$daxie)
发表于 2011-5-17 13:13:41 | 显示全部楼层
标记下。。。。。。。。。。。
 楼主| 发表于 2011-5-17 15:49:46 | 显示全部楼层
回复 2# 3mile

能不能只显示一次26行那个提示啊?
发表于 2011-5-18 10:44:26 | 显示全部楼层
回复  3mile

能不能只显示一次26行那个提示啊?
515276542 发表于 2011-5-17 15:49

完全听不懂你说的一次26行是什么意思.请解释
 楼主| 发表于 2011-5-18 14:55:35 | 显示全部楼层
本帖最后由 515276542 于 2011-5-18 17:02 编辑

回复 5# 3mile


就是说现在改了之后在GUICtrlCreateEdit的控件里显示

     已连接的设备盘符为 ==>  H:
     已连接的设备盘符为 ==>  I:

能不能改成

    已连接的设备盘符为 ==>  H: I:

发表于 2011-5-18 17:53:32 | 显示全部楼层
回复 6# 515276542
变通下即可:
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 294, 187, 192, 124)
$Edit1 = GUICtrlCreateEdit("", 16, 16, 265, 113)
GUICtrlSetBkColor($Edit1, 0xFFFFFF)
GUICtrlSetState($Edit1, $GUI_DISABLE)
GUICtrlSetData(-1, "")
$Button1 = GUICtrlCreateButton("获取U盘", 152, 152, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        move()
        EndSwitch
WEnd

Func move()
        $zi = "  已连接的设备盘符为 ==>  "
        $drive = DriveGetDrive("REMOVABLE");获取一个含有指定驱动器盘符, "REMOVABLE(可移动驱动器)"
        If Not @error Then
                Local $daxie = ""
                For $i = 1 To $drive[0]
                        $daxie &= StringUpper($drive[$i]) & Chr(32);将小写盘符转换大写
                Next
                GUICtrlSetData($Edit1, $zi & $daxie);修改指定控件的数据,$Edit2是那个输入框
        Else
                MsgBox(16, "警告!", "未发现有U盘。", "", $Form1);显示一个简单的对话框
        EndIf
EndFunc   ;==>move

评分

参与人数 1金钱 +20 贡献 +2 收起 理由
tryhi + 20 + 2

查看全部评分

 楼主| 发表于 2011-5-19 18:12:37 | 显示全部楼层
回复 7# 3mile


    谢谢啦
发表于 2011-12-17 18:35:13 | 显示全部楼层
代码收下了!
发表于 2012-10-16 09:57:41 | 显示全部楼层
很好用的代码
发表于 2012-10-16 11:04:41 | 显示全部楼层
好用的代码
发表于 2012-10-19 23:52:52 | 显示全部楼层
好用的代码
发表于 2015-8-29 11:46:49 | 显示全部楼层
代码收下了,记下。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-28 20:15 , Processed in 0.103117 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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