AustrianOak Posted February 22, 2009 Posted February 22, 2009 I have a question with a problem I have with png files in my program. I need to get rid of the window border around my window and want everything except my image file (which is a fish) to be transparent. (you're going to have to get a subsitute image file that's 26 by 26) How do I do this? expandcollapse popup#include <GDIPlus.au3> #include <GUIConstants.au3> #include <WindowsConstants.au3> #include <array.au3> #include <misc.au3> Global $GUI_OBJECT[1][5]; 0=hwnd, 1=width, 2=height, 3=graphics obj, 4 = img obj Opt("GUIOnEventMode",1) $hwnd=GUICreate("Parent",400,300) GUISetOnEvent($GUI_EVENT_CLOSE,"close") GUISetState() _GDIPlus_Startup() $GUI_OBJECT[0][0]=$hwnd $GUI_OBJECT[0][1]=26 $GUI_OBJECT[0][2]=26 $GUI_OBJECT[0][3]=_GDIPlus_GraphicsCreateFromHWND($hwnd) $GUI_OBJECT[0][4]=_GDIPlus_ImageLoadFromFile("background.png") _RePaint($GUI_OBJECT[0][0],0,0,0) GUIRegisterMsg($WM_PAINT,"_RePaint") Do Sleep(20) If _IsPressed("01") And WinActive($hwnd) Then _CreateChild($hwnd,Random(0,@DesktopWidth,1),Random(0,@DesktopHeight,1),26,26,"background.png") Do Sleep(10) Until Not _IsPressed("01") EndIf Until False Func _CreateChild($parent,$x,$y,$w,$h,$imagename) ReDim $GUI_OBJECT[Ubound($GUI_OBJECT)+1][5] $GUI_OBJECT[Ubound($GUI_OBJECT)-1][0]=GUICreate("Child number: "&Ubound($GUI_OBJECT),$w,$h,$x,$y) GUISetState(@SW_SHOW,$GUI_OBJECT[Ubound($GUI_OBJECT)-1][0]) $GUI_OBJECT[Ubound($GUI_OBJECT)-1][1]=$w $GUI_OBJECT[Ubound($GUI_OBJECT)-1][2]=$h $GUI_OBJECT[Ubound($GUI_OBJECT)-1][3]=_GDIPlus_GraphicsCreateFromHWND($GUI_OBJECT[Ubound($GUI_OBJECT)-1][0]) $GUI_OBJECT[Ubound($GUI_OBJECT)-1][4]=_GDIPlus_ImageLoadFromFile($imagename) GUISetOnEvent($GUI_EVENT_CLOSE,"close",$GUI_OBJECT[Ubound($GUI_OBJECT)-1][0]) _RePaint($GUI_OBJECT[Ubound($GUI_OBJECT)-1][0],0,0,0) EndFunc Func _RePaint($hwndparam,$msg,$wparam,$lparam) For $i=0 To UBound($GUI_OBJECT)-1 If $hwndparam=$GUI_OBJECT[$i][0] Then _GDIPlus_GraphicsDrawImageRect($GUI_OBJECT[$i][3],$GUI_OBJECT[$i][4],0,0,$GUI_OBJECT[$i][1],$GUI_OBJECT[$i][2]) ExitLoop EndIf Next Return $GUI_RUNDEFMSG EndFunc Func close() If @GUI_WinHandle<>$hwnd THen For $i=0 To UBound($GUI_OBJECT)-1 If @GUI_WinHandle=$GUI_OBJECT[$i][0] Then _GDIPlus_GraphicsDispose($GUI_OBJECT[$i][3]) _GDIPlus_ImageDispose($GUI_OBJECT[$i][4]) GUIDelete($GUI_OBJECT[$i][0]) _ArrayDelete($GUI_OBJECT,$i) Return EndIf Next EndIf For $i=0 To UBound($GUI_OBJECT)-1 _GDIPlus_GraphicsDispose($GUI_OBJECT[$i][3]) _GDIPlus_ImageDispose($GUI_OBJECT[$i][4]) Next _GDIPlus_Shutdown() Exit EndFunc
ChangMinYang Posted February 22, 2009 Posted February 22, 2009 How about this?http://www.autoitscript.com/forum/index.ph...st&p=358069
AustrianOak Posted February 22, 2009 Author Posted February 22, 2009 If it requires a higher version than 3.2.11.5 I cant use it. If it doesnt, where might I be able to find the include <A3LGDIPlus.au3>?
DaRam Posted February 23, 2009 Posted February 23, 2009 bumpSee attached (2 AU3 & a PNG)SplashTest.Au3Splash.Au3
AustrianOak Posted February 23, 2009 Author Posted February 23, 2009 thanks. i think this might work. i've been trying to tweak it towards my needs and i cant figure out how to get the flash to appear and then just stay there.
AustrianOak Posted February 23, 2009 Author Posted February 23, 2009 i figured out i shouldnt call the DismissSplash() but when i take that out in line 9 then the png doesnt appear?
DaRam Posted February 24, 2009 Posted February 24, 2009 (edited) i figured out i shouldnt call the DismissSplash() but when i take that out in line 9 then the png doesnt appear?@AustrianOak, I'm sorry I could not respond to your PM's. Perhaps this is what you are looking for - change the png filename to whatever your png is called. expandcollapse popup#NoTrayIcon #include <WindowsConstants.au3> #include <GUIConstants.au3> #Include <GDIPlus.au3> Local $SplashGUI, $hSplashImage Local $pngSrc, $width, $height, $i $pngSrc = @WorkingDir & "\Splash.png" _GDIPlus_Startup() $hSplashImage = _GDIPlus_ImageLoadFromFile($pngSrc) ; Extract image width and height from PNG $width = _GDIPlus_ImageGetWidth($hSplashImage) $height = _GDIPlus_ImageGetHeight($hSplashImage) ; Create layered window $SplashGUI = GUICreate("", $width, $height, -1, -1, $WS_POPUP, $WS_EX_LAYERED, $DS_MODALFRAME) SetBitmap($SplashGUI, $hSplashImage, 0) GUISetState() WinSetOnTop($SplashGUI, "", 1) ;Sleep(500) ;fade in png background For $i = 0 To 255 Step 5 SetBitmap($SplashGUI, $hSplashImage, $i) Next ;Sleep(1000) While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE, $GUI_EVENT_PRIMARYDOWN, $GUI_EVENT_PRIMARYUP ExitLoop EndSwitch Wend ; Below commented out, necessary only if in a separate function ;If Not IsHWnd($SplashGUI) Then ; SetError(1) ; Exit; <- Should be 'Return' if in a Fn. ;EndIf ;fade out png background For $i = 255 To 0 Step - 5 SetBitmap($SplashGUI, $hSplashImage, $i) Next ; Release resources _GDIPlus_ImageDispose($hSplashImage) _GDIPlus_Shutdown() GUIDelete($SplashGUI) Func SetBitmap($hGUI, $hImage, $iOpacity) Const $AC_SRC_ALPHA = 1 ;Const $ULW_ALPHA = 2 Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend local $hBrush, $hFormat, $hFamily, $hFont, $tLayout,$hGraphic $hScrDC = _WinAPI_GetDC(0) $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC) $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) $hOld = _WinAPI_SelectObject($hMemDC, $hBitmap) $hGraphic = _GDIPlus_GraphicsCreateFromHDC ($hMemDC) $hBrush = _GDIPlus_BrushCreateSolid (0xffFA0C0A) $hFormat = _GDIPlus_StringFormatCreate () $hFamily = _GDIPlus_FontFamilyCreate ("Arial") $hFont = _GDIPlus_FontCreate ($hFamily, 32, 1) $tLayout = _GDIPlus_RectFCreate ( 100, 200, 350, 50 ) $tSize = DllStructCreate($tagSIZE) $pSize = DllStructGetPtr($tSize) DllStructSetData($tSize, "X", _GDIPlus_ImageGetWidth($hImage)) DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($hImage)) $tSource = DllStructCreate($tagPOINT) $pSource = DllStructGetPtr($tSource) $tBlend = DllStructCreate($tagBLENDFUNCTION) $pBlend = DllStructGetPtr($tBlend) DllStructSetData($tBlend, "Alpha", $iOpacity) DllStructSetData($tBlend, "Format", $AC_SRC_ALPHA) _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA) _WinAPI_ReleaseDC(0, $hScrDC) _WinAPI_SelectObject($hMemDC, $hOld) _WinAPI_DeleteObject($hBitmap) _WinAPI_DeleteDC($hMemDC) _GDIPlus_FontDispose ($hFont) _GDIPlus_FontFamilyDispose ($hFamily) _GDIPlus_StringFormatDispose ($hFormat) _GDIPlus_BrushDispose ($hBrush) EndFunc ;==>SetBitmap Edited February 26, 2009 by DaRam
AustrianOak Posted February 24, 2009 Author Posted February 24, 2009 Well in taskmanager it shows your script is running but again, no png can be seen.
DaRam Posted February 25, 2009 Posted February 25, 2009 (edited) Back again - I ran the code I posted and it works fine. Could someone else try and run this to verify?Anyone else feel free to jump in. Sorry I'm offline in 3,2,1.... bumpy Edited February 26, 2009 by DaRam
DaRam Posted February 26, 2009 Posted February 26, 2009 Well in taskmanager it shows your script is running but again, no png can be seen.Can someone else run the code in Post #8 #648608Please use the PNG in Post #5 #648307
Moderators Melba23 Posted February 26, 2009 Moderators Posted February 26, 2009 DaRam,Ran without problems (once I changed the Return in line 35 to Exit) and produced the result below (shown against my Vista blue desktop).M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
DaRam Posted February 26, 2009 Posted February 26, 2009 Thanks Melba23. Did you have an issue like the OP w/o the change in line 35? I think the return was left over from when this code was in a separate function, in any case I've commented it out (since it is not necessary) in Post #8. AustrianOak could you check? If you have modified the code or incorporated it in your own code and are having issues, please do mention this and post relevant code.DaRam,Ran without problems (once I changed the Return in line 35 to Exit) and produced the result below (shown against my Vista blue desktop).M23
Moderators Melba23 Posted February 26, 2009 Moderators Posted February 26, 2009 DaRam, SciTE would not let me run the script without changing that line, so I cannot say if any problems resulted from leaving it in. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
AustrianOak Posted March 8, 2009 Author Posted March 8, 2009 Thanks Melba23. Did you have an issue like the OP w/o the change in line 35? I think the return was left over from when this code was in a separate function, in any case I've commented it out (since it is not necessary) in Post #8. AustrianOak could you check? If you have modified the code or incorporated it in your own code and are having issues, please do mention this and post relevant code.DaRam, sorry I've been away so long. Concerning the script, strangely when I started it up today the script worked perfectly and the png appeared and stayed until I clicked on it. I hadn't even changed any lines yet but since you said the Return on line 35 wasn't necessary I commented it out and the script remained working. One question though, does the script close once you click on the png? If so what part of the script is responsible for this?
Recommended Posts