Sign in to follow this  
Followers 0
qwert

Need idea for providing visual feedback upon click

2 posts in this topic

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>

_GDIPlus_Startup()
$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
GUISetState()

While 1
  Switch GUIGetMsg()
    Case $exit
      _GDIPlus_GraphicsDispose($hGraphic)
      _GDIPlus_ImageDispose($hImage)
      _GDIPlus_Shutdown()
      GUIDelete()
      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)
   EndSwitch
WEnd
;
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)
    _WinAPI_DeleteObject($hBitmap)
    _WinAPI_DeleteDC($hMemDC)
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.

 

post-29172-0-18194900-1420270800.png

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:

post-29172-0-15299000-1420324959.gif

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  
Followers 0