gsb Posted June 11, 2007 Posted June 11, 2007 Dragable transparent gif image/GUI - Floating gif image example.I have seen a few posts that use "regions" to accomplish something similar. However, I fell into this example while trying to do yet another something, really. Did not help me. But seems somewhat like some members have been looking for in their posts. So anyway, I thought I'd pause a moment, clean it up and share it here as an example script. Does nothing more than titled.expandcollapse popup;;----------------- Constants and Options Global Const $GUI_EVENT_CLOSE = -3 Global Const $GUI_EVENT_PRIMARYUP = -8 Global Const $GUI_EVENT_MOUSEMOVE = -11 Global Const $WS_POPUP = 0x80000000 Global Const $WS_EX_LAYERED = 0x00080000 Global Const $WS_EX_MDICHILD = 0x00000040 Global Const $WS_EX_TOPMOST = 0x00000008 Opt("GUICloseOnESC", 1) Opt("TrayIconHide", 1) ;;----------------- What is... Dim $guiWinTitle = "TranaparentGUI" Dim $Version = "v0700611a" ;;----------------- 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 ;;----------------- Exit hotkey HotKeySet("^+x", "_Exit") ;;----------------- Tramsparent gif/GUI core code InetGet("http://www.GypsyTrader.com/avatars/avatar_t80x80.gif", @ScriptDir & "\t80x80.gif") Local $width = 80, $height = 80 Local $mainGUI = GUICreate($guiWinTitle, $width, $height, _ (@DesktopWidth - $width) / 2, (@DesktopHeight - $height) / 2, _ $WS_POPUP, $WS_EX_LAYERED + $WS_EX_MDICHILD + $WS_EX_TOPMOST, _ WinGetHandle(WinGetTitle("Program Manager"))) Local $image = GUICtrlCreatePic("t80x80.gif", 0, 0, $width, $height) FileDelete( @ScriptDir & "\t80x80.gif" ) GUISetState(@SW_SHOW) ;;----------------- Variables for loop and dragging Local $msg, $mouseOffsetPos, $dragging = $image While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE _Exit() Case $msg = $GUI_EVENT_PRIMARYUP If $dragging Then $dragging = $image Case $msg = $image If $dragging <> $GUI_EVENT_MOUSEMOVE Then $dragging = $GUI_EVENT_MOUSEMOVE Opt("MouseCoordMode", 0) $mouseOffsetPos = MouseGetPos() Opt("MouseCoordMode", 1) EndIf Case $msg = $dragging _BoundedDrag($mainGUI) EndSelect WEnd _Exit();; unreachable ;;----------------- Support functions Func _BoundedDrag($win, $top=0, $left=0, $bottom=@DesktopHeight, $right=@DesktopWidth) Local $mousePos = MouseGetPos() Local $windowPos = WinGetPos($win) Local $x, $y If $mousePos[0] - $mouseOffsetPos[0] < $left Then $x = $left ElseIf $windowPos[2] - $mouseOffsetPos[0] + $mousePos[0] > $right Then $x = $right - $windowPos[2] Else $x = $mousePos[0] - $mouseOffsetPos[0] EndIf If $mousePos[1] - $mouseOffsetPos[1] < $top Then $y = $top ElseIf $windowPos[3] - $mouseOffsetPos[1] + $mousePos[1] > $bottom Then $y = $bottom - $windowPos[3] Else $y = $mousePos[1] - $mouseOffsetPos[1] EndIf WinMove($win, "", $x, $y) EndFunc ;==>_BoundedDrag Func _Exit() Exit EndFunc ;==>_ExitEnjoy!gsb "Did you ever stop to think? ...and forget to restart!"
star2 Posted June 12, 2007 Posted June 12, 2007 (edited) nice job but doesn't work with animated pix Edited June 12, 2007 by star2 [quote]Baby you're all that I want, When you're lyin' here in my armsI'm findin' it hard to believe, We're in heavenAnd love is all that I need , And I found it there in your heartIt isn't too hard to see, We're in heaven .Bryan Adams[/quote].............................................................................[u]AUTOIT[/u]
jvanegmond Posted June 12, 2007 Posted June 12, 2007 Looks very complicated, is quite simple. You should just leave the #includes up and call the functions that are inside. Don't try to be smart when providing an example. Not a great example, because of the reason mentioned above. You could do better on the commenting too! github.com/jvanegmond
lod3n Posted June 12, 2007 Posted June 12, 2007 (edited) Try this:#include <GUIConstants.au3> $src = "http://www.GypsyTrader.com/avatars/avatar_t80x80.gif" $dest = @ScriptDir & "\avatar_t80x80.gif" InetGet($src,$dest) $width = 80 $height = 80 $gui = GUICreate("GUI Transparency", $width, $height, -1, -1, $WS_POPUP, $WS_EX_LAYERED) $pic = GUICtrlCreatePic($dest, 0, 0, $width, $height,-1,$GUI_WS_EX_PARENTDRAG) GUISetState(@SW_SHOW) WinSetOnTop($gui, "",1) While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop Wend BTW, all the hints for this are located in the help file under GUICtrlCreatePic. Edited June 12, 2007 by lod3n [font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]
gsb Posted June 12, 2007 Author Posted June 12, 2007 Manadar, you were saying..."Looks very complicated, is quite simple."Yes is very simple. Complexity was added the for bounded-drag capability.Is why I added:;;----------------- Transparent gif/GUI core code InetGet("http://www.GypsyTrader.com/avatars/avatar_t80x80.gif", @ScriptDir & "\t80x80.gif") Local $width = 80, $height = 80 Local $mainGUI = GUICreate($guiWinTitle, $width, $height, _ (@DesktopWidth - $width) / 2, (@DesktopHeight - $height) / 2, _ $WS_POPUP, $WS_EX_LAYERED + $WS_EX_MDICHILD + $WS_EX_TOPMOST, _ WinGetHandle(WinGetTitle("Program Manager"))) Local $image = GUICtrlCreatePic("t80x80.gif", 0, 0, $width, $height) FileDelete( @ScriptDir & "\t80x80.gif" ) GUISetState(@SW_SHOW)Seemed clear enough at the time."You should just leave the #includes up and call the functions that are inside.""Don't try to be smart when providing an example."Point well taken for an "example post." However, as you well know, to reduce the size of the an exe one should remove the unnecessary code that the includes provide. You may have missed it above in post #1 where I said:"...I fell into this example while trying to do yet another something ... I thought I'd pause a moment, clean it up and share it here as an example script."So that is what it is, a cleaned up cut-and-paste from a larger project; not a from scratch tutorial. Next time I will add back in the includes although routines used ID the include it is from."Not a great example, because of the reason mentioned above."Well it does not play AVI's either, but wait... The title hinted at that, no?Dragable transparent gif image/GUI - Floating gif image example....and I added: "Does nothing more than titled," just for good measure."You could do better on the commenting too!"...as could most programmers. LOLBut I would say that this is better documented than many of the post I have read on this forum. I prefer pointed comments and 'self-documenting' code. But you are right again regarding more than usual comments required for an example script. Given time, next time I will add additional comments.Thanks for your time and comments all.gsb "Did you ever stop to think? ...and forget to restart!"
gsb Posted June 12, 2007 Author Posted June 12, 2007 Thanks lod3n. Like a lot in the help files, i seemed to have missed that too. I will try it out later today... need to head off to work now. But WoW! You are even worse with comments than I am. JK LOL gsb "Did you ever stop to think? ...and forget to restart!"
lod3n Posted June 12, 2007 Posted June 12, 2007 AutoIt supports comments? [font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]
gsb Posted June 12, 2007 Author Posted June 12, 2007 lod3n, Yes. Much better LOL, TY. Now, how about the same for that Flashy of yours? ...possible? gsb "Did you ever stop to think? ...and forget to restart!"
lod3n Posted June 12, 2007 Posted June 12, 2007 Apparently this works for flash files too. Compile this, and drag a flash file onto the .exe expandcollapse popup#include <GUIConstants.au3> #include <ie.au3> #include <array.au3> $flashfile = _ArrayToString($cmdline," ",1) HotKeySet("{ESC}","quitter") func quitter() Exit EndFunc $dest = @ScriptDir & "\avatar_t80x80.gif" InetGet($src,$dest) $width = 400 $height = 400 $gui = GUICreate("GUI Transparency", $width, $height, -1, -1, $WS_POPUP, $WS_EX_LAYERED) $pic = GUICtrlCreatePic($dest, 0, 0, $width, $height,-1,$GUI_WS_EX_PARENTDRAG) ;$gui = GUICreate("Flashy"&$flashfile, 80, 80, -1, -1, BitOR($WS_MINIMIZEBOX,$WS_MAXIMIZEBOX,$WS_SIZEBOX,$WS_THICKFRAME,$WS_SYSMENU,$WS_CAPTION,$WS_POPUPWINDOW,$WS_GROUP,$WS_BORDER,$WS_CLIPSIBLINGS),$WS_EX_ACCEPTFILES) $oIE = _IECreateEmbedded ( ) $browser = GUICtrlCreateObj($oIE, 0, 0,$width,$height) GUICtrlSetState (-1, $GUI_DROPACCEPTED) GUICtrlSetResizing(-1,$GUI_DOCKBORDERS) GUICtrlSetStyle ( -1, $GUI_WS_EX_PARENTDRAG) _IENavigate ($oIE, 'about:blank') $sHTML = '<embed id=flashy src="" ' $sHTML &= 'quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" ' $sHTML &= 'type="application/x-shockwave-flash" ' $sHTML &= 'width="100%" height="100%"></embed>' _IEBodyWriteHTML ($oIE, $sHTML) loadswf($flashfile) $oDoc = _IEDocGetObj ($oIE) $oDoc.body.style.overflow = "auto" $oDoc.body.style.border = "0px" GUISetState(@SW_SHOW) WinSetOnTop($gui, "",1) While 1 $Msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit EndSelect WEnd func loadswf($filename) if stringlen($filename) = 0 then msgbox(16,"Flashy","No flash file specified. Associate SWFs with Flashy, or drop one onto the blank window") Return EndIf if stringright($filename,4) <> ".swf" then msgbox(16,"Flashy - Error","Dude, that's not a SWF.") Return EndIf $flash = _IEGetObjByName ($oIE, "flashy") $flash.Movie = $filename winsettitle($gui,"","Flashy - "&$filename) EndFunc [font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]
gsb Posted June 13, 2007 Author Posted June 13, 2007 I have played with your example some lod3n; expanded it and added some more complex swf's to try. Nice and thanks again for the help. One annoyance though, don't know if you noticed. But in the swf anything on a top layer of color "white" is transparent through to the desktop. Burns a hole through all the layers, LOL. Is interesting effect, no? Any thoughts? gsb "Did you ever stop to think? ...and forget to restart!"
lod3n Posted June 13, 2007 Posted June 13, 2007 Yes, that's just how Windows achieves the transparency. You can avoid this by changing the color of the things you don't want to be transparent to off-white. It's cheap and easy, but not perfect. [font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]
star2 Posted June 14, 2007 Posted June 14, 2007 what about animated GIF? [quote]Baby you're all that I want, When you're lyin' here in my armsI'm findin' it hard to believe, We're in heavenAnd love is all that I need , And I found it there in your heartIt isn't too hard to see, We're in heaven .Bryan Adams[/quote].............................................................................[u]AUTOIT[/u]
gsb Posted June 14, 2007 Author Posted June 14, 2007 "Yes, that's just how Windows achieves the transparency. You can avoid this by changing the color of the things you don't want to be transparent to off-white. It's cheap and easy, but not perfect." Yes lod3n, exactly what I did as a workaround - redefined 'white' as 0xFEFEFE. LOL Hey, but it works. gsb "Did you ever stop to think? ...and forget to restart!"
lod3n Posted June 14, 2007 Posted June 14, 2007 Hey, I noticed something interesting on this, and it seems I was wrong regarding the nature of how windows handles transparency in this case.When you set the window style to $WS_EX_LAYERED, and set a background image with GUICtrlCreatePic, the window's transparency seems to be set by whatever color is at 0,0 in the image (I think). On top of that, it doesn't seem to realize that transparent GIFs even have transparency, but instead assumes that the image's 0,0 pixel is white. If you use a red gif instead, the transparent color is red!I discovered this while producing this demo:http://www.autoitscript.com/forum/index.php?showtopic=47651I include a gray.gif file which nicely defines my transparent background color as gray. I wanted white text on a gray background, with the area surrounding the text to be transparent.It make sense. Why would Microsoft force you to use white as a transparent color? The off-white solution may still hold for what you are trying to do though, but at least the reason for it is better understood now. [font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]
gsb Posted June 14, 2007 Author Posted June 14, 2007 Thanks lod3n. Yes. I was looking at your other example (before coffee) this morning. I upgraded AutoIt (again) and re-downloaded the lib but could not get it to run. Seems his lib was last updated last month not yesterday. Is there an 0613 update? ...burried in that 45 page thread maybe instead of post#1? And thanks for the update here. I will do more testing for this works great, TYVM. So far I can make transparent animated text and graphics anywhere on the desktop as the visible portion of the GUI. These animation are flash movies and use the fsCommands to communicate directly to the autoIt script which can in turn, communicate back to the movie. Of course this is all asynchronous communications via callbacks, but works nicely... so far that is. Thanks for your help. I will play with your other example at a future point I think. PNG's are nice, cleaner, but I can already put them in my movies as needed and flash movies are more in line with my short term objectives. gsb "Did you ever stop to think? ...and forget to restart!"
gsb Posted June 14, 2007 Author Posted June 14, 2007 (edited) Hummm...I fixed my swf transparency "drill through" issue and am back to a white transparency basis w/o that problem.But I am not sure why it was a problem in the first place - bad code perhaps.Anyway is fixed now.***EDIT:I was on a old WIN2000p machine. XP still has the problem the swf transparency "drill through" ...oh well.gsb Edited June 15, 2007 by gsb "Did you ever stop to think? ...and forget to restart!"
gsb Posted June 15, 2007 Author Posted June 15, 2007 Well... at risk again, but here is a cut-down Flash movie (.swf) example. The movie has two somewhat independent clips: simple menu button and a watch (swf by Craig Lowe.) The two movie parts are dragable but trapped on-screen. They have a common context menu with two local HotKey/menu-items (local to Flash and not processed by the GUI) and two GUI menu-items. The GUI also has two HotKeys, visibility and exit. And the Flash button is simply a toggle for the watch clip to show/hide. expandcollapse popup#include <GUIConstants.au3> #include <IE.au3> #include <Misc.au3> ; ...setup Initializations Opt("TrayIconHide", 1) _IEErrorHandlerRegister() Dim $guiWinTitle = "TSMkiosk" Dim $Version = "v070614p" Dim $AboutText = $guiWinTitle & " " & $Version & " " & @LF & "by gsb" & @LF ; ...setup hotkeys HotKeySet("^+x", "_Exit") HotKeySet("^+v", "_ToggleVisibility") HotKeySet("{ESC}","_Exit") ; ...setup files Local $htmlFilename = @ScriptDir & "\forumExample.html" Local $swfFilename = @ScriptDir & "\TSMkiosk24.swf" Local $imageFile = @ScriptDir & "\TSMkiosk.gif" InetGet("http://www.GypsyTrader.com/SWiSHmax/au3Examples/forumExample.html",$htmlFilename) InetGet("http://www.GypsyTrader.com/SWiSHmax/au3Examples/TSMkiosk24.swf",$swfFilename) InetGet("http://www.GypsyTrader.com/SWiSHmax/au3Examples/TSMkiosk.gif",$imageFile) ; ...Core GUI code Local $mainGUI = GUICreate($guiWinTitle, @DesktopWidth, @DesktopHeight, -1, -1, $WS_POPUP, $WS_EX_LAYERED+$WS_EX_TOPMOST) GUISetBkColor(0xFFFFFF) Local $ieOBJ = _IECreateEmbedded ( ) Local $ieCTL = GUICtrlCreateObj($ieOBJ, 0, 0, @DesktopWidth, @DesktopHeight) GUICtrlSetResizing($ieCTL, $GUI_DOCKBORDERS) GUICtrlCreatePic($imageFile, 0, 0, 1, 1, -1) _IENavigate($ieOBJ, $htmlFilename) GUISetState(@SW_SHOW) ; ...setup runtime variables Dim $isVisible = 1 Dim $stageManager, $oXfer = $ieOBJ.document.parentwindow.document.documentElement ; ...main movie interface loop While 1 If IsObj($oXfer.gsb) And $oXfer.gsb <> "" Then If $oXfer.gsb.cmd = "initialize" Then $stageManager = $oXfer.gsb.obj $oXfer.gsb = "" $stageManager.SetVariable ("/:TSMkiosk", "ok") Else _fsCommand($oXfer.gsb.cmd, $oXfer.gsb.args) $stageManager.SetVariable ("/:au3Direct", "") EndIf $oXfer.gsb = "" EndIf $msg = GUIGetMsg() WEnd _Exit();; unreachable ;;----------------- fsCommand processor Func _fsCommand($cmd, $args) Select Case $cmd = "_About" _About($args) Case $cmd = "_Exit" _Exit() Case $cmd = "_ToggleVisibility" _ToggleVisibility() Case $cmd = "_Alert" _Alert($args) Case Else $stageManager.gsbTrace ("Unknown cmd: " & $cmd & " Args: [" & $args & "]") EndSelect EndFunc ;==>_fsCommand ;;----------------- Functions Func _ToggleVisibility() If Not $isVisible Then GUISetState(@SW_SHOW) $isVisible = 1 Else GUISetState(@SW_HIDE) $isVisible = 0 EndIf EndFunc ;==>_ToggleVisibility Func _Trace($str) $stageManager.gsbTrace($str) EndFunc ;==>_Trace Func _About($str = "") MsgBox(266288, "About", _Iif($str = "", $AboutText, $str & @LF & $AboutText), 10); modal, top, info EndFunc ;==>_About Func _Alert($str) MsgBox(266288, "Alert", $str, 10); modal, top, info EndFunc ;==>_Alert Func _Exit() Exit EndFunc ;==>_Exit Thanks again lod3n for all your examples and help. gsb "Did you ever stop to think? ...and forget to restart!"
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