刚来,放上我的第一个脚本作品!

这个作品首发在http://www.mybat.cn/站点上
具体配置文件请见本人作品http://www.mybat.cn/viewthread.php?tid=4612
http://www.autoit.net.cn/viewthread.php?tid=725&extra=page%3D2
大家可以关注哈!
这里只放代码,供对au3脚本技术感兴趣的朋友参考学习!
样本图:
代码如下:

#include <WindowsConstants.au3>
#include <GUIConstants.au3>
#include <StaticConstants.au3>
#Include <GuiList.au3>
#include <Sound.au3>
Opt
("GUIOneventMode", 1)

#cs
    脚本给我的感觉就像“吃大锅饭”
,别有滋味!
    为了新手学习,我尽量把注释写具体一点!
    代码尽量模块化,方便扩展利用!
#ce

;;------------
begin
()
;;---------------

;首先,面板的建立--可借用KODA设计
;生成三个面板并初始化隐藏状态
Global 
$gui_1 = _GuiDragableCreate("", 317, 202, -1, -1);创建欢迎界面面板
Global 
$ax_flash = ObjCreate("ShockwaveFlash.ShockwaveFlash.1")
Global 
$GUIActiveX = GUICtrlCreateObj($ax_flash, 6, 6, 302, 187)
GUISetState
(@SW_HIDE)
;-------
Global 
$music_tool_1 = _GuiDragableCreate("歌曲播放设置", 280, 454, 620, 260);歌曲设置面板
Global 
$Input_url = GUICtrlCreateInput("", 0, 120, 177, 21)
Global 
$play_url = GUICtrlCreateButton("添加URL(播放)", 184, 120, 89, 25, 0)
Global 
$Edit = GUICtrlCreateEdit("", 8, 24, 257, 81)
Global 
$List = GUICtrlCreateList("", 8, 168, 217, 201)
Global 
$createlist = GUICtrlCreateButton("生成", 224, 168, 41, 201, 0)
Global 
$Group1 = GUICtrlCreateGroup("必要说明", 0, 8, 273, 105)
Global 
$Group2 = GUICtrlCreateGroup("歌曲列表", 0, 144, 273, 241)
Global 
$Label = GUICtrlCreateLabel("谢谢您的使用,有任何建议请联系作者!", 8, 408, 260, 33)
Global 
$Group3 = GUICtrlCreateGroup("信息提示", 0, 392, 273, 57)
GUISetState
(@SW_HIDE)
;-------
Global 
$oMediaplayer = ObjCreate("WMPlayer.OCX.7")
Global 
$oMediaPlayControl = $oMediaplayer.Controls
Global 
$oMediaPlaySettings = $oMediaplayer.Settings
;主面板
Global 
$music_tool = GUICreate("FURST-释放音乐", 200, 100, (@DesktopWidth - 200) / 2, (@DesktopHeight + 200) / 2, -1)
Global 
$Label1 = GUICtrlCreateLabel("    --欢迎光临--" & @CRLF & "5ayangguangokman@163.com", 16, 8, 188, 33)
Global 
$Volume = GUICtrlCreateSlider(56, 72, 81, 25)
Global 
$VolLevel;
Global 
$play = GUICtrlCreateButton("播放", 0, 72, 49, 25, 0)
Global 
$Label2 = GUICtrlCreateLabel("", 0, 40, 204, 33)
Global 
$stop = GUICtrlCreateButton("停止", 144, 72, 57, 25, 0)
GUISetState
(@SW_HIDE)

;显示面板(“欢迎界面”)----
go
($gui_1)
GUISetState
(@SW_SHOW, $gui_1)
flash_shezhi
('http://cp.qzone.qq.com/flash/1004678.swf')

;;----------
obj_look
()
gui_driver
()
check
()
;;--------



While 
1
    Sleep
(1000)
WEnd

#cs
    三大模块:--
    事件处理模块,风格设置模块,功能设置模块
#ce

;事件处理模块

Func gui_driver
();--注册事件驱动
    HotKeySet
("+!i", "gui_drivemessage")
    HotKeySet
("+!p", "gui_drivemessage")
    HotKeySet
("+!o", "gui_drivemessage")
    GUISetOnEvent
($GUI_EVENT_CLOSE, "gui_drivemessage1", $music_tool)
    GUICtrlSetOnEvent
($play_url, "gui_drivemessage1")
    GUICtrlSetOnEvent
($List, "gui_drivemessage1")
    GUICtrlSetOnEvent
($createlist, "gui_drivemessage1")
    GUICtrlSetOnEvent
($play, "gui_drivemessage1")
    GUICtrlSetOnEvent
($stop, "gui_drivemessage1")
    GUICtrlSetOnEvent
($Volume, "gui_drivemessage1")


EndFunc   
;==>gui_driver
;处理事件函数

Func gui_drivemessage
();--热键事件处理
    Switch @HotKeyPressed
        Case 
"+!o"
            GUICtrlDelete
($GUIActiveX)
            back
($gui_1)
            GUISetState
(@SW_HIDE, $gui_1)
            GUISetState
(@SW_SHOW, $music_tool)
            GUISetState
(@SW_SHOW, $music_tool_1)
            
If (FileExists('songs.m3u') = 1) Then $oMediaplayer.URL = "songs.m3u"
        Case 
"+!i"
            
;MsgBox(0,"as",GUICtrlGetState($gui_1))
            GUISetState
(@SW_SHOW, $music_tool_1)
        Case 
"+!p"
            GUISetState
(@SW_HIDE, $music_tool_1)
    EndSwitch
EndFunc   
;==>gui_drivemessage

Func gui_drivemessage1
();--点击事件处理
    Switch @GUI_CtrlId
        Case 
$GUI_EVENT_CLOSE
            
Exit
        Case 
$play_url
            
$getURL = GUICtrlRead($Input_url)
            
;MsgBox(0,"sd",$Input)
            
;$temp = StringSplit($Input,'"')
            $file1 = FileOpen('songs.m3u', 1)
            FileWrite($file1, $getURL)
            FileClose($file1)
            $oMediaplayer.URL = $getURL
            $oMediaPlayControl.Play
            Sleep(1000)
            GUISetState(@SW_HIDE, $music_tool_1)
        Case $createlist
            $songs_path = FileSelectFolder(
"请选择歌曲所在的文件夹" & @CRLF & "***************""")
            ;;这里把Run改成RunWait不行,??
            Run('getsongs.bat 
"' & $songs_path & '" ', '', @SW_HIDE)
            Sleep(2000)
            If (FileGetSize(
"songs.m3u") = 0) Then
                MsgBox(16, 
"MUSIC系统""对不起,错误!可能你选择的文件夹里没有音乐文件!")
                Exit
            EndIf
            show_biao()
            GUICtrlSetState($createlist, $GUI_DISABLE)
            GUICtrlSetState($play_url, $GUI_ENABLE)
            GUICtrlSetData($Label, '谢谢您的使用,有任何建议请联系作者!')
        Case $List
            Global $getsongs = _GUICtrlListGetSelItemsText($List)
            $oMediaplayer.URL = $getsongs[1]
            $oMediaPlayControl.Play
            $thesong = StringSplit($getsongs[1], '\')
            GUICtrlSetData($Label1, '正在播放:' & @CRLF & $thesong[$thesong[0]])
            Sleep(1000)
            GUISetState(@SW_HIDE, $music_tool_1)
        Case $play
            $oMediaPlayControl.Play
        Case $stop
            $oMediaPlayControl.Stop
        Case Else
            If GUICtrlRead($Volume) <> $VolLevel Then
                $oMediaPlaySettings.Volume = GUICtrlRead($Volume)
                $VolLevel = GUICtrlRead($Volume)
            EndIf

    EndSwitch
EndFunc   ;==>gui_drivemessage1

;风格设置模块

;显示风格函数
Func ishide($window_name, $size)
    $L = DllCall(
"user32.dll""long""GetWindowLongA""hwnd", $window_name, "int", -20);
    $L = BitOR($L, 0x00080000);
    $Result = DllCall(
"user32.dll""long""SetWindowLongA""hwnd", $window_name, "int", -20, "long", $L);
    $Result = DllCall(
"user32.dll""int""SetLayeredWindowAttributes""hwnd", $window_name, "int", 0, "int", $size, "int", 0x00000002);
EndFunc   ;==>ishide
Func go($window_name)
    DllCall(
"User32.dll""long""AnimateWindow""hwnd", $window_name, "long", 800, "long", 0x10)
EndFunc   ;==>go
Func back($window_name)
    DllCall(
"User32.dll""long""AnimateWindow""hwnd", $window_name, "long", 1500, "long", 0x10 + 0x10000)
EndFunc   ;==>back

;主窗体风格函数
Func _GuiDragableCreate($Title = 
"", $Width = 300, $Height = 200, $Left = -1, $Top = -1, $Style = -1, $exStyle = -1, $Parent = 0)
    Local $SetStyle = $WS_POPUPWINDOW + $Style, $SetExStyle = $WS_EX_DLGMODALFRAME + $exStyle
    If $Style = -1 Then $SetStyle = $WS_POPUPWINDOW
    If $exStyle = -1 Then $SetExStyle = $WS_EX_DLGMODALFRAME
    Local $hWnd = GUICreate($Title, $Width, $Height, $Left, $Top, $SetStyle, $SetExStyle, $Parent)
    $Title_Label = GUICtrlCreateLabel($Title, 0, 0, 300, 20, $SS_CENTER)
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUICtrlSetFont(-1, 18, 700, 0, 
"Courier New")
    If Not BitAND($SetStyle, $WS_MAXIMIZEBOX) Then GUICtrlSetState(-1, $GUI_DISABLE)
    Return $hWnd
EndFunc   ;==>_GuiDragableCreate

;主窗体上个控件风格函数
Func obj_look()
    GUISetBkColor(0xF0F8FF, $gui_1)
    GUISetBkColor(0xF0F8FF, $music_tool)
    GUISetBkColor(0xF0F8FF, $music_tool_1)
    GUICtrlSetColor($Label1, 0x6B238E)
    GUICtrlSetColor($Label2, 0x5C3317)
    GUICtrlSetBkColor($play, 0xF0F8FF)
    GUICtrlSetBkColor($stop, 0xF0F8FF)
    GUICtrlSetBkColor($Volume, 0xF0F8FF)
    GUICtrlSetFont($Label2, 10, 400, 0, 
"宋体")
    GUICtrlSetFont($Label, 14)
    GUICtrlSetFont($Edit, 10)
    GUICtrlSetFont($Label1, 11, 400, 0, 
"黑体")
    GUICtrlSetData($Volume, 100)
    GUICtrlSetState($createlist, $GUI_DISABLE)
    GUICtrlSetData($Label2, 
"作者心中有画可曼描" & @CRLF & "观者角度不同能出奇")
    GUICtrlSetData($Edit, 
"这是一个纯脚本作品,也是我的第一个脚本习作!" & @CRLF & _
            
"大概写了差不多两三天,其中受到了很多朋友的帮助" & @CRLF & _
            
"也参照了不少优秀作品,这里一并感谢!" & @CRLF & _
            
"脚本的轻便总是给人惊喜" & @CRLF & _
            
"正是:大家秀餐情浓意胜,小家渔风另有滋味!" & @CRLF & _
            
"当然作品的相关漏洞也不少" & @CRLF & _
            
"希望高手在代码优化和功能扩张方面继续研究,多提建议!" & @CRLF & _
            
"简单说明:" & @CRLF & "涉及到的组合键有:Shift+Alt+O,Shift+Alt+i,Shift+Alt+,大家参照使用!" & @CRLF & _
            
"QQ:896032591" & @CRLF & _
            
"MAIL:5a@[email]yangguangokman@163.com[/email]")
    ishide($music_tool_1, 200)
    ishide($gui_1, 200)
    ishide($music_tool, 150)
    
EndFunc   ;==>obj_look

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;功能函数模块

Func begin();--防脚本多次打开
    $neirong = 
"open Faile"
    If WinExists($neirong) Then Exit
    AutoItWinSetTitle($neirong)
EndFunc   ;==>begin
Func check();--程序运行前检查各种配置文件是否存在并做出相应的提示!
    If (FileExists('getsongs.bat') = 0) Then
        GUICtrlSetData($Label, '重要文件getsongs.bat可能被删除或移动!')
    ElseIf (FileExists('songs.m3u') = 0) Then
        GUICtrlSetData($Label, '歌曲列表不存在,请先生成!')
        GUICtrlSetState($createlist, $GUI_ENABLE)
        GUICtrlSetState($play_url, $GUI_DISABLE)
    Else
        show_biao()
        ;If(GUICtrlGetState($GUIActiveX)=-1) Then $oMediaplayer.URL = 
"songs.m3u"
        ;MsgBox(0,
"asf",GUICtrlGetState($GUIActiveX))
    EndIf
EndFunc   ;==>check
Func show_biao();--生成歌曲列表
    $file = FileOpen('songs.m3u', 0)
    While 1
        $readline = FileReadLine($file)
        If @error = -1 Then ExitLoop
        _GUICtrlListAddItem($List, $readline)
    WEnd
    FileClose($file)
EndFunc   ;==>show_biao

Func flash_shezhi($temp_FlashUrl);--设置flash控件的默认值
    $ax_flash.ScaleMode = 1
    $ax_flash.bgcolor = 
"#FFFFFF"
    $ax_flash.Loop = False
    $ax_flash.wmode = 
"transparent"
    Do
        Sleep(20)
        $ax_flash.Movie = $temp_FlashUrl
        ToolTip(
"思极其静慢细深" & @CRLF & "行极其快准意明" & @CRLF & "--欢迎DOS多媒体--" & @CRLF & "  ^^^请等待^^^" & @CRLF & 'Shift+Alt+O组合键,快速调用music系统' & @CRLF & "      ^^^^ --ss")
    Until (String($ax_flash.readyState) = 
"complete" Or $ax_flash.readyState = 4)
    ToolTip(
"")
    
EndFunc   ;==>flash_shezhi


#cs
    模块总结:
    显式函数--
    begin()
    obj_look()
    gui_driver()
    check()
    flash_shezhi()
    go()
    back()
    _GuiDragableCreate()
    隐式函数--
    show_biao()
    ishide()
#ce
;----------至此完成!

我本身在学.NET方面,所以老感觉在敲au3代码时有点不自在,也许这就是各种语言的个性所使,这篇代码从au3设计模式角度思考对代码进行了优化,总算找回点‘高级’语言编程时的感觉,希望能给朋友们提供点启发和帮助!
 

posted on 2008-06-05 23:43  cmd_ss  阅读(339)  评论(0)    收藏  举报