Jump to content

Recommended Posts

Posted

The following code seems to make everything transparent as soon as I add the style and exstyle to the GUI. What am I missing so that just the background of the GUI is transparent but the pie shape is displayed (opaque)?

 

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

HotKeySet("{ESC}", _Exit)

_GDIPlus_Startup()

$myWidth = 800
$myHeight = 800
$hGUI = GUICreate('', $myWidth, $myHeight, -1, -1, $WS_POPUP, $WS_EX_LAYERED)
GUISetState()

    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    $hBitmap = _GDIPlus_BitmapCreateFromGraphics(300, 300, $hGraphic)
    $hBrush = _GDIPlus_BrushCreateSolid(0xFF0000FF)
    _GDIPlus_GraphicsFillPie($hGraphic, 150, 80, 100, 100, 45, 90, $hBrush)

_SetBitmap($hGUI, $hBitmap, 255)
_WinAPI_DeleteObject($hBitmap)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            _Exit()
    EndSwitch
WEnd


Func _SetBitmap($hWnd, $hBitmap, $iOpacity)
    Local $hDC, $hMemDC, $tBlend, $tSIZE, $tSource
    $hDC = _WinAPI_GetDC($hWnd)
    $hMemDC = _WinAPI_CreateCompatibleDC($hDC)
    _WinAPI_SelectObject($hMemDC, $hBitmap)
    $tSIZE = _WinAPI_GetBitmapDimension($hBitmap)
    $tSource = DllStructCreate($tagPOINT)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    DllStructSetData($tBlend, 'Alpha', $iOpacity)
    DllStructSetData($tBlend, 'Format', 1)
    _WinAPI_UpdateLayeredWindow($hWnd, $hDC, 0, DllStructGetPtr($tSIZE), $hMemDC, DllStructGetPtr($tSource), 0, DllStructGetPtr($tBlend), $ULW_ALPHA)
    _WinAPI_ReleaseDC($hWnd, $hDC)
    _WinAPI_DeleteDC($hMemDC)
EndFunc   ;==>_SetBitmap

Func _Exit()
    _WinAPI_DeleteObject($hBitmap)
    _GDIPlus_Shutdown()
    Exit
EndFunc

 

  • Solution
Posted

Here is an adaptation based this code

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

Global Const $SC_DRAGMOVE = 0xF012

HotKeySet("{ESC}", _Exit)

_GDIPlus_Startup()

$myWidth = 800
$myHeight = 800
$hGUI = GUICreate('', $myWidth, $myHeight, -1, -1, $WS_POPUP, $WS_EX_LAYERED)
GUISetState()

$hBitmap = _GDIPlus_BitmapCreateFromScan0(300, 300)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hBitmap)
$hBrush = _GDIPlus_BrushCreateSolid(0xFF0000FF)
_GDIPlus_GraphicsFillPie($hGraphic, 150, 80, 100, 100, 45, 90, $hBrush)
_GDIPlus_GraphicsDispose($hGraphic)
$hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
_WinAPI_BitmapDisplayTransparentInGUI($hHBitmap, $hGUI, 255)
GUIRegisterMsg($WM_LBUTTONDOWN, "_WM_LBUTTONDOWN")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            _Exit()
    EndSwitch
WEnd


Func _WinAPI_BitmapDisplayTransparentInGUI(ByRef $hHBitmap, ByRef $hGUI, $iOpacity = 0xFF, $bReleaseGDI = True)
    If Not BitAND(GUIGetStyle($hGUI)[1], $WS_EX_LAYERED) = $WS_EX_LAYERED Then Return SetError(1, 0, 0)
    Local $tDim = DllStructCreate($tagBITMAP)
    If Not _WinAPI_GetObject($hHBitmap, DllStructGetSize($tDim), DllStructGetPtr($tDim)) Then Return SetError(2, 0, 0)
    Local $tSize = DllStructCreate($tagSIZE), $tSource = DllStructCreate($tagPOINT), $tBlend = DllStructCreate($tagBLENDFUNCTION)
    Local Const $hScrDC = _WinAPI_GetDC(0), $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC), $hOld = _WinAPI_SelectObject($hMemDC, $hHBitmap)
    $tSize.X = $tDim.bmWidth
    $tSize.Y = $tDim.bmHeight
    $tBlend.Alpha = $iOpacity
    $tBlend.Format = 1
    _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, DllStructGetPtr($tSize), $hMemDC, DllStructGetPtr($tSource), 0, DllStructGetPtr($tBlend), $ULW_ALPHA)
    _WinAPI_ReleaseDC(0, $hScrDC)
    _WinAPI_SelectObject($hMemDC, $hOld)
    _WinAPI_DeleteDC($hMemDC)
    If $bReleaseGDI Then _WinAPI_DeleteObject($hHBitmap)
    Return True
EndFunc

Func _WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam)
    _SendMessage($hGUI, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0)
EndFunc   ;==>_WM_LBUTTONDOWN

Func _Exit()
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_Shutdown()
    Exit
EndFunc

 

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...