Jump to content
Sign in to follow this  
JohnnLock

Botões Invisíveis em PNG GUI

Recommended Posts

Olá,

Eu peguei uma source de uma form em PNG para estudar como funciona, devo dizer que achei lindo e muito interessante porém não consegui adicionar botões nela.

Eu queria colocar botões invisíveis na form, assim quando eu clicasse em parte X da form o comando X seria executado.

Ex: A imagem usada foi de um personagem, queria que ao clicar em sua mão função X seria executada, ao clicar em seu olho função X² seria executada.

Vi aqui no fórum um link para um post que dizia ter a solução, porém ele está expirado.

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>
Opt("guioneventmode",1)
Global Const $AC_SRC_ALPHA = 1
_GDIPlus_Startup()

$hImage = _GDIPlus_ImageLoadFromFile(@ProgramFilesDir & "\AutoIt3\Examples\GUI\Advanced\Images\Bakura.png")
$width = _GDIPlus_ImageGetWidth($hImage)
$height = _GDIPlus_ImageGetHeight($hImage)
$gui = GUICreate("", $width, $height, -1, -1, $WS_POPUP, $WS_EX_LAYERED, GUICreate("",0,0,50,100))
GUICtrlCreateLabel("",0,0,99999,99999,-1,$GUI_WS_EX_PARENTDRAG)
GUISetOnEvent(-3,"tat")
SetBitmap($gui, $hImage, 225)
GUICtrlCreateButton("Test",50,50,220,40)
GUISetState(@SW_SHOW)
While 1
   Sleep(100)
WEnd

func tat()
   Exit
EndFunc
Func SetBitmap($hGUI, $hImage, $iOpacity)
        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

Share this post


Link to post
Share on other sites

Olá JohnnLock, estive lendo seu poste e achei o assunto muito interessante, até mesmo porque já trabalhei com imagens mas em sistema dotnet. Acabei achando no irmão inglês do fórum um post que pode te ajudar, pelo menos achei muita coisa interessante.

 

Segue o link

https://www.autoitscript.com/forum/topic/146282-example-random-colour-gui-based-drawer/

 

Esse código mostra como trabalhar com coordenadas da tela, movimento do mouse e captura do click.

#AutoIt3Wrapper_UseX64=n
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#include <WinApi.au3>
#include <GdiPlus.au3>

Global $hGUI, $hGraphic, $hBrush
CreateTheGUI()

;Launch GDI & globals
_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hBrush = _GDIPlus_BrushCreateSolid()


While GUIGetMsg() <> $GUI_EVENT_CLOSE
WEnd

;Clean up
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_Shutdown()

Func CreateTheGUI()
    $hGUI = GUICreate("", 300, 300, -1, -1)
    GUISetBkColor('0x000000')
    GUISetState(@SW_SHOW)
    GUIRegisterMsg($WM_MOUSEMOVE, "EventHandler")
    GUIRegisterMsg($WM_LBUTTONDOWN, "EventHandler")
    GUIRegisterMsg($WM_LBUTTONUP, "EventHandler")
    GUIRegisterMsg($WM_RBUTTONDOWN, "EventHandler")
    GUIRegisterMsg($WM_RBUTTONUP, "EventHandler")
EndFunc ;==>CreateTheGUI

Func EventHandler($hWnd, $Msg, $WParam, $LParam)
    If $hWnd <> $hGui Then Return $GUI_RUNDEFMSG

    Local $szMsg = ""

    Local $Coords[2] = [_WinAPI_LoWord ($lParam), _WinApi_HiWord($lParam)]

    Static $MK_LBUTTON = 0x1
    Static $MK_RBUTTON = 0x2
    Static $MK_MBUTTON = 0x10


    Switch $Msg
        Case $WM_MOUSEMOVE
            Switch $WParam
                Case $MK_LBUTTON ;Paint while dragging
                    Paint($Coords[0],$Coords[1])
                Case $MK_RBUTTON ;Erase while dragging
                    Erase($Coords[0], $Coords[1])
                Case $MK_MBUTTON
                Case 0
            EndSwitch
        Case $WM_LBUTTONDOWN ;Paint on click
            Paint($Coords[0],$Coords[1])
        Case $WM_LBUTTONUP
        Case $WM_RBUTTONDOWN ;Erase on click
            Erase($Coords[0], $Coords[1])
        Case $WM_RBUTTONUP
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc

Func Paint($x, $y)
    _GDIPlus_BrushSetSolidColor($hBrush, 0xFF & Random(1, 16777215, 1))
    _GDIPlus_GraphicsFillRect($hGraphic, Int($x/5) * 5, Int($y/5) * 5, 5, 5, $hBrush)
EndFunc

Func Erase($x, $y)
    _GDIPlus_GraphicsFillRect($hGraphic, Int($x/5) * 5, Int($y/5) * 5, 5, 5) ;Omitting $hBrush defaults to painting a black rectangle (erasing)
EndFUnc

espero ter ajudado.

  • Like 1

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  

×