Jump to content
Sign in to follow this  
mvk25

Icon and AVI controls losing transparency in status bar

Recommended Posts

mvk25

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

Share this post


Link to post
Share on other sites
rover

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
  • Like 1

I see fascists...

Share this post


Link to post
Share on other sites
mvk25

Thank you Rover :) example 1 works great.

And I am sorry for the late reply, I was away from home for while.

Share this post


Link to post
Share on other sites
rover

Another option is an animated GIF or SWF file, there are udfs in the examples forum.


I see fascists...

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  

  • Similar Content

    • timmy2
      By timmy2
      The following script, thanks largely to @UEZ, displays the attached PNG image on the Windows Desktop.

      It perfectly renders the sticky note's shadow over whatever's in the background.
      But here's the catch: I would like to add a line of text, fetched from a variable and using a font of my choice, atop the sticky note. It needs to be part of the same GUI because the sticky note can be dragged and placed anywhere on the screen.
      Will someone here show me how to add just the additional code needed to accomplish my goal? I have tried sporadically for two years to merge in code from scripts that use GDI+ calls to display text over alpha channels but the challenge has proven beyond me.
      #include <ButtonConstants.au3> #include <MsgBoxConstants.au3> #include <StructureConstants.au3> #include <WinAPIConstants.au3> #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPISysWin.au3> _GDIPlus_Startup() Global Const $SC_DRAGMOVE = 0xF012 Global $iW, $iH, $hImage, $hBitmap, $hGUI $hImage = _GDIPlus_BitmapCreateFromFile("Using-Note.png") $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) $iW = _GDIPlus_ImageGetWidth($hImage) $iH = _GDIPlus_ImageGetHeight($hImage) $hGUI = GUICreate("", $iW, $iH, -1, -1, $WS_POPUP, BitOR($WS_EX_LAYERED,$WS_EX_TOPMOST)) GUISetState() _WinAPI_BitmapDisplayTransparentInGUI($hBitmap, $hGUI) GUIRegisterMsg($WM_LBUTTONDOWN, "_WM_LBUTTONDOWN") Do Until GUIGetMsg() = $GUI_EVENT_CLOSE _WinAPI_DeleteObject($hBitmap) _GDIPlus_BitmapDispose($hImage) _GDIPlus_Shutdown() GUIDelete() 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  
    • dimm
      By dimm
      Is it possible to compile script without any icon resources included?
      When I make exe it uses default system icon of current OS even if I compile as console application.
      On other versions of Windows it looks a little strange

       
      Update:
      It seems that the only way is remove icons from exe after compilation using resource editors like ResHacker.

       
      another bad solution:
      Using corrupted 35 bytes icon file. Windows can't load it and shows default system icon.
      #pragma compile(Icon, broken.ico) broken.ico
    • KaFu
      By KaFu
      ICU - Icon Configuration Utility

      Current Version: v6 (2018-Sep-16)
      Restore your desktop when the icons get "rearranged".
      Melba23 and I found we were working on very similar ideas to restore the Desktop icons to their normal place if they became "rearranged" (
      ). Vista seems to like this doing on occasion just for fun - but we all know some apps and games which change the display resolution or move icons around. This annoys "tidy" people who like their desktops arranged "just so" - I am particularly thinking of this desktop when I say that!
      We combined efforts and here is the result of our labors.
      Operation is easy - press "Save" to store a particular configuration and "Restore" to reset the icons to the saved positions in the selected configuration file. "Delete" allows you to remove unwanted configuration files from the list. There is a command line option so that the restoration can be run via HotKeys if required (that is why the script warns that it should be compiled for full functionality). You can decide what to do with any icons that have been added since you last saved the configuration file - the default is to put them in the top-left corner, but you can also banish them way off-screen or, more sensibly, specify a location for them.
      A new feature as of ICU v3.4 is the optional Desktop Contextmenu Integration (DCI) for Win7 (Win7 only because Microsoft implemented an easy way to do this through the registry as of this release).
      Version 3.3 should fix the empty save file bug
      Version 3.4 Win7: Admin rights no longer needed for DCI
      Version 5.0 Win8 compatibility for DCI
      The source and executable can be downloaded from my site: http://www.funk.eu
      Kudos to Ascend4nt, Melba23, Prog@ndy, & Valik for parts of the code.
      Please let me know if you found some piece of code in the source for which I forgot to mention a credit.
      Enjoy, let me know what you think of ICU and with Best Regards
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening everyone
      First, I want to apologize with you for the title not very clear, but I thought a little bit on which title to set at the thread, and this is the one that came in mind.
      Now, let me explain what I'm trying to understand.

      I am making an application ( with n clients ), with an SQLite Database, which has a Main form, and n sub-forms... 
      Since these sub-forms are called several times, because they are used to add or update records to the Database, I put the code that generates the GUI of these sub-forms in Functions.
      There are two sub-forms which are "treated" as two main forms, since even them have n sub-forms, which perform various tasks.
      Where am I stucked?

      For the Main form I created a Status Bar, in order to display messages ( add/delete/update/search results ), and it works perfectly with all the forms which don't have other sub-forms.
      For the two forms, which indeed have n sub-forms, I created two separated Status Bars, which are (re)created everytime I call the function that then displays the form.
      Practically, I can't set icons to these two Status Bars, and I don't know why.
      I'm really sorry that I don't feel clear enough, so, here you are an example of what I am saying.
      I recreated exactly what my script does:
      #include <GuiButton.au3> #include <GUIConstantsEx.au3> #include <GuiStatusBar.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) Global $frmSubForm, _ $txtSubFormField, _ $sbSubFormStatusBar, _ $objSB_IconError = _WinAPI_LoadShell32Icon(109), _ $objSB_IconInformation = _WinAPI_LoadShell32Icon(277) #Region ### START Koda GUI section ### Form= $frmMainForm = GUICreate("Main Form", 300, 300, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "ExitApplication") $sbMainStatusBar = _GUICtrlStatusBar_Create($frmMainForm) $btnCreateSubForm = GUICtrlCreateButton("Create Sub Form", 105, 110, 75, 41, BitOR($BS_CENTER,$BS_VCENTER,$BS_MULTILINE)) GUICtrlSetOnEvent(-1, "GenerateSubForm") GUICtrlSetFont(-1, 10, 400, 0, "Arial") _GUICtrlStatusBar_SetSimple($sbMainStatusBar) _GUICtrlStatusBar_SetText($sbMainStatusBar, "") GUISetState(@SW_SHOW, $frmMainForm) #EndRegion ### END Koda GUI section ### While 1 Sleep(100) WEnd Func ExitApplication() Exit EndFunc Func GenerateSubForm() #Region ### START Koda GUI section ### Form= $frmSubForm = GUICreate("Sub-Form", 300, 300, -1, -1, -1, -1, $frmMainForm) GUISetOnEvent($GUI_EVENT_CLOSE, "DeleteSubForm") $txtSubFormField = GUICtrlCreateInput("", 0, 0, 100, 20) $btnCheckSubFormField = GUICtrlCreateButton("Check Field", 105, 110, 75, 41, BitOR($BS_CENTER,$BS_VCENTER,$BS_MULTILINE)) GUICtrlSetOnEvent(-1, "CheckSubFormField") GUICtrlSetFont(-1, 10, 400, 0, "Arial") $sbSubFormStatusBar = _GUICtrlStatusBar_Create($frmSubForm) _GUICtrlStatusBar_SetSimple($sbSubFormStatusBar) _GUICtrlStatusBar_SetText($sbSubFormStatusBar, "") GUISetState(@SW_SHOW, $frmSubForm) GUISetState(@SW_DISABLE, $frmMainForm) #EndRegion ### END Koda GUI section ### EndFunc Func DeleteSubForm() ; Declared Globally => $frmSubForm GUIDelete($frmSubForm) GUISetState(@SW_ENABLE, $frmMainForm) EndFunc Func WriteToStatusBar($sbStatusBar, $objSB_Icon, $strText) _GUICtrlStatusBar_SetIcon($sbStatusBar, 0, $objSB_Icon) _GUICtrlStatusBar_SetText($sbStatusBar, $strText) ConsoleWrite("Icon Handle: " & $objSB_Icon & @CRLF) EndFunc Func CheckSubFormField() ; Declared Globally => $txtSubFormField If GUICtrlRead($txtSubFormField) = "" Then ; Declared Globally => $sbStatusBar WriteToStatusBar($sbSubFormStatusBar, $objSB_IconError, "Field NOK.") Else WriteToStatusBar($sbSubFormStatusBar, $objSB_IconInformation, "Field OK.") EndIf EndFunc The text is set, but icon is not.
      Could someone please tell me why?
      Thanks everyone in advance  

      Best Regards.
×