Jump to content
Sign in to follow this  

Need idea for providing visual feedback upon click

Recommended Posts


Here’s a small version of a simple method I’ve been using to click on elements of a background GUI image.

;   Test of image button click feedback
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>

$backdrop = @ScriptDir & "\Back.png"    ; load graphic
$hImage = _GDIPlus_ImageLoadFromFile($backdrop)
$width = _GDIPlus_ImageGetWidth($hImage)
$height = _GDIPlus_ImageGetHeight($hImage)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
Global $GUI = GUICreate("Button Panel", $width, $height, -1, 300, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_LAYERED))  ; layered is necessary for graphic
$button1 = GUICtrlCreateLabel("", 50, 20, 40, 40)
GUICtrlSetTip ( -1, "Button 1")
$button2 = GUICtrlCreateLabel("", 130, 20, 40, 40)
GUICtrlSetTip ( -1, "Button 2")
$exit = GUICtrlCreateLabel("", 210, 20, 60, 60)
GUICtrlSetTip ( -1, "Click to exit")
_SetBitmap($GUI, $hImage, 255)  ; set graphic as background

While 1
  Switch GUIGetMsg()
    Case $exit
    Case $button1
      MsgBox(0, "Clicked", "First Button", 1)
    Case $button2
      MsgBox(0, "Clicked", "Second Button", 1)
    GUICtrlSetBkColor($button2, 0x222222)   ; this doesn't work
    Sleep(900)                              ;
    GUICtrlSetBkColor($button2, $GUI_BKCOLOR_TRANSPARENT)
Func _SetBitmap($hGUI, $hImage, $iOpacity)
    Local Const $AC_SRC_ALPHA = 1
    Local Const $ULW_ALPHA = 2
    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)
EndFunc   ;==>_SetBitmap


What I’d like to add is some sort of visual feedback—like a flashed rectangle or ring effect—when one of the elements is clicked.


My thought was to work with the background color of the individual labels (see button 2 in the script), but it doesn’t work. I suppose it’s because the control is actually defined on the layer below the graphic.


Can someone offer a suggestion of a simple mechanism?


Thanks in advance for any help.



Share this post

Link to post
Share on other sites

As clarification of the kind of visual feedback that would be ideal, I captured this example:


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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.