Jump to content
Sign in to follow this  
CrewXp

Knowing if a gui is clicked or not? Im using GDIPlus to make a png GUI. Want to know if someone clicks it.

Recommended Posts

CrewXp

I used to know how to do this, but I took a 3 year break from autoit lol.

Is it possible (without making an invisible ctrl overlaying my gui) to detect if my GUI is clicked on? I have it set that if I click it, my current application does not lose focus. It is just an overlay/toast. I made my gui using gdiplus and a transparent PNG. I tried using $GUI_EVENT_PRIMARYDOWN, but nothing happens when I press my mouse down on it.

Share this post


Link to post
Share on other sites
UEZ

You can create a picture control and send the PNG image to that control. GUIGetMsg() can check whether the pic control is clicked.

 

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
DatMCEyeBall

Oh! and see if you can write a longer topic title please.

Don't think there's a limit to that.


"Just be fred, all we gotta do, just be fred."  -Vocaliod

"That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha

@tabhooked

Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation

Share this post


Link to post
Share on other sites
CrewXp

Lol... argh. Okay. Sorry, it was 4am yesterday when I was trying to figure it out.

Code:

Func Test()
   Msgbox(0,"","")
EndFunc

Func Loader($type,$x, $y)
$loc="D:\Development\AutoIt\TestToast.png"
_GDIPlus_Startup()
$GUI = _GUICreate_Alpha("Look at the shiny", $loc, $x, $y)
GuiSetOnEvent($GUI_EVENT_PRIMARYDOWN,"Test")
$myGuiHandle = WinGetHandle("Look at the shiny")
GLOBAL $hGraphic = _GDIPlus_GraphicsCreateFromHWND ($myGuiHandle)
GUISetState()

$hwnd = GUICreate("ControlGUI", $toast_x,$toast_y, 0, 0, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $myGuiHandle)
GUISetBkColor(0xABCDEF)


;Failed attempt to use dllcall to slide down and fade in as it slides. Shows a random weird blue box
 ;DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 270, "long", 0x00040004) ; $SLIDE IN FROM TOP ;DOESNT WORK!!!!
#define AW_HOR_POSITIVE     0x00000001
#define AW_HOR_NEGATIVE     0x00000002
#define AW_VER_POSITIVE     0x00000004
#define AW_VER_NEGATIVE     0x00000008
#define AW_CENTER           0x00000010
#define AW_HIDE             0x00010000
#define AW_ACTIVATE         0x00020000
#define AW_SLIDE            0x00040000
#define AW_BLEND            0x00080000

If $type=1 Then
GLOBAL $obj_e1   = GUICtrlCreateLabel('Elevator 1: Uninitialized', 35, 19, 150, 25)
    GUICtrlSetColor(-1, 0xFFFFFF)
    EndIf
If $type=2 Then
GLOBAL $obj_e2   = GUICtrlCreateLabel('Elevator 2: Uninitialized', 35, 19, 150, 25)
    GUICtrlSetColor(-1, 0xFFFFFF)
    EndIf
If $type=3 Then
GLOBAL $obj_e3   = GUICtrlCreateLabel('Elevator 3: Uninitialized', 35, 19, 150, 25)
    GUICtrlSetColor(-1, 0xFFFFFF)
    EndIf
If $type=4 Then
GLOBAL $obj_m1   = GUICtrlCreateLabel('Main Entrance: Uninitialized', 35, 19, 150, 25)
    GUICtrlSetColor(-1, 0xFFFFFF)
EndIf
_WinAPI_SetLayeredWindowAttributes($hwnd, 0xABCDEF, 255)


;Failed Attempt to manually slide the gui down from top. Moves, but doesnt move text with it. And Cant fade using this
For $i=100 to 0 Step -1
WinMove($myGuiHandle, "", $x, $y-$i, $toast_x, $toast_y)
   If $i=100 Then GUISetState(@SW_SHOW,$myGuiHandle)
Sleep(1)
Next
GUISetState() EndFunc

Func _GUICreate_Alpha($sTitle, $sPath, $iX=-1, $iY=-1, $iOpacity=255)
    Local $hGUI, $hImage, $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend
    $hImage = _GDIPlus_ImageLoadFromFile($sPath)
    $width = _GDIPlus_ImageGetWidth($hImage)
    $height = _GDIPlus_ImageGetHeight($hImage)
    $hGUI = GUICreate($sTitle, $width, $height, $iX, $iY, $WS_POPUP, $WS_EX_LAYERED)


    $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", $width)
    DllStructSetData($tSize, "Y", $height)
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, "Alpha", $iOpacity)
    DllStructSetData($tBlend, "Format", 1)
    _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, 2)
    _WinAPI_ReleaseDC(0, $hScrDC)
    _WinAPI_SelectObject($hMemDC, $hOld)
    _WinAPI_DeleteObject($hBitmap)
    _WinAPI_DeleteObject($hImage)
    _WinAPI_DeleteDC($hMemDC)
EndFunc ;==>_GUICreate_Alpha

What I can't get:

-Clicking on the GUI After it's setup make it call a function.

-Having the gui/toast slide in from the top and fade in as it slides. Manually moving using WinMove only moves png, not text. Using the dllcall animates a random weird blue box.

Edited by CrewXp

Share this post


Link to post
Share on other sites
trancexx

Does that script work for you at all?

I have troubles understanding what exactly you want. How's this:

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include "GIFAnimation.au3"

Opt("GUICloseOnESC", 1); ESC to exit

Global $sFile = InetRead("http://files.myopera.com/supergreatChandu8/albums/5466862/smiley-transparent.png"); @ProgramFilesDir & "\AutoIt3\Examples\GUI\Torus.png"

$aGIFDimension = _GIF_GetDimension($sFile)
$hGui = GUICreate("GIF Animation", $aGIFDimension[0], $aGIFDimension[1], -1, -1, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_LAYERED))
GUISetBkColor(0xFFFFFF, $hGui)

$hPic = _GUICtrlCreateGIF($sFile, "", 0, 0, $aGIFDimension[0], $aGIFDimension[1])
GUICtrlSetTip($hPic, "Aaaahh... ESC to Exit")
GUICtrlSetStyle($hPic, Default, $GUI_WS_EX_PARENTDRAG)

GUISetState()
While 1
    Switch GUIGetMsg()
        Case -3
            Exit
        Case $hPic
            MsgBox(4096, "Click", "Aaah")
    EndSwitch
WEnd
...You can find GIFAnimation.au3 in examples forum. Don't let its name fool you, it can display any image, not only GIFs. Place it in the same folder as your script before you run it.

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
CrewXp

Thanks for the assist! Here is a 'working' copy of the code above. (includes and even test png). Your example uses gui get messages, I am using the gdiplus include, so I'm not sure how to make mine as yours functions. I tried using 

 

Func Test()

   Msgbox(0,"","")
EndFunc

;Placed this after my gui was created
GuiSetOnEvent($GUI_EVENT_PRIMARYDOWN,"Test")

 

But it didn't do anything...

Code:

;GUI Stuff
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
HotKeySet('{esc}','_exit'); ALT+1 Show / Hode Gui to tray

$toast_x=300
$toast_y=50

InetGet("http://dummyimage.com/300x50/000/fff",@ScriptDir&"\blank.png")
Global $sFile = InetRead("http://dummyimage.com/300x50/000/fff"); @ProgramFilesDir & "\AutoIt3\Examples\GUI\Torus.png"


Func Test()
   Msgbox(0,"","")
EndFunc

Func _exit()
   Exit
EndFunc

Func Loader($type,$x, $y)
$loc=@ScriptDir&"\blank.png"
_GDIPlus_Startup()

$GUI = _GUICreate_Alpha("Look at the shiny", $loc, $x, $y)
GuiSetOnEvent($GUI_EVENT_PRIMARYDOWN,"Test")
$myGuiHandle = WinGetHandle("Look at the shiny")
GLOBAL $hGraphic = _GDIPlus_GraphicsCreateFromHWND ($myGuiHandle)
GUISetState()

$hwnd = GUICreate("ControlGUI", $toast_x,$toast_y, 0, 0, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $myGuiHandle)
GUISetBkColor(0xABCDEF)


;Failed attempt to use dllcall to slide down and fade in as it slides. Shows a random weird blue box
 ;DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 270, "long", 0x00040004) ; $SLIDE IN FROM TOP ;DOESNT WORK!!!!
#define AW_HOR_POSITIVE     0x00000001
#define AW_HOR_NEGATIVE     0x00000002
#define AW_VER_POSITIVE     0x00000004
#define AW_VER_NEGATIVE     0x00000008
#define AW_CENTER           0x00000010
#define AW_HIDE             0x00010000
#define AW_ACTIVATE         0x00020000
#define AW_SLIDE            0x00040000
#define AW_BLEND            0x00080000

If $type=1 Then
GLOBAL $obj_e1   = GUICtrlCreateLabel('Elevator 1: Uninitialized', 35, 19, 150, 25)
    GUICtrlSetColor(-1, 0xFFFFFF)
    EndIf
If $type=2 Then
GLOBAL $obj_e2   = GUICtrlCreateLabel('Elevator 2: Uninitialized', 35, 19, 150, 25)
    GUICtrlSetColor(-1, 0xFFFFFF)
    EndIf
If $type=3 Then
GLOBAL $obj_e3   = GUICtrlCreateLabel('Elevator 3: Uninitialized', 35, 19, 150, 25)
    GUICtrlSetColor(-1, 0xFFFFFF)
    EndIf
If $type=4 Then
GLOBAL $obj_m1   = GUICtrlCreateLabel('Main Entrance: Uninitialized', 35, 19, 150, 25)
    GUICtrlSetColor(-1, 0xFFFFFF)
EndIf
_WinAPI_SetLayeredWindowAttributes($hwnd, 0xABCDEF, 255)


;Failed Attempt to manually slide the gui down from top. Moves, but doesnt move text with it. And Cant fade using this
For $i=100 to 0 Step -1
WinMove($myGuiHandle, "", $x, $y-$i, $toast_x, $toast_y)
   If $i=100 Then GUISetState(@SW_SHOW,$myGuiHandle)
Sleep(1)
Next
GUISetState(@SW_SHOW,$hwnd) 
EndFunc

Func _GUICreate_Alpha($sTitle, $sPath, $iX=-1, $iY=-1, $iOpacity=255)
    Local $hGUI, $hImage, $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend
    $hImage = _GDIPlus_ImageLoadFromFile($sPath)
    $width = _GDIPlus_ImageGetWidth($hImage)
    $height = _GDIPlus_ImageGetHeight($hImage)
    $hGUI = GUICreate($sTitle, $width, $height, $iX, $iY, $WS_POPUP, $WS_EX_LAYERED)


    $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", $width)
    DllStructSetData($tSize, "Y", $height)
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, "Alpha", $iOpacity)
    DllStructSetData($tBlend, "Format", 1)
    _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, 2)
    _WinAPI_ReleaseDC(0, $hScrDC)
    _WinAPI_SelectObject($hMemDC, $hOld)
    _WinAPI_DeleteObject($hBitmap)
    _WinAPI_DeleteObject($hImage)
    _WinAPI_DeleteDC($hMemDC)
 EndFunc ;==>_GUICreate_Alpha
 
 Loader(1,0,0)
 
 While 1
    Sleep(1000)
    WEnd

Share this post


Link to post
Share on other sites
trancexx

You want click-through second window. To have that you need to add another extended style:

$hwnd = GUICreate("ControlGUI", $toast_x,$toast_y, 0, 0, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD, $WS_EX_TRANSPARENT), $myGuiHandle)

Another thing is that in on-event mode you have to have:

Opt("GUIOnEventMode", 1)

...somewhere at the top of your script.


♡♡♡

.

eMyvnE

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  

×