Jump to content

Icon and AVI controls losing transparency in status bar


mvk25
 Share

Recommended Posts

Hi ;)

I am trying to embed an icon control and an AVI control in the status bar but the problem is they won't retain their transparency.

An example:

#include <GuiStatusBar.au3>
#include <GUIConstantsEx.au3>

Global $WindowMain = GUICreate("Example", 351, 176, -1, -1)
GUISetBkColor( 0xDDDDDD, $WindowMain )
Global $Statusbar = _GUICtrlStatusBar_Create($WindowMain)
Global $Statusbar_PartsWidth[2] = [324, -1]
_GUICtrlStatusBar_SetParts($Statusbar, $Statusbar_PartsWidth)
_GUICtrlStatusBar_SetText($Statusbar, "", 0)
_GUICtrlStatusBar_SetText($Statusbar, "", 1)
_GUICtrlStatusBar_SetMinHeight($Statusbar, 20)
GUISetState(@SW_SHOW)

$Icon = GUICtrlCreateIcon('ico.ico',-1,300,130,16,16) ;Icon on GUI
;Without this the icon will not be tranparent. No idea why.
GUICtrlSetState($icon, $GUI_SHOW)

$Icon2 = GUICtrlCreateIcon('ico.ico',-1,10,10,16,16)
_GUICtrlStatusBar_EmbedControl($Statusbar, 1, GUICtrlGetHandle($Icon2), 1+2)
; This has no effect. Icon has a white square around it
GUICtrlSetState($icon2, $GUI_SHOW)

$AVI = GUICtrlCreateAvi( 'avi.avi',0,250,130,16,16)
GUICtrlSetState( $AVI, 1 )

$AVI2 = GUICtrlCreateAvi( 'avi.avi',0,250,130,16,16)
GUICtrlSetState( $AVI2, 1 )
_GUICtrlStatusBar_EmbedControl($Statusbar, 0, GUICtrlGetHandle($AVI2), 1+2)

Global $GuiMsg
Do
$GuiMsg = GUIGetMsg()
Until $GuiMsg = $GUI_EVENT_CLOSE

I've tried a couple of things like using _GUICtrlStatusBar_SetIcon() or GDIplus for icons and that works and the icons are transparent. As for the AVI, I tried faking a status bar by drawing some lines at the buttom of the window and that worked ok too, But I'd love to be able to use it with a real status bar.

example.zip

Link to comment
Share on other sites

Welcome to the forums mvk25

A few things to try:

1 - Embedded UDF avi control: AVI Control gets background brush from statusbar (not themed but not as visible as your gui background colour)

2 - Embedded UDF avi control: Turn off themes for the statusbar - (control gets background brush from unthemed statusbar)

3 - Embedded native avi control: Turn off themes for the statusbar and set statusbar colour same as gui (control gets background brush from parent gui)

4 - Embedded native/UDF avi control: Get statusbar theme/system colour* and return brush in _WM_CTLCOLORSTATIC message handler

(udf avi control created with gui as parent, then made parent of statusbar, so we get a WM_CTLCOLORSTATIC message)

;*(issues with getting colour from themed statusbar and themes that have a background gradient in the statusbar - the default xp theme has a gradient themed statusbar)

5 - Embedded native/UDF avi control: write the themed background to a memdc, write to a bitmap and create a brush from it to return in _WM_CTLCOLORSTATIC message handler

(requires code to monitor theme change and create a new brush)

#include <WindowsConstants.au3>
#include <GuiAVI.au3>
#include <GuiStatusBar.au3>
#include <GUIConstantsEx.au3>

_example1()
_example2()
_example3()
Exit

Func _example1()
    Local $WindowMain = GUICreate("Example", 351, 176, -1, -1)
    GUISetBkColor(0xDDDDDD, $WindowMain)
    Local $Statusbar = _GUICtrlStatusBar_Create($WindowMain)
    Local $Statusbar_PartsWidth[2] = [324, -1]
    _GUICtrlStatusBar_SetParts($Statusbar, $Statusbar_PartsWidth)
    _GUICtrlStatusBar_SetText($Statusbar, "", 0)
    _GUICtrlStatusBar_SetText($Statusbar, "", 1)
    _GUICtrlStatusBar_SetMinHeight($Statusbar, 20)
    Local $hIcon = __GUICtrlStatusBar_SetIcon($Statusbar, 1, 0, 'ico.ico') ;the original udf destroys the icon handle
    Local $Icon = GUICtrlCreateIcon('ico.ico', -1, 300, 130, 16, 16) ;Icon on GUI - place before GUISetState
    Local $AVI = GUICtrlCreateAvi('avi.avi', 0, 250, 130, 16, 16)
    GUICtrlSetState($AVI, 1)
    Local $hAVI2 = _GUICtrlAVI_Create($WindowMain, 'avi.avi', -1, 154, 4, 16, 16)
    _GUICtrlStatusBar_EmbedControl($Statusbar, 0, $hAVI2, 1 + 2)
    _GUICtrlAVI_Play($hAVI2)
    GUISetState(@SW_SHOW)
    Local $GuiMsg
    Do
        $GuiMsg = GUIGetMsg()
    Until $GuiMsg = $GUI_EVENT_CLOSE
    _WinAPI_DestroyIcon($hIcon)
    Return
EndFunc   ;==>_example1

Func _example2()
    Local $WindowMain = GUICreate("Example", 351, 176, -1, -1)
    GUISetBkColor(0xDDDDDD, $WindowMain)
    Local $Statusbar = _GUICtrlStatusBar_Create($WindowMain)
    DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", $Statusbar, "wstr", 0, "wstr", 0)
    Local $Statusbar_PartsWidth[2] = [324, -1]
    _GUICtrlStatusBar_SetParts($Statusbar, $Statusbar_PartsWidth)
    _GUICtrlStatusBar_SetText($Statusbar, "", 0)
    _GUICtrlStatusBar_SetText($Statusbar, "", 1)
    _GUICtrlStatusBar_SetMinHeight($Statusbar, 20)
    Local $hIcon = __GUICtrlStatusBar_SetIcon($Statusbar, 1, 0, 'ico.ico') ;the original udf destroys the icon handle
    Local $Icon = GUICtrlCreateIcon('ico.ico', -1, 300, 130, 16, 16) ;Icon on GUI - place before GUISetState
    Local $AVI = GUICtrlCreateAvi('avi.avi', 0, 250, 130, 16, 16)
    GUICtrlSetState($AVI, 1)
    Local $hAVI2 = _GUICtrlAVI_Create($WindowMain, 'avi.avi', -1, 154, 4, 16, 16)
    _GUICtrlStatusBar_EmbedControl($Statusbar, 0, $hAVI2, 1 + 2)
    _GUICtrlAVI_Play($hAVI2)
    GUISetState(@SW_SHOW)
    Local $GuiMsg
    Do
        $GuiMsg = GUIGetMsg()
    Until $GuiMsg = $GUI_EVENT_CLOSE
    _WinAPI_DestroyIcon($hIcon)
    Return
EndFunc   ;==>_example1

Func _example3()
    Local $WindowMain = GUICreate("Example", 351, 176, -1, -1)
    GUISetBkColor(0xDDDDDD, $WindowMain)
    Local $Statusbar = _GUICtrlStatusBar_Create($WindowMain)
    DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", $Statusbar, "wstr", 0, "wstr", 0)
    _GUICtrlStatusBar_SetBkColor($Statusbar, 0xDDDDDD)
    Local $Statusbar_PartsWidth[2] = [324, -1]
    _GUICtrlStatusBar_SetParts($Statusbar, $Statusbar_PartsWidth)
    _GUICtrlStatusBar_SetText($Statusbar, "", 0)
    _GUICtrlStatusBar_SetText($Statusbar, "", 1)
    _GUICtrlStatusBar_SetMinHeight($Statusbar, 20)
    Local $hIcon = __GUICtrlStatusBar_SetIcon($Statusbar, 1, 0, 'ico.ico') ;the original udf destroys the icon handle
    Local $Icon = GUICtrlCreateIcon('ico.ico', -1, 300, 130, 16, 16) ;Icon on GUI - place before GUISetState
    Local $AVI = GUICtrlCreateAvi('avi.avi', 0, 250, 130, 16, 16)
    GUICtrlSetState($AVI, 1)
    Local $AVI2 = GUICtrlCreateAvi('avi.avi', 0, 154, 4, 16, 16)
    Local $hAVI2 = GUICtrlGetHandle(-1)
    GUICtrlSetState($AVI2, 1)
    _GUICtrlStatusBar_EmbedControl($Statusbar, 0, $hAVI2, 1 + 2)
    GUISetState(@SW_SHOW)
    Local $GuiMsg
    Do
        $GuiMsg = GUIGetMsg()
    Until $GuiMsg = $GUI_EVENT_CLOSE
    _WinAPI_DestroyIcon($hIcon)
    Return
EndFunc   ;==>_example2

Func __GUICtrlStatusBar_SetIcon($hWnd, $iPart, $iIcon = 0, $sIconFile = "")
    Local $tIcon = DllStructCreate("handle")
    Local $vResult = DllCall("shell32.dll", "uint", "ExtractIconExW", "wstr", $sIconFile, "int", $iIcon, "ptr", 0, "struct*", $tIcon, "uint", 1)
    If @error Then Return SetError(@error, @extended, False)
    $vResult = $vResult[0]
    If $vResult > 0 Then $vResult = _SendMessage($hWnd, $SB_SETICON, $iPart, DllStructGetData($tIcon, 1), 0, "wparam", "handle")
    Return DllStructGetData($tIcon, 1)
EndFunc   ;==>__GUICtrlStatusBar_SetIcon
Edited by rover

I see fascists...

Link to comment
Share on other sites

  • 2 weeks later...

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
 Share

×
×
  • Create New...