找回密码
 加入
搜索
查看: 5389|回复: 13

[AU3基础] 请问一段代码怎样弄成GUI?

  [复制链接]
发表于 2015-5-22 23:38:24 | 显示全部楼层 |阅读模式
现有一段显示MAC代码,由于最后使用msgbox显示结果,不能改变字体大小,所以想用GUI输出,新手看了一晚教程还是不会,请问各位高手应该怎样做?
--------------------------附代码---------------------
$sky=mac()

Func mac()
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"
$Output=""
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled != 0", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
If IsObj($colItems) then
   For $objItem In $colItems
      $Output1 = $Output & "" & $objItem.MACAddress & @CRLF
   Next
Return $Output1
Else
Endif
EndFunc

MsgBox(0,"物理地址查看器","本机物理地址为:   "&StringReplace($sky,":",""))
------------------------------------------------------------------------------------------------
发表于 2015-5-23 00:17:55 | 显示全部楼层
本帖最后由 luren666 于 2015-5-23 00:20 编辑

#cs ----------------------------------------------------------------------------

AutoIt Version: 3.3.6.1
Author:         myName

Script Function:
        Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
#include <GUIConstantsEx.au3>
$sky=mac()
Example()

Func Example()
        Local $font, $msg

        GUICreate("My GUI") ; will create a dialog box that when displayed is centered

        $font = "Comic Sans MS"
        GUICtrlCreateLabel($sky, 10, 20)
        GUICtrlSetFont(-1, 9, 400, 4, $font) ; will display underlined characters
       

        GUISetState() ; will display an empty dialog box

        ; Run the GUI until the dialog is closed
        While 1
                $msg = GUIGetMsg()

                If $msg = $GUI_EVENT_CLOSE Then ExitLoop
        WEnd
EndFunc   ;==>Example



Func mac()
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"
$Output=""
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled != 0", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
If IsObj($colItems) then
   For $objItem In $colItems
      $Output1 = $Output & "" & $objItem.MACAddress & @CRLF
   Next
Return $Output1
Else
Endif
EndFunc
****************************************

从示例里面便找了一段代码,跟你的代码组合到一起,具体的效果您自己研究吧。睡觉了。
 楼主| 发表于 2015-5-23 13:08:00 | 显示全部楼层
回复 2# luren666


    非常感谢。
 楼主| 发表于 2015-5-23 13:23:06 | 显示全部楼层
回复 2# luren666


非常感谢,不过自己研究了一下还是不会弄,能否帮忙弄成这样?

字体:宋体 20px;
MAC地址不要用冒号间隔,用文本框控件输出,因为这样方便复制。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2015-5-23 16:10:07 | 显示全部楼层
自己看帮助文件吧,有很多种方法可以实现的。比如替换冒号后再更新输入框什么的。
发表于 2015-5-23 16:10:22 | 显示全部楼层
自己看帮助文件吧,有很多种方法可以实现的。比如替换冒号后再更新输入框什么的。
发表于 2015-5-23 22:49:52 | 显示全部楼层
回复 4# q4369

修改一下:

#include <GUIConstantsEx.au3>
$sky = mac()
Example()
Func Example()
        Local $font, $msg
        $Form1 = GUICreate("物理地址查看器", 230, 50,-1,-1)
        $Input1 = GUICtrlCreateInput("", 105, 10, 100, 17)
        $skya = StringReplace($sky, ":", "")       
        GUICtrlSetData($Input1, $skya)
        $Label = GUICtrlCreateLabel("本机物理地址为: ", 10, 14, 95, 20)
        GUISetState()
        While 1
                $msg = GUIGetMsg()
                If $msg = $GUI_EVENT_CLOSE Then ExitLoop
        WEnd
EndFunc   ;==>Example
Func mac()
        $wbemFlagReturnImmediately = 0x10
        $wbemFlagForwardOnly = 0x20
        $colItems = ""
        $strComputer = "localhost"
        $Output = ""
        $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
        $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled != 0", "WQL", _
                        $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
        If IsObj($colItems) Then
                For $objItem In $colItems
                        $Output1 = $Output & "" & $objItem.MACAddress & @CRLF
                Next
                Return $Output1
        Else
        EndIf
EndFunc   ;==>mac
发表于 2015-5-24 16:10:55 | 显示全部楼层
#include <GUIConstantsEx.au3>
#Include <Clipboard.au3>

$sky=mac()
_ClipBoard_SetData(StringReplace($sky,":",""));;将MAC地址存入剪贴板,无冒号
Example($sky)  ;;;显示的时候带冒号

Func Example($mac)
        Local $font, $msg

        GUICreate("My GUI",250,170) ; will create a dialog box that when displayed is centered

        $font = "宋体"
        
        GUICtrlCreateLabel("本机MAC地址为:", 10,20,230,40)  ;;标签
        GUICtrlSetFont(-1, 20, 300, 0, $font) ; 设置标签的字体
        
        GUICtrlCreateInput($mac, 10,60,230,40) ;创建一个输入框
        GUICtrlSetFont(-1, 20, 300, 0, $font) ; 输入框的字体
        
        $OKButton = GUICtrlCreateButton("确  定",60,120,120,35)  ;;按钮
        GUICtrlSetFont(-1, 20, 300, 0, $font) ;按钮字体
        GUISetState() 

        While 1
                $msg = GUIGetMsg()

                If $msg = $GUI_EVENT_CLOSE Or $msg = $OKButton Then ExitLoop
        WEnd
EndFunc


Func mac()
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"
$Output=""
$objWMIService = ObjGet("winmgmts:\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled != 0", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
If IsObj($colItems) then
   For $objItem In $colItems
      $Output1 = $Output & "" & $objItem.MACAddress & @CRLF
   Next
Return $Output1
Else
Endif
EndFunc
楼主能不能自己多看看帮助文档,这么简单的问题,稍微看一下就明白了。
发表于 2015-5-27 15:39:05 | 显示全部楼层
代码都有了,弄个GUI倒不会?
发表于 2015-5-28 16:13:28 | 显示全部楼层
可以先生成gui,再放代码进去,,不是有个gui编辑器吗
发表于 2015-5-29 09:39:50 | 显示全部楼层
回复 8# luren666


    win7表示不能运行
>"D:\Autoit3\SciTE\ACNWrapper\ACNWrapper.exe" /run /ErrorStdOut /in "L:\au3\test\MAC.au3" /autoit3dir "D:\Autoit3" /UserParams    
+>09:37:31 开始执行 ACNWrapper v.1.0.1.2
+> ============================================
+>执行环境:
+>        CPU构架:        X64
+>        系统构架:        X86
+>        系统语言:        0804
+>        键盘布局:        00000804
+>        内存总量:        3553MB
+>        内存剩余:        2006MB
+>        操作系统:        WIN_7/Service Pack 1
+>        AU3版本:        3.3.9.0
+> ============================================
>运行 AU3Check (1.54.23.0)  开始目录:D:\Autoit3
+>09:37:31 AU3Check 完成[CODE]:0
>运行:(3.3.9.0):D:\Autoit3\autoit3.exe "L:\au3\test\MAC.au3"    
"L:\au3\test\MAC.au3" (40) : ==> ?????????? ')'.:
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled != 0", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
$colItems = ^ ERROR
->09:37:31 AutoIT3.exe 完成:[CODE]:1
+>09:37:33 ACNWrapper 完成..
>退出代码: 1        运行时间: 2.198 秒
发表于 2015-5-29 11:45:51 | 显示全部楼层
本帖最后由 不是小灵通 于 2015-5-29 12:48 编辑

帖子和下面的发重了,删掉一个
发表于 2015-5-29 11:47:00 | 显示全部楼层
本帖最后由 不是小灵通 于 2015-5-29 12:50 编辑

额,还不止重了一个呢
俗话说论坛抽风
发表于 2015-5-29 11:47:07 | 显示全部楼层
不知道楼主是不是只需要完成MAC获取,我刚接触AU3不久,试了下,有些部分还不会做
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ACN_NET.au3>
#include <GuiEdit.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("获取本机MAC地址", 439, 183, 650, 288)
$Label1 = GUICtrlCreateLabel("本机物理地址为:", 24, 16, 220, 31)
GUICtrlSetFont(-1, 20, 400, 0, "宋体")
$Edit1 = GUICtrlCreateEdit("", 24, 56, 393, 49, BitOR($GUI_SS_DEFAULT_EDIT,$ES_CENTER))
GUICtrlSetData(-1, "")
GUICtrlSetFont(-1, 20, 400, 0, "宋体")
$Button1 = GUICtrlCreateButton("确定",32 , 120, 137, 41)
$Button2 = GUICtrlCreateButton("复制", 272, 120, 161, 41)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        $a=_API_Get_NetworkAdapterMAC (@IPAddress1)
                        $MAC=StringMid($a,1,2) &StringMid($a,4,2)&StringMid($a,7,2)&StringMid($a,10,2)&StringMid($a,13,2)&StringMid($a,16,2)
                        _GUICtrlEdit_AppendText($Edit1, $MAC)
                        
                Case $Button2
                        MsgBox(0,"哈哈","我也是刚学AU3的菜鸟,不会复制文本框内容,请指点!"& @CRLF & "还有文本框的滚动条也不知道如何去掉")
        EndSwitch
WEnd
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-4-28 15:42 , Processed in 0.086171 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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