lordicast Posted July 9, 2009 Posted July 9, 2009 Is it possible to run a GuiCtrlCreatePic inside a PNG GUI? I have been trying for a hour or so maybe I am just overlooking something when I use the code below it makes the Gui Png turn gray and distorts my Pic, Any thoughts? expandcollapse popup#NoTrayIcon #include <GDIPlus.au3> #include <GuiComboBox.au3> #include <File.au3> #include <Array.au3> #include <WindowsConstants.au3> #include <GuiConstantsEx.au3> #include <ButtonConstants.au3> #include <_Animate_Window_UDF.au3> #include <inet.au3> #include <ie.au3> #Include <WinAPI.au3> HotKeySet('{esc}','_exit') Global Const $AC_SRC_ALPHA = 1 Global $old_string = "", $runthis = "" Global $launchDir = 'C:\' ; Load PNG file as GDI bitmap _GDIPlus_Startup() $pngSrc = @ScriptDir & "\ipwn3.png" $hImage = _GDIPlus_ImageLoadFromFile($pngSrc) ;++++ ;+++ ; Extract image width and height from PNG $width = _GDIPlus_ImageGetWidth($hImage) $height = _GDIPlus_ImageGetHeight($hImage) ;++++ ; Create layered window $GUI = GUICreate("lod3n launcher", $width, $height,-1,-1, $WS_POPUP, $WS_EX_LAYERED) SetBitmap($GUI, $hImage, 0) ; Register notification messages GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST") GUISetState() WinSetOnTop($GUI, "", 1) ;fade in png background For $i = 0 To 255 Step 10 sleep(10) SetBitmap($GUI, $hImage, $i) Next $controlGui = GUICreate("ControlGUI", $width, $height,0, 0, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $GUI) GUICtrlCreatePic(@ScriptDir & "\grey.gif", 0, 0, $width, $height) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlCreateLabel("Concept v.1", 10, 10, 140, 50) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetColor(-1, 0xFFFFFF) $Pic = GUICtrlCreatePic(@ScriptDir & '/logo',100,100,200,200); <---- This is the problem GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop EndSelect WEnd Func _exit() GUIDelete($controlGui) ;fade out png background For $i = 255 To 0 Step -10 sleep(30) SetBitmap($GUI, $hImage, $i) Next ; Release resources _WinAPI_DeleteObject($hImage) _GDIPlus_Shutdown() Exit EndFunc ; ==================================================================================================== ; Handle the WM_NCHITTEST for the layered window so it can be dragged by clicking anywhere on the image. ; ==================================================================================================== Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam) If ($hWnd = $GUI) And ($iMsg = $WM_NCHITTEST) Then Return $HTCAPTION EndFunc ;==>WM_NCHITTEST Func SetBitmap($hGUI, $hImage, $iOpacity) Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend $hScrDC = _WinAPI_GetDC(0) $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC) $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) $hOld = _WinAPI_SelectObject($hMemDC, $hBitmap) $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) EndFunc ;==>SetBitmap [Cheeky]Comment[/Cheeky]
Malkey Posted July 9, 2009 Posted July 9, 2009 (edited) Is it possible to run a GuiCtrlCreatePic inside a PNG GUI? I have been trying for a hour or so maybe I am just overlooking something when I use the code below it makes the Gui Png turn gray and distorts my Pic, Any thoughts? expandcollapse popup#NoTrayIcon #include <GDIPlus.au3> #include <GuiComboBox.au3> #include <File.au3> #include <Array.au3> #include <WindowsConstants.au3> #include <GuiConstantsEx.au3> #include <ButtonConstants.au3> #include <_Animate_Window_UDF.au3> #include <inet.au3> #include <ie.au3> #Include <WinAPI.au3> HotKeySet('{esc}','_exit') Global Const $AC_SRC_ALPHA = 1 Global $old_string = "", $runthis = "" Global $launchDir = 'C:\' ; Load PNG file as GDI bitmap _GDIPlus_Startup() $pngSrc = @ScriptDir & "\ipwn3.png" $hImage = _GDIPlus_ImageLoadFromFile($pngSrc) ;++++ ;+++ ; Extract image width and height from PNG $width = _GDIPlus_ImageGetWidth($hImage) $height = _GDIPlus_ImageGetHeight($hImage) ;++++ ; Create layered window $GUI = GUICreate("lod3n launcher", $width, $height,-1,-1, $WS_POPUP, $WS_EX_LAYERED) SetBitmap($GUI, $hImage, 0) ; Register notification messages GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST") GUISetState() WinSetOnTop($GUI, "", 1) ;fade in png background For $i = 0 To 255 Step 10 sleep(10) SetBitmap($GUI, $hImage, $i) Next $controlGui = GUICreate("ControlGUI", $width, $height,0, 0, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $GUI) GUICtrlCreatePic(@ScriptDir & "\grey.gif", 0, 0, $width, $height) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlCreateLabel("Concept v.1", 10, 10, 140, 50) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetColor(-1, 0xFFFFFF) $Pic = GUICtrlCreatePic(@ScriptDir & '/logo',100,100,200,200); <---- This is the problem GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop EndSelect WEnd Func _exit() GUIDelete($controlGui) ;fade out png background For $i = 255 To 0 Step -10 sleep(30) SetBitmap($GUI, $hImage, $i) Next ; Release resources _WinAPI_DeleteObject($hImage) _GDIPlus_Shutdown() Exit EndFunc ; ==================================================================================================== ; Handle the WM_NCHITTEST for the layered window so it can be dragged by clicking anywhere on the image. ; ==================================================================================================== Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam) If ($hWnd = $GUI) And ($iMsg = $WM_NCHITTEST) Then Return $HTCAPTION EndFunc ;==>WM_NCHITTEST Func SetBitmap($hGUI, $hImage, $iOpacity) Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend $hScrDC = _WinAPI_GetDC(0) $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC) $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) $hOld = _WinAPI_SelectObject($hMemDC, $hBitmap) $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) EndFunc ;==>SetBitmap I played around with your script. This is something. expandcollapse popup; #NoTrayIcon #include <GDIPlus.au3> #include <GuiComboBox.au3> #include <File.au3> #include <Array.au3> #include <WindowsConstants.au3> #include <GuiConstantsEx.au3> #include <ButtonConstants.au3> ;#include <_Animate_Window_UDF.au3> #include <inet.au3> #include <ie.au3> #include <WinAPI.au3> HotKeySet('{esc}', '_exit') Global Const $AC_SRC_ALPHA = 1 Global $old_string = "", $runthis = "" Global $launchDir = 'C:\' ; Load PNG file as GDI bitmap _GDIPlus_Startup() $pngSrc = "C:\Program Files\AutoIt3\Examples\GUI\Advanced\Images\Torus.png" $hImage = _GDIPlus_ImageLoadFromFile($pngSrc) $width = _GDIPlus_ImageGetWidth($hImage) $height = _GDIPlus_ImageGetHeight($hImage) ; Create layered window $GUI = GUICreate("lod3n launcher", $width, $height, -1, -1, $WS_POPUP, $WS_EX_LAYERED) SetBitmap($GUI, $hImage, 0) ; Register notification messages GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST") GUISetState() WinSetOnTop($GUI, "", 1) ;fade in png background For $i = 0 To 255 Step 10 Sleep(10) SetBitmap($GUI, $hImage, $i) Next $controlGui = GUICreate("ControlGUI", 84, 34, 30, 30, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TRANSPARENT, $WS_EX_MDICHILD), $GUI) GUICtrlCreatePic("C:\Program Files\AutoIt3\Examples\GUI\logo4.gif", 0, 0, 84, 34) GUICtrlSetState(-1, $GUI_DISABLE) GUISetState() $controlGui2 = GUICreate("2ndControlGUI", 169, 68, 30, 120, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TRANSPARENT, $WS_EX_MDICHILD), $GUI) GUICtrlCreatePic('C:\Program Files\AutoIt3\Examples\GUI\logo4.gif', 0, 0, 169, 68); <---- This is the problem GUICtrlSetState(-1, $GUI_DISABLE) GUISetState() $controlGui3 = GUICreate("3ndControlGUI", 100, 35, 10, 80, $WS_POPUP, $WS_EX_MDICHILD, $GUI) WinSetTrans($controlGui3, "", 10) GUISetBkColor($GUI_BKCOLOR_TRANSPARENT, $controlGui3) GUICtrlCreatePic('', 0, 0, 1, 1) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlCreateLabel("A label", 0, 0, 100, 35) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop EndSelect WEnd Func _exit() GUIDelete($controlGui) ;fade out png background For $i = 255 To 0 Step -10 Sleep(30) SetBitmap($GUI, $hImage, $i) Next ; Release resources _GDIPlus_ImageDispose($hImage) _GDIPlus_Shutdown() Exit EndFunc ;==>_exit ; ==================================================================================================== ; Handle the WM_NCHITTEST for the layered window so it can be dragged by clicking anywhere on the image. ; ==================================================================================================== Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam) If ($hWnd = $GUI) And ($iMsg = $WM_NCHITTEST) Then Return $HTCAPTION EndFunc ;==>WM_NCHITTEST Func SetBitmap($hGUI, $hImage, $iOpacity) Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend $hScrDC = _WinAPI_GetDC(0) $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC) $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) $hOld = _WinAPI_SelectObject($hMemDC, $hBitmap) $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) EndFunc ;==>SetBitmap ; Edit: Had wrong drive letter for first image. Edited July 9, 2009 by Malkey
lordicast Posted July 9, 2009 Author Posted July 9, 2009 I see, So in order to add a pic on top of the gui you need to add another control gui? The label worked like .. GUICtrlCreateLabel("Concept v.1", 10, 10, 140, 50) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetColor(-1, 0xFFFFFF) Is there another reason you added a control gui for that? Thanks Malkey! [Cheeky]Comment[/Cheeky]
Malkey Posted July 9, 2009 Posted July 9, 2009 I see, So in order to add a pic on top of the gui you need to add another control gui? The label worked like .. GUICtrlCreateLabel("Concept v.1", 10, 10, 140, 50) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetColor(-1, 0xFFFFFF) Is there another reason you added a control gui for that? Thanks Malkey! Here is an example to show my reasoning why the label was given its own child GUI. Looking at the scripts generated image:- A label is on parent GUI. Does not display. B label is on exposed area of child GUI, not over image. I couldn't make this child GUI transparent. C label is on its own GUI. Transparent background, and can be placed any where on desktop. D label is over image on child GUI. Positioning is restricted to over image on child GUI. The strange thing about this is, the help file has a note for the Extended Style parameter, $WS_EX_LAYERED, for GUICreate() saying, "... this cannot be used for child windows." expandcollapse popup; #NoTrayIcon #include <GDIPlus.au3> #include <GuiComboBox.au3> #include <File.au3> #include <Array.au3> #include <WindowsConstants.au3> #include <GuiConstantsEx.au3> #include <ButtonConstants.au3> ;#include <_Animate_Window_UDF.au3> #include <inet.au3> #include <ie.au3> #include <WinAPI.au3> HotKeySet('{esc}', '_exit') Global Const $AC_SRC_ALPHA = 1 Global $old_string = "", $runthis = "" Global $launchDir = 'C:\' ; Load PNG file as GDI bitmap _GDIPlus_Startup() $pngSrc = "C:\Program Files\AutoIt3\Examples\GUI\Advanced\Images\Torus.png" $hImage = _GDIPlus_ImageLoadFromFile($pngSrc) $width = _GDIPlus_ImageGetWidth($hImage) $height = _GDIPlus_ImageGetHeight($hImage) ; Create layered window $GUI = GUICreate("lod3n launcher", $width, $height, -1, -1, $WS_POPUP, $WS_EX_LAYERED) SetBitmap($GUI, $hImage, 0) ;A label - On Parent GUI NOT displaying GUICtrlCreateLabel("A label", ($width + 100) / 2, 5, 100, 35) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) ; Register notification messages GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST") GUISetState() WinSetOnTop($GUI, "", 1) ;fade in png background For $i = 0 To 255 Step 10 Sleep(10) SetBitmap($GUI, $hImage, $i) Next $controlGui = GUICreate("ControlGUI", 84, 54, 30, 20, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TRANSPARENT, $WS_EX_MDICHILD), $GUI) GUICtrlCreatePic("C:\Program Files\AutoIt3\Examples\GUI\logo4.gif", 0, 20, 84, 34) GUICtrlSetState(-1, $GUI_DISABLE) ; B label - Shws backgroud of child GUI GUICtrlCreateLabel("B label", 5, 0, 79, 30) GUICtrlSetColor(-1, 0x0000FF) GUICtrlSetFont(-1, 10, 800) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUISetState() ; C label - has its own child GUI $controlGui2 = GUICreate("3ndControlGUI", 100, 35, 10, 80, $WS_POPUP, $WS_EX_MDICHILD, $GUI) WinSetTrans($controlGui2, "", 10) GUISetBkColor($GUI_BKCOLOR_TRANSPARENT, $controlGui2) GUICtrlCreatePic('', 0, 0, 1, 1) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlCreateLabel("C label", 0, 0, 100, 35) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUISetState() ; D label - showws on top of Image $controlGui3 = GUICreate("2ndControlGUI", 169, 68, 30, 120, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TRANSPARENT, $WS_EX_MDICHILD), $GUI) GUICtrlCreatePic('C:\Program Files\AutoIt3\Examples\GUI\logo4.gif', 0, 0, 169, 68); <---- This is the problem GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlCreateLabel("D label", 4, 24, 100, 35) GUICtrlSetColor(-1, 0x00000) GUICtrlSetFont(-1, 10, 800) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop EndSelect WEnd Func _exit() GUIDelete($controlGui) ;fade out png background For $i = 255 To 0 Step -10 Sleep(30) SetBitmap($GUI, $hImage, $i) Next ; Release resources _GDIPlus_ImageDispose($hImage) _GDIPlus_Shutdown() Exit EndFunc ;==>_exit ; ==================================================================================================== ; Handle the WM_NCHITTEST for the layered window so it can be dragged by clicking anywhere on the image. ; ==================================================================================================== Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam) If ($hWnd = $GUI) And ($iMsg = $WM_NCHITTEST) Then Return $HTCAPTION EndFunc ;==>WM_NCHITTEST Func SetBitmap($hGUI, $hImage, $iOpacity) Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend $hScrDC = _WinAPI_GetDC(0) $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC) $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) $hOld = _WinAPI_SelectObject($hMemDC, $hBitmap) $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) EndFunc ;==>SetBitmap ;
hot202 Posted August 20, 2009 Posted August 20, 2009 can u add the pictures so i can see how it looks?
Malkey Posted August 20, 2009 Posted August 20, 2009 can u add the pictures so i can see how it looks?These two pictures I used:-"C:\Program Files\AutoIt3\Examples\GUI\Advanced\Images\Torus.png", and,"C:\Program Files\AutoIt3\Examples\GUI\logo4.gif",I found in a sub-directory of the install directory of AutoIt3 on my computer's hard-drive.It is likely, you also have these image files.
hot202 Posted August 20, 2009 Posted August 20, 2009 i found a better way to do it just with a bmp and cerve the edges and make window transperent
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