gsb Posted July 10, 2007 Share Posted July 10, 2007 DeskTopSWFs - Widgets for the desktop ...of your own design using Flash.IntroductionThis project has been to develop "stand alone" application out of Flash movie content. I found it best to use a GUI with a single _IECreateEmbedded control. This works better than the ObjCreate("ShockwaveFlash.ShockwaveFlash.1") control due to some bad behavior of the Flash Player such as; re-draw hick-ups, refusal to re-size properly and some focus related issues I could not sort out. Embedding the movie in a small HTML script allows the browser to mitigate such annoyances. It also opens the possibility of far more robust web rich desktop applications and CD based applications for example anyway.GoalsThe main goal was seamless two way communications between the Flash movie and the AutoIt GUI wrapper script. Flash's "External Interface" provides AutoIt with direct access to the movie's ActionScript exposing all of the movie's functionality and capabilities. And lod3n's "event bridge" enables Flash to trigger events that are then captured and processed by the AutoIt wrapper script. Although asynchronous, this combinations seems to work efficiently so far.Some of the other goals included "look-n-feel" like: full screen applications without any window dressings - chromeless. And GUI transparency with click-through to the desktop capability. Simple GUI tricks enable both of these capabilities and of course even more.RequirementsThis approach requires three files:an AutoIt GUI wrapper script,a compiled Flash movie (.swf) file, anda 1x1 pixel gif file of the transparent color.I usually compile the AutoIt using "FileInstall" for the other two files to make a single exe out of the three.The AutoIt script is still changing some and ultimately I would like to make a user interface allowing someone to simply pick and choose a couple of options and spit them out an exe of their Flash movie.CommentsNote that I example AutoIt assisting Flash to create stand alone applications. But this could just as easily be a Flash movie acting as an AutoIt GUI: it just depends on your point of view, no?ExamplesI posted an earlier example of a clock face here: Clock ExampleThis is an example of a streaming radio using CFire's Windows Media Player example. The radio player is dragable and I added a context menu along with two hot keys: 1) <esc> to exit (also double click will work) and 2) <ctl><shift>V to toggle visibility.Here I also added the "inetGet" to avoid file issues in this example. RestrictionsThe example runs on any windows PC with IE and the Flash player plug-in version 8 or better for IE as well as the Windows Media Player installed.expandcollapse popup#include <IE.au3> Global Const $GUI_EVENT_MOUSEMOVE = -11 Global Const $GUI_EVENT_CLOSE = -3 Global Const $WS_POPUP = 0x80000000 Global Const $WS_EX_TOPMOST = 0x00000008 Global Const $WS_EX_TOOLWINDOW = 0x00000080 Global Const $WS_EX_LAYERED = 0x00080000 Global Const $GUI_DOCKBORDERS = 0x0066 ; ...setup Initializations Opt("GUIOnEventMode", 1) Opt("GUICloseOnESC", 0) Opt("TrayIconHide", 1) _IEErrorHandlerRegister() Dim $guiWinTitle = "DeskTopSWFs" Dim $Version = "v070808a" Dim $AboutText = $guiWinTitle & " " & $Version & " " & @LF & "by gsb" & @LF ;;----------------- from: Misc.au3 - _Singleton for $guiWinTitle DllCall("kernel32.dll", "int", "CreateMutex", "int", 0, "long", 1, "str", $guiWinTitle) Dim $lastError = DllCall("kernel32.dll", "int", "GetLastError") If $lastError[0] == 183 Then MsgBox(266288, $guiWinTitle & " - Error", "...already running. Aborting. ", 8) Exit EndIf HotKeySet("^+v", "_ToggleVisibility") HotKeySet("{ESC}", "_Exit") ;; last chance exit ;; **** for example post only InetGet("http://www.GypsyTrader.com/SWiSHmax/au3Examples/mainSWF.swf",@ScriptDir&"\mainSWF.swf") InetGet("http://www.GypsyTrader.com/SWiSHmax/au3Examples/required.key",@ScriptDir&"\required.key") #region ;; ...setup files and build HTML for IE inatance Local $swfFilename = @TempDir & "\mainSWF.swf" FileDelete($swfFilename) FileInstall("mainSWF.swf", $swfFilename) Local $keyFile = @TempDir & "\required.key" FileDelete($keyFile) FileInstall("required.key", $keyFile) $sHTML = '<html><head><title>DeskTopSWFs by gsb</title>' & @CRLF $sHTML &= '<meta name="author" content="gsb">' & @CRLF $sHTML &= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />' & @CRLF $sHTML &= '<style type="text/css">' & @CRLF $sHTML &= '* {margin:0px;padding:0px;}' & @CRLF $sHTML &= 'HTML {height:100%;overflow:hidden;border:0px;background-color:#FEDDEF}' & @CRLF $sHTML &= 'body {height:100%;overflow:hidden;border:0px;background-color:#FEDDEF}' & @CRLF $sHTML &= '</style>' & @CRLF $sHTML &= '<script type="text/javascript">' & @CRLF ;; Bridge Event sequencer javascript compressed @ http://dean.edwards.name/packer/ $sHTML &= 'window.au3EventsQueue=new Array();window.au3Interval=null;function au3EventsSequencer(){if(window.au3EventsQueue.length){if((o=document.getElementById("eventBridge")).bridge==""){var data=window.au3EventsQueue.shift();o.bridge=new function(){this.cmd=data.cmd;this.cb=data.cb;this.args=data.args}}}return(window.au3EventsQueue.length)};function au3Event(cmd,args){window.au3EventsQueue.push({cb:((t=cmd.split("|")).length>1?t[1]:""),cmd:t[0],args:args});au3EventsSequencer()};function au3Direct(cmd,args){document.getElementById("eventBridge").bridge=new function(){this.cb=(t=cmd.split("|")).length>1?t[1]:"";this.cmd=t[0];this.args=args}};' & @CRLF $sHTML &= '</script>' & @CRLF $sHTML &= '<base href="file:\\' & @ScriptDir & '\" />' & @CRLF $sHTML &= '</head><body scroll="no">' & @CRLF $sHTML &= '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,22,0" id="gsbMovie" width="100%" height="100%">' & @CRLF $sHTML &= '<param name="bgcolor" value="#FEDDEF">' & @CRLF $sHTML &= '<param name="quality" value="high">' & @CRLF $sHTML &= '<param name="loop" value="false">' & @CRLF $sHTML &= '<param name="menu" value="true">' & @CRLF $sHTML &= '<param name="allowscriptaccess" value="always">' & @CRLF $sHTML &= '<param name="wmode" value="transparent">' & @CRLF $sHTML &= '<param name="base" value="file://' & @ScriptDir & '\">' & @CRLF $sHTML &= '<param name="movie" value="' & $swfFilename & '">' & @CRLF ;; $sHTML &= '<param name="flashvars" value="debug=true">' & @CRLF $sHTML &= '</object><input type="hidden" id="eventBridge" gsb=""></body></html>' & @CRLF #endregion #region;; ...Core GUI code - transparent, Kiosk mode IE instance loaded w/ $sHTML Local $height = 100, $width = 300 Local $mainGUI = GUICreate($guiWinTitle, $width, $height, -@DesktopWidth, 0, $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST + $WS_EX_LAYERED) Local $ieOBJ = _IECreateEmbedded() Local $ieCTL = GUICtrlCreateObj($ieOBJ, 0, 0, $width, $height) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUICtrlSetResizing($ieCTL, $GUI_DOCKBORDERS) _IENavigate($ieOBJ, 'about:blank') _IEDocWriteHTML($ieOBJ, $sHTML) GUICtrlCreatePic($keyFile, 0, 0, 0, 0, -1) AdlibEnable("_LoadAbort", 10000) Sleep(10);; needed for old/slow sytems/machines Local $oTarget = $ieOBJ.document.getElementById ("eventBridge") Local $handler = ObjEvent($oTarget, "IeEvent_") Local $movie = 0, $mousePos Local $WMStation, $WMVol = 100, $WMPlayer = ObjCreate("WMPlayer.ocx") Local $WMStates[12] = ["Undefined", "Stopped", "Paused", "Playing", "ScanForward", "ScanReverse", "Buffering", "Waiting", "MediaEnded", "Transitioning", "Ready", "Reconnecting"] GUISetState(@SW_SHOW) ;;Sleep(100);; to eliminate initial Kiosk mode and Transparent screen flicker WinMove($mainGUI, "", (@DesktopWidth - $width) / 2, (@DesktopHeight - $height) / 2) Local $isVisible = 1 FileDelete($swfFilename) FileDelete($keyFile) #endregion ;; ...main GUI "idle around loop" While 1 Sleep(100) WEnd _Exit();; unreachable ;;----------------- Flash/IE event receiver Func IeEvent_onpropertychange() Local $event = @COM_EventObj If Not $movie Then $movie = _IEGetObjById ($ieOBJ, "gsbMovie") If IsObj($event.bridge) Then If $event.bridge.cmd = "initialize" Then $movie.SetVariable ("/:au3Init", $event.bridge.args) ElseIf $event.bridge.cmd = "loaded" Then AdlibDisable();; kill load timeout Else $movie.gsbTrace ("AU3: " & $event.bridge.cmd & ", " & $event.bridge.args & " [" & $event.bridge.cb & "]") gsbCommands($event.bridge.cmd, $event.bridge.args, $event.bridge.cb) EndIf $event.bridge = "" Local $rv = $movie.au3NextEvent ("") EndIf EndFunc ;==>IeEvent_onpropertychange ;;----------------- gsbCommand processor Func gsbCommands($cmd, $args, $cb) Select Case $cmd = "_About" _About($args) Case $cmd = "quit" _Exit() Case $cmd = "_Exit" _Exit() Case $cmd = "_ToggleVisibility" _ToggleVisibility() Case $cmd = "_Alert" _Alert($args) Case $cmd = "_StartWinDrag" Opt("MouseCoordMode", 0) $mousePos = MouseGetPos() Opt("MouseCoordMode", 1) GUISetOnEvent($GUI_EVENT_MOUSEMOVE, "_WinDrag") Case $cmd = "_StopWinDrag" GUISetOnEvent($GUI_EVENT_MOUSEMOVE, "") Case $cmd = "_ContextMenu" _Trace("_ContextMenu"); Case $cmd = "WMPlayer" ;; args - WMPlayerCommand, data [, more CSVs] Local $a = StringSplit($args, ",") Switch StringStripWS($a[1], 3) Case "open" If $a[0] > 1 Then Local $WMStream = StringStripWS($a[2], 3) $WMStation = $WMPlayer.newMedia ($WMStream) $WMPlayer.url = $WMStream While $WMStates[$WMPlayer.playState () ] <> "Playing" Sleep(100) $movie.WMDisplayState ($WMStates[$WMPlayer.playState () ]) WEnd $WMPlayer.settings.volume = $WMVol EndIf Case "mute" $WMVol = $WMPlayer.settings.volume $WMPlayer.settings.volume = 0 $movie.WMDisplayState ($WMStates[$WMPlayer.playState () ] & " :: Muted") Case "unmute" $WMPlayer.settings.volume = $WMVol $movie.WMDisplayState ($WMStates[$WMPlayer.playState () ]) Case Else _Trace("Bad WMPlayer Command: " & $a[1]) EndSwitch Case Else $movie.gsbTrace ("Unknown cmd: " & $cmd & " Args: [" & $args & "]") EndSelect EndFunc ;==>gsbCommands #region ;;----------------- Functions Func _LoadAbort() _Alert("SWF Load failure. Aborting. " & @LF); _Trace("*** Load Aborted.") _Exit() EndFunc ;==>_LoadAbort Func _WinDrag() Local $x, $y, $pos = MouseGetPos() Local $winPos = WinGetPos($mainGUI) If $pos[0] - $mousePos[0] < 0 Then $x = 0 ElseIf $winPos[2] - $mousePos[0] + $pos[0] > @DesktopWidth Then $x = @DesktopWidth - $winPos[2] Else $x = $pos[0] - $mousePos[0] EndIf If $pos[1] - $mousePos[1] < 0 Then $y = 0 ElseIf $winPos[3] - $mousePos[1] + $pos[1] > @DesktopHeight Then $y = @DesktopHeight - $winPos[3] Else $y = $pos[1] - $mousePos[1] EndIf WinMove($mainGUI, '', $x, $y) EndFunc ;==>_WinDrag Func _ToggleVisibility() If Not $isVisible Then GUISetState(@SW_SHOW) $isVisible = 1 Else GUISetState(@SW_HIDE) $isVisible = 0 MsgBox(266288, "Remember:",@LF&"<ESC> to exit"&@LF&"<CTL><SHIFT>V to 'Show' "&@LF&@LF, 10) EndIf EndFunc ;==>_ToggleVisibility Func _Trace($str) $movie.gsbTrace ($str) EndFunc ;==>_Trace Func _About($str = "") If $str = "" Then MsgBox(266288, "About", $AboutText, 10); modal, top, info Else MsgBox(266288, "About", "swf: " & $str & @LF & "exe: " & $AboutText, 10); modal, top, info EndIf EndFunc ;==>_About Func _Alert($str) MsgBox(266288, "Alert", $str, 10); modal, top, info EndFunc ;==>_Alert Func _Exit() $WMPlayer.controls.stop () Exit EndFunc ;==>_Exit #endregionLet me know...gsb "Did you ever stop to think? ...and forget to restart!" Link to comment Share on other sites More sharing options...
lod3n Posted July 10, 2007 Share Posted July 10, 2007 Nice work! [font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font] Link to comment Share on other sites More sharing options...
gsb Posted July 10, 2007 Author Share Posted July 10, 2007 Thanks lod3n. And thanks for so much help along the way. gsb "Did you ever stop to think? ...and forget to restart!" Link to comment Share on other sites More sharing options...
microsoft Posted August 1, 2007 Share Posted August 1, 2007 thanks Link to comment Share on other sites More sharing options...
martin Posted August 1, 2007 Share Posted August 1, 2007 The example runs on any windows PC with IE and the Flash player plug-in version 8 or better for IE as well as the Windows Media Player installed.Not quite every PC!I have IE version 6, Flash player plugin V9, WMP V8.I get "SWF load failure". Your clock works fine, in fact I have added it to lod3n'slauncher so that Ctrl Shift M brings up the combo box with the clock just above it. - Looks good. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
GtaSpider Posted August 1, 2007 Share Posted August 1, 2007 (edited) Hi Looks pretty cool^^ But by me there are no sound.. is that rigth? Mfg Spider Edit: ahh ok.. i must stop my Firewall^^ Uhm.. the visualization is only a fake, rigth?^^ Edited August 1, 2007 by GtaSpider www.AutoIt.de - Moderator of the German AutoIt Forum Link to comment Share on other sites More sharing options...
gsb Posted August 4, 2007 Author Share Posted August 4, 2007 Martin - That is a timeout for loading. Sounds like it did not get connected up with javascript in your browser. GtaSpider - Yeah fake I do not know how to get that data from the player. gsb "Did you ever stop to think? ...and forget to restart!" Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now