找回密码
 加入
搜索
查看: 9567|回复: 10

[GUI管理] 如何响应动态按钮的事件

  [复制链接]
发表于 2013-5-23 00:20:28 | 显示全部楼层 |阅读模式
悬赏100金钱已解决
本帖最后由 xyhqqaa 于 2013-5-23 00:53 编辑

新手求助,工作需要,想弄个小东东。获取局域网内电脑的共享文件夹列表。现在测试自己电脑可以获取到列表。但是只是增加按钮而已。无法点击按钮打开相应文件夹,有点郁闷。
求指教下。哪里错了。还有个两个小问题,点击确定按钮的时候,如果实现删除清空之前获取的按钮。因为如果再次按下确定,就会叠加按钮。。头疼!!最后一个是关于_Net_Share_ShareEnum
,帮助上写的是检索服务器上资源共享的信息,但实际上我只需要获取C$,D$,E$之类的硬盘盘符,像IPC$,共享文件夹之类的就不需要显示了。
_Net_Share_FileGetInfo检索服务器特定资源的信息,不知道如何应用!
。。。。不知道写这么多有没有大哥能理解俺的意思不。。。。。能帮忙给点方法,感激不尽!!


代码如下
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <NetShare.au3>
#region ### START Koda GUI section ### Form=
Local $server, $button[100]
Local $posx=0, $posy=1
;Opt("GUIOnEventMode", 1);启用EventMode
;GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "main")
$Form1 = GUICreate("Form1", 434, 507)
$Label = GUICtrlCreateLabel("计算机名:", 8, 16, 72, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Input = GUICtrlCreateInput("", 80, 16, 209, 21)
;$SERVER = GUICtrlRead($Input)
$OK = GUICtrlCreateButton("确定", 304, 16, 123, 25)
$Group = GUICtrlCreateGroup("", 8, 48, 417, 449)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState()
#endregion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                        $server = @ComputerName
                        $share = _Net_Share_ShareEnum($server)
                        $IPING = Ping($server, 250)
                        If $IPING = 0 Then MsgBox("", "", "连接错误,检测下网络啦!看自己网络有木有问题,或者对方网络有木有问题")
                        

                        For $i = 1 To $share[0][0]
                                If Mod($i, 6) = 0 And $i <> 0 Then
                                        $posx += 1
                                        $posy = 1
                                EndIf
                                
                                $button[$share[0][0]] = GUICtrlCreateButton($share[$i][0], 30 + $posx * 180, 75 * $posy - 15, 180, 30)
                        
                                ;GUICtrlSetOnEvent($button[$share[0][0]] , "main")
                                $posy += 1
                        Next
                        
        EndSwitch
WEnd

#cs
Func main()
        For $i = 1 To $share[0][0]
        Switch @GUI_CtrlId
        Case -3
        Exit
        Case $button[$share[$i][0]] 
        MsgBox(0, "第 " & $i & " 个按钮", "我是按钮 " & $i & " 号!", 0, $Form1)
        EndSwitch
        Next
EndFunc
#ce
附件: 您需要 登录 才可以下载或查看,没有账号?加入

最佳答案

查看完整内容

这种情况我比较喜欢用列表框。
发表于 2013-5-23 00:20:29 | 显示全部楼层
本帖最后由 shqf 于 2013-5-23 10:15 编辑

这种情况我比较喜欢用列表框。
#include <Array.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <NetShare.au3>
#include <GuiListBox.au3>

#region ### START Koda GUI section ### Form=
Local $server
$Form1 = GUICreate("Form1", 292, 260)
$Label = GUICtrlCreateLabel("计算机名:", 8, 16, 72, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Input = GUICtrlCreateInput("", 70, 16, 106, 20)
$OK = GUICtrlCreateButton("确定", 190, 14, 80, 25)
$Group = GUICtrlCreateGroup("共享目录", 8, 48, 274, 200)
$List1 = GUICtrlCreateList("", 16, 63, 161, 180)
$Button1 = GUICtrlCreateButton("打开", 190, 80, 80, 25)

GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState()
#endregion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $OK
                        $server = @ComputerName
                        $share = _Net_Share_ShareEnum($server)
                        ;_ArrayDisplay($share,'Debug~~~')
                        $IPING = Ping($server, 250)
                        If $IPING = 0 Then MsgBox("", "", "连接错误,检测下网络啦!看自己网络有木有问题,或者对方网络有木有问题")
                        _GUICtrlListBox_BeginUpdate($List1)
                        For $i = 1 To $share[0][0]
                                If $share[$i][1]="2147483648" Then 
                                _GUICtrlListBox_AddString($List1,$share[$i][0])
                                EndIf
                        Next
                        _GUICtrlListBox_EndUpdate($List1)

                Case $Button1
                        If GUICtrlRead($List1)="" Then
                                MsgBox(0,"","请选择共享目录!")
                        else
                                For $i = 1 To $share[0][0]
                                If $share[$i][0]=GUICtrlRead($List1) Then 
                                        ;$DMA = DriveMapAdd("", "\" & $server & "" & $share[$i][0], 0)
                                Run("Explorer.exe /e,/root,\" & $server & "" & $share[$i][0])
                                EndIf
                        Next
                        EndIf
        EndSwitch
WEnd

评分

参与人数 1金钱 +50 收起 理由
xyhqqaa + 50 good..帅气,简单。。我再慢慢修改下其他的 ...

查看全部评分

发表于 2013-5-23 01:29:17 | 显示全部楼层
用事件模式,很好解决~
这个钱我就不赚了 ^ ___ ^

评分

参与人数 1金钱 +10 收起 理由
xyhqqaa + 10 恩恩。AFAN哥确实要注意休息时间啦。。。熬 ...

查看全部评分

发表于 2013-5-23 06:26:53 | 显示全部楼层
发表于 4 小时前 | 只看该作者
用事件模式,很好解决~
这个钱我就不赚了 ^ ___ ^
版主,请注意休息

评分

参与人数 1金钱 +10 收起 理由
xyhqqaa + 10 嘻嘻。

查看全部评分

发表于 2013-5-23 07:06:06 | 显示全部楼层
这种不定个数的,用treeview应该是更好看,我没使用过treeview,不知道能不能够的

评分

参与人数 1金钱 +10 收起 理由
xyhqqaa + 10 哦哦。。。好像会比较好看点。。我去找点资 ...

查看全部评分

发表于 2013-5-23 08:53:49 | 显示全部楼层
删掉之前的,添加新的~
 楼主| 发表于 2013-5-23 10:59:32 | 显示全部楼层
回复 2# shqf

您好,请问下
    If $share[$i][1] = "2147483648" Then
怎么理解
发表于 2013-5-23 11:15:48 | 显示全部楼层
原按钮形式的
#include <NetShare.au3>

Opt('GUIOnEventMode', 1)

Local $aiBtn[100], $aShare, $iSL = 0
Local $posx = 0, $posy = 1

$hGui = GUICreate('Form1', 434, 507)
GUISetOnEvent(-3, '_Main')
GUICtrlCreateLabel('计算机名:', 8, 16, 72, 20)
GUICtrlSetFont(-1, 10, 400, 0, 'MS Sans Serif')
$iInput = GUICtrlCreateInput(@ComputerName, 80, 16, 209, 21)
GUICtrlCreateButton('确定', 304, 16, 123, 25)
GUICtrlSetOnEvent(-1, '_Crate')
$Group = GUICtrlCreateGroup('', 8, 48, 417, 449)
GUICtrlCreateGroup('', -99, -99, 1, 1)
_Crate()
GUISetState()

While 1
        Sleep(1000)
WEnd

Func _Crate()
        If $iSL > 0 Then _Del()
        $aShare = _Net_Share_ShareEnum(GUICtrlRead($iInput))
        If @error Then Return
        $iSL = $aShare[0][0]
        For $i = 1 To $iSL
                If Mod($i, 6) = 0 And $i <> 0 Then
                        $posx += 1
                        $posy = 1
                EndIf
                $aiBtn[$i] = GUICtrlCreateButton($aShare[$i][0], 30 + $posx * 180, 75 * $posy - 15, 180, 30)
                GUICtrlSetOnEvent(-1, '_Main')
                $posy += 1
        Next
EndFunc   ;==>_Crate

Func _Del()
        For $i = 1 To $iSL
                GUICtrlDelete($aiBtn[$i])
        Next
        Dim $posx = 0, $posy = 1
EndFunc   ;==>_Del

Func _Main()
        Switch @GUI_CtrlId
                Case -3
                        Exit
                Case $aiBtn[1] To $aiBtn[$iSL]
                        Local $ix = @GUI_CtrlId - $Group - 1
                        If MsgBox(1, '第 ' & $ix & ' 个按钮', $aShare[$ix][0] & @LF & '打开:' & $aShare[$ix][6], 0, $hGui) = 1 Then _
                                ShellExecute($aShare[$ix][6])
        EndSwitch
EndFunc   ;==>_Main

评分

参与人数 1金钱 +30 收起 理由
xyhqqaa + 30 A大都出手。辛苦您了,注意身体啦。。学习了 ...

查看全部评分

发表于 2013-5-23 12:40:20 | 显示全部楼层
本帖最后由 shqf 于 2013-5-23 12:44 编辑

回复 7# xyhqqaa


    为共享类型$STYPE_SPECIA(专用共享)的十进制值。共享类型与其十六进制值对应如下,可以组合:
$STYPE_DISKTREE = 0x00000000
$STYPE_PRINTQ = 0x00000001
$STYPE_DEVICE = 0x00000002
$STYPE_IPC = 0x00000003
$STYPE_TEMPORARY = 0x40000000
$STYPE_SPECIAL = 0x80000000
最好第2 行(磁盘驱动器)与第6行(专用共享)进行组合

评分

参与人数 1金钱 +10 收起 理由
xyhqqaa + 10 谢谢您,我好好学习下,。谢谢

查看全部评分

发表于 2013-5-25 13:54:41 | 显示全部楼层
进来看看谁领钱的!
发表于 2013-5-29 11:58:46 | 显示全部楼层
居然有人敢领钱啊。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-4-28 18:36 , Processed in 0.084405 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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