leonidas Posted November 18, 2009 Share Posted November 18, 2009 Hi i have a small problem I want to make a png image to act like button by getting notify events from mouse. If I use only one GUI and then add .png image with GUICtrlCreatePic then i receive Mouse events but when I use more GUI controls (so to have better transparency effects for my project), I cant make the second png image to work like button. Thanks in advance expandcollapse popup#include <GDIPlus.au3> #include <WindowsConstants.au3> #include <GuiConstantsEx.au3> #include <StaticConstants.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, 54, 30, 20, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TRANSPARENT, $WS_EX_MDICHILD), $GUI) ; 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) Global $ControlPic = GUICtrlCreatePic('C:\Program Files\AutoIt3\Examples\GUI\logo4.gif', 0, 0, 169, 68, $SS_NOTIFY); <---- This is the problem GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $ControlPic MsgBox(0, "Message", "Test Click OK",5) 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 ; Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 18, 2009 Moderators Share Posted November 18, 2009 leonidas,Try removing the $WS_EX_LAYERED style from your $controlGui3. Then look for the "mouse primary down" event and see if the mouse is over the picture by using GUIGetCursorInfo - works for me every time: ; D label - showws on top of Image $controlGui3 = GUICreate("2ndControlGUI", 169, 68, 30, 120, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $GUI) Global $ControlPic = GUICtrlCreatePic('C:\Program Files\AutoIt3\Examples\GUI\logo4.gif', 0, 0, 169, 68, $SS_NOTIFY); <---- This is the problem GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_PRIMARYDOWN $aInfo = GUIGetCursorInfo($controlGui3) If $aInfo[4] = $ControlPic Then MsgBox(0, "Message", "Test Click OK",5)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 Link to comment Share on other sites More sharing options...
leonidas Posted November 18, 2009 Author Share Posted November 18, 2009 leonidas, Try removing the $WS_EX_LAYERED style from your $controlGui3. Then look for the "mouse primary down" event and see if the mouse is over the picture by using GUIGetCursorInfo - works for me every time: ; D label - showws on top of Image $controlGui3 = GUICreate("2ndControlGUI", 169, 68, 30, 120, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $GUI) Global $ControlPic = GUICtrlCreatePic('C:\Program Files\AutoIt3\Examples\GUI\logo4.gif', 0, 0, 169, 68, $SS_NOTIFY); <---- This is the problem GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_PRIMARYDOWN $aInfo = GUIGetCursorInfo($controlGui3) If $aInfo[4] = $ControlPic Then MsgBox(0, "Message", "Test Click OK",5) M23 First of all ,thanks for the reply. After removing $WS_EX_LAYERED ,I start to receive CLICK events but the second image (gif image) stopped to be transparent. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 18, 2009 Moderators Share Posted November 18, 2009 (edited) leonidas,Apologies, I meant $WS_EX_TRANSPARENT as in the code I posted. Have you tried running it yet? I get a transparent background to the .gif and clicks registered.M23Edit: a screengrab showing the code without $WS_EX_TRANSPARENT and with a transparent .gif: Edited November 18, 2009 by Melba23 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 Link to comment Share on other sites More sharing options...
leonidas Posted November 19, 2009 Author Share Posted November 19, 2009 Melba23 Thanks for your help. You solve my problem Thank you once again. 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