ReverendJ1 Posted November 28, 2006 Posted November 28, 2006 (edited) Hello all. Simply put I am trying to have a little space ship that moves over a background picture. I would like to use transparency for the space ship. The background is saved as several different bmps, and the ship is a gif, with transparency set. (All are attached). Below is what I have come up with so far (from the helpfile), and it shows the tranparency of the ship okay, but you cannot see any other part of the background! It only shows up when the ship is over it. Below is the code I have so far #include <GUIConstants.au3> #Region ### START Koda GUI section ### Form=z:\my programs\kanaattacks!\frmmaingui.kxf $frmMain = GUICreate("Kana Attacks!", 720, 355, -1, -1) $grpInfo = GUICtrlCreateGroup("", 8, 0, 265, 305) $lblTime = GUICtrlCreateLabel("Time Left:", 32, 24, 93, 17) $lblTotalScore = GUICtrlCreateLabel("Score: ", 32, 56, 99, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) $picBackground1 = GUICtrlCreatePic(@ScriptDir & "\Images\Background1.bmp", 280, 0, 51, 305) $picBackground2 = GUICtrlCreatePic(@ScriptDir & "\Images\Background2.bmp", 331, 0, 42, 305) $picBackground3 = GUICtrlCreatePic(@ScriptDir & "\Images\Background3.bmp", 373, 0, 42, 305) $picBackground4 = GUICtrlCreatePic(@ScriptDir & "\Images\Background4.bmp", 415, 0, 42, 305) $picBackground5 = GUICtrlCreatePic(@ScriptDir & "\Images\Background5.bmp", 457, 0, 42, 305) $picBackground6 = GUICtrlCreatePic(@ScriptDir & "\Images\Background6.bmp", 499, 0, 42, 305) $picBackground7 = GUICtrlCreatePic(@ScriptDir & "\Images\Background7.bmp", 541, 0, 42, 305) $picBackground8 = GUICtrlCreatePic(@ScriptDir & "\Images\Background8.bmp", 583, 0, 42, 305) $picBackground9 = GUICtrlCreatePic(@ScriptDir & "\Images\Background9.bmp", 625, 0, 42, 305) $picBackground10 = GUICtrlCreatePic(@ScriptDir & "\Images\Background10.bmp", 667, 0, 51, 305) $frmGame = GUICreate("", 438, 305, 280, 0,$WS_POPUP,BitOr($WS_EX_LAYERED,$WS_EX_MDICHILD),$frmMain) $picShip = GUICtrlCreatePic(@ScriptDir & "\Images\Ship.gif", 253, 285, 50, 20) GUISetState(@SW_SHOW, $frmGame) GUISetState(@SW_SHOW, $frmMain) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEndbackground1.bmpbackground2.bmpbackground3.bmpbackground4.bmpbackground5.bmpbackground6.bmpbackground7.bmpbackground8.bmpbackground9.bmpbackground10.bmp Edited November 28, 2006 by ReverendJ1
Valuater Posted November 28, 2006 Posted November 28, 2006 (edited) maybe try $picBackground1 = GUICtrlCreatePic(@ScriptDir & "\Images\Background1.bmp", 280, 0, 51, 305) GUICtrlSetState( -1, $GUI_DISABLE) 8) Edited November 28, 2006 by Valuater
BigDod Posted November 28, 2006 Posted November 28, 2006 Comment out this GUI $frmGame = GUICreate("", 438, 305, 280, 0,$WS_POPUP,BitOr($WS_EX_LAYERED,$WS_EX_MDICHILD),$frmMain) and you can see the background Time you enjoyed wasting is not wasted time ......T.S. Elliot Suspense is worse than disappointment................Robert Burns God help the man who won't help himself, because no-one else will...........My Grandmother
ReverendJ1 Posted November 28, 2006 Author Posted November 28, 2006 Thank you for your quick respones! I just double-checked, but I had tried both of those. @Valuater - When I do that (I did it to each background) it doesn't seem to have any effect. @BigDod - True, when I comment out the second GUI I can see the background, but the transparent part of the spaceship stays pink (the transparent color I set in the gif file). I have been racking my brain all day with this combing the helpfile and forums to no avail. -ReverendJ1
GaryFrost Posted November 28, 2006 Posted November 28, 2006 The dll is from Larry, you can find it also in Example Scriptshttp://www.autoitscript.com/fileman/users/gafrost/BMP2RGN.dllSaved the gif as a bitmap ship.bmpexpandcollapse popup#include <GUIConstants.au3> #Region ### START Koda GUI section ### Form=z:\my programs\kanaattacks!\frmmaingui.kxf $frmMain = GUICreate("Kana Attacks!", 720, 355, -1, -1) $grpInfo = GUICtrlCreateGroup("", 8, 0, 265, 305) $lblTime = GUICtrlCreateLabel("Time Left:", 32, 24, 93, 17) $lblTotalScore = GUICtrlCreateLabel("Score: ", 32, 56, 99, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) Dim $picBackground[11] $picBackground[1] = GUICtrlCreatePic(@ScriptDir & "\Images\Background1.bmp", 280, 0, 51, 305) GUICtrlSetState($picBackground[1], $GUI_DISABLE) $x = 331 For $z = 2 To 9 $picBackground[$z] = GUICtrlCreatePic(@ScriptDir & "\Images\Background" & $z & ".bmp", $x, 0, 42, 305) GUICtrlSetState($picBackground[$z], $GUI_DISABLE) $x += 42 Next $picBackground[10] = GUICtrlCreatePic(@ScriptDir & "\Images\Background10.bmp", 667, 0, 51, 305) GUICtrlSetState($picBackground[10], $GUI_DISABLE) $frmGame = GUICreate("ship", 50, 20, 280, 0,$WS_POPUP,$WS_EX_MDICHILD,$frmMain) $picShip = GUICtrlCreatePic(@ScriptDir & "\Images\Ship.bmp", 0, 0, 50, 20) $a = DLLCall(@ScriptDir & "\BMP2RGN.dll","int","BMP2RGN", _ "str",@ScriptDir & "\Images\Ship.bmp", _ "int",255, _ "int",0, _ "int",255) SetWindowRgn($frmGame, $a[0]) GUISetState(@SW_SHOW, $frmMain) GUISetState(@SW_SHOW, $frmGame) $winpos = WinGetPos($frmMain) $winX = $winpos[0] + 280 For $x = 1 To 60 $winX += 5 WinMove($frmGame,"", $winX, $winpos[1] + 30) Sleep ( 100 ) Next #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func SetWindowRgn($h_win, $rgn) DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $h_win, "long", $rgn, "int", 1) EndFunc SciTE for AutoItDirections for Submitting Standard UDFs  Don't argue with an idiot; people watching may not be able to tell the difference. Â
ReverendJ1 Posted November 29, 2006 Author Posted November 29, 2006 (edited) @gafrost - Thank you. That works fairly good. It doesn't seem to make all the transparent part transparent all the time though. There was a couple spots that kept showing up and disappearing. Hmm. Also, thanks for the hint on how to shorten the code. I have to go through and shorten all my code soon.I did however find a way to do it flawlessly (so far)! This method works very well, and I have done it with several moving pictures on the screen at the same time. You simply have to create a new GUI for EACH gif, sized to the size of the gif. Originally I was planning on having one GUI on top where all the action would happen, because that is how I interpreted the help file. But no, one GUI for each gif. #include <GUIConstants.au3> #Region ### START Koda GUI section ### Form=z:\my programs\kanaattacks!\frmmaingui.kxf $frmMain = GUICreate("Kana Attacks!", 720, 355, 100, 100) $grpInfo = GUICtrlCreateGroup("", 8, 0, 265, 305) $lblTime = GUICtrlCreateLabel("Time Left:", 32, 24, 93, 17) $lblTotalScore = GUICtrlCreateLabel("Score: ", 32, 56, 99, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) $picBackground1 = GUICtrlCreatePic(@ScriptDir & "\Images\Background1.bmp", 280, 0, 51, 305) $picBackground2 = GUICtrlCreatePic(@ScriptDir & "\Images\Background2.bmp", 331, 0, 42, 305) $picBackground3 = GUICtrlCreatePic(@ScriptDir & "\Images\Background3.bmp", 373, 0, 42, 305) $picBackground4 = GUICtrlCreatePic(@ScriptDir & "\Images\Background4.bmp", 415, 0, 42, 305) $picBackground5 = GUICtrlCreatePic(@ScriptDir & "\Images\Background5.bmp", 457, 0, 42, 305) $picBackground6 = GUICtrlCreatePic(@ScriptDir & "\Images\Background6.bmp", 499, 0, 42, 305) $picBackground7 = GUICtrlCreatePic(@ScriptDir & "\Images\Background7.bmp", 541, 0, 42, 305) $picBackground8 = GUICtrlCreatePic(@ScriptDir & "\Images\Background8.bmp", 583, 0, 42, 305) $picBackground9 = GUICtrlCreatePic(@ScriptDir & "\Images\Background9.bmp", 625, 0, 42, 305) $picBackground10 = GUICtrlCreatePic(@ScriptDir & "\Images\Background10.bmp", 667, 0, 51, 305) $frmShip = GUICreate("Kana Attacks!", 50, 20, 453, 285, $WS_POPUP,$WS_EX_LAYERED+$WS_EX_MDICHILD,$frmMain) $picShip = GUICtrlCreatePic(@ScriptDir & "\Images\Ship.gif", 0, 0, 50, 20) GUISetState(@SW_SHOW, $frmMain) GUISetState(@SW_SHOW, $frmShip) GUISwitch($frmMain) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEndEDIT - I forgot to change the code. Edited November 29, 2006 by ReverendJ1
dabus Posted November 29, 2006 Posted November 29, 2006 (edited) Had the same problem a feew months ago... If you have correct gifs (some don't work, I had to play a little with gimp and irfan_view) try this for your background gif: $BG = GUICtrlCreatePic(@ScriptDir & '\Transparent.gif', 0, 0, 450, 450, 0) Worked for me on WinXP Pro SP1, sorry, can't test right now... Edited November 29, 2006 by dabus
ReverendJ1 Posted November 29, 2006 Author Posted November 29, 2006 @Dabus - So you would create a transparent picture to use as the background of the top GUI ($frmGame) and then just create the ship as a picture on top of that? Is that what you are saying? I am just trying to clarify. I tried that already, but it doesn't seem to work. It only shows the ship transparent, and where the background is supposed to be transparent is all just the color that transparent is set to. If I take out the ship, and just leave the transparent background, then the background shows up transparent, so I know that the gif is ok.
dabus Posted November 29, 2006 Posted November 29, 2006 Yes, the 0 at the end of the line puts the background-gif on the lowest layer, and then the rest is on the top layer. Here's my example:; Creating GUI $Gui = GUICreate('DApwal', $Num * $IconVSize, $Num * $IconVSize, $b, $c, $WS_POPUP, $WS_EX_LAYERED+$WS_EX_TOPMOST+$WS_EX_TOOLWINDOW ) $BG = GUICtrlCreatePic(@ScriptDir & '\Icons\Basic\AllTrans.gif', 0, 0, 450, 450, 0); this is the background layer <<< GUICtrlCreateLabel('Test', -50, -50, 10, 10) ; Please note that you need to resize AllTrans.gif and recompile the script if you want a bigger transparent GUI than 450*450 ; Creating GUI and visible icons For $Row = 0 To $Num - 1 For $Col = 0 To $Num - 1 $Index = $Row * $Num + $Col $Command = IniRead($IniFile, $a&$Index, 'Command', '') If $Command <> '' Then $Pic = IniRead($IniFile, $a&$Index, 'Icon', @ScriptDir & '\Icons\Basic\Question.gif') $Icons[$Index] = GUICtrlCreatePic($Pic, $IconVSize * $Col, $IconVSize * $Row, $IconSize, $IconSize); >>>this is the top layer<<< GUICtrlSetTip(-1, $Command) EndIf Next Next GUISetState(@SW_SHOW, $Gui)Please have a look at dapwal, the code above is a part of it: http://www.autoitscript.com/forum/index.php?showtopic=23693
ReverendJ1 Posted November 29, 2006 Author Posted November 29, 2006 I can't seem to get that method to work. I added the 0 to the end of GUICtrlCreatePic for the background, but it still shows up as non-transparent. I also tried using your dapwal program and I couldn't seem to get that working either. Or maybe I just don't understand it. I changed all the fileinstall paths to where I had unpacked the files, and then I changed the paths in the .ini file but nothing showed up. It actually hid my Firefox, Scite, and a help file's windows. I tried pushing ctrl-shift and ctrl-tab, but nothing happened.
dabus Posted November 30, 2006 Posted November 30, 2006 Hmm, do you run win2k? I had another proggie that had problems with transparency under win2k... just did not work.
ReverendJ1 Posted December 5, 2006 Author Posted December 5, 2006 @Dabus - Were you able to get my code working on your computer? I hope I don't sound like I am trying to get you guys to write my code for me, but I am stuck here. Although I have figured out the workaround making a new GUI for each transparent gif, it is not very elegant, and I know that it is possible to do what you say. It just doesn't seem to working for me, or I am missing something.
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