I have thought again and this is simpler and the better solution.
#NoTrayIcon
;#RequireAdmin
#include <WinAPISys.au3>
#include <GDIPlus.au3>
#include <WinAPIShellEx.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <StaticConstants.au3>
Example()
Func Example()
Local $hGUI, $hGraphic, $hIcon, $hBitmap, $iX = 768, $iY = 525
$hGUI = GUICreate("GDI+", $iX, $iY)
_GDIPlus_Startup()
; Create GUI
Global $idPic = GUICtrlCreatePic("", 0, 0, $iX, $iY)
Global $sFileName = @ScriptDir& "\MAIN.png"
$hImage = _GDIPlus_ImageLoadFromFile($sFileName)
$iX = _GDIPlus_ImageGetWidth($hImage)
$iY = _GDIPlus_ImageGetHeight($hImage)
$hBGImage = _GDIPlus_BitmapCreateFromScan0($iX, $iY)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hBGImage)
_GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0)
$btnx = 250
$btny = 150
;_GDIPlus_GraphicsClear($hGraphic, 0xFFFFFFFF)
$hIcon = _WinAPI_ShellExtractIcon(@SystemDir & '\shell32.dll', 221, 48, 48)
$hBitmap = _GDIPlus_BitmapCreateFromHICON32($hIcon)
_GDIPlus_GraphicsDrawImage($hGraphic, $hBitmap, $btnx, $btny)
$shBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBGImage)
_WinAPI_DeleteObject(GUICtrlSendMsg($idPic, 0x0172, 0, $shBitmap)) ; STM_SETIMAGE = 0x0172, $IMAGE_BITMAP = 0
GUICtrlSetState($idPic, $gui_disable)
GUICtrlSetState(-1, $GUI_ONTOP)
GUICtrlSetCursor(-1, 0)
$hIcon = GUICtrlCreateIcon(@SystemDir & '\shell32.dll', -1, $btnx, $btny, 48, 48, BitOR($SS_NOTIFY, $SS_BLACKRECT))
GUISetState()
; Loop until user exits
Do
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
Case $hIcon
ConsoleWrite("Icon clicked" & @CRLF)
EndSwitch
Until False
; Clean up resources
_WinAPI_DestroyIcon($hIcon)
_WinAPI_DeleteObject($shBitmap)
_GDIPlus_BitmapDispose($hImage)
_GDIPlus_BitmapDispose($hBGImage)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()
EndFunc ;==>Example