Jump to content

Make active transparent icon on image background


Go to solution Solved by UEZ,

Recommended Posts

Posted

Hi all,

I need some help to activate this icon on this code

so cursor will be active on the icon and can excute command

 

Code :

#NoTrayIcon
#RequireAdmin
#include <WinAPISys.au3>
#include <GDIPlus.au3>
#include <WinAPIShellEx.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Example()

Func Example()
    Local $hGUI, $hGraphic, $hIcon, $hBitmap, $iX = 768, $iY = 525

     $hGUI = GUICreate("GDI+", $iX, $iY)
      GUISetState()

    _GDIPlus_Startup()

    Global $sFileName = @ScriptDir& "\MAIN.png"
    $hImage = _GDIPlus_ImageLoadFromFile($sFileName)
    $iX = _GDIPlus_ImageGetWidth($hImage)
    $iY = _GDIPlus_ImageGetHeight($hImage)
    $shBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    ; Create GUI

    Global $idPic = GUICtrlCreatePic("", 0, 0, $iX, $iY)
    GUICtrlSendMsg($idPic, 0x0172, 0, $shBitmap) ; STM_SETIMAGE = 0x0172, $IMAGE_BITMAP = 0
    GUICtrlSetState($idPic, $gui_disable)

    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;Create a graphics object from a window handle
    ;_GDIPlus_GraphicsClear($hGraphic, 0xFFFFFFFF)
    $hIcon = _WinAPI_ShellExtractIcon(@SystemDir & '\shell32.dll', 221, 48, 48)
    $hBitmap = _GDIPlus_BitmapCreateFromHICON32($hIcon)
    $idICON = _GDIPlus_GraphicsDrawImage($hGraphic, $hBitmap, 250, 150)
    GUICtrlSetState(-1, $GUI_ONTOP)
    GUICtrlSetCursor(-1, 0)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    ; Clean up resources
    _WinAPI_DestroyIcon($hIcon)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
EndFunc   ;==>Example

 

 

main.png :

image.png

Posted
1 hour ago, UEZ said:

You have to exclude the area of the icon off the bitmap (graphic).

One example:

 

I need a help to add this exclusion to my script code as i don't know how can i add it to my script

if you can modify my script please this will be fine

Thanks a lot for help

  • Solution
Posted (edited)

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

 

Edited by UEZ
$btny missed

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted
38 minutes ago, UEZ said:

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, $btnx)

    $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, $btnx, 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

 

Great Work Thanks

 

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...