Jump to content
Sign in to follow this  
leonidas

Cant receive notify events from GUICtrlCreatePic control

Recommended Posts

leonidas

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

#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
;

Share this post


Link to post
Share on other sites
Melba23

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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
leonidas

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.

Share this post


Link to post
Share on other sites
Melba23

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.

M23

Edit: a screengrab showing the code without $WS_EX_TRANSPARENT and with a transparent .gif: :)

Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
leonidas

Melba23

Thanks for your help. You solve my problem :)

Thank you once again.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×