Sign in to follow this  
Followers 0
mvk25

Icon and AVI controls losing transparency in status bar

4 posts in this topic

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



#2 ·  Posted (edited)

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
1 person likes this

I see fascists...

Share this post


Link to post
Share on other sites

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

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  
Followers 0

  • Similar Content

    • Skeletor
      By Skeletor
      Hi All,
      I know many newbies search for this feature.
      I decided to share this piece of code with everyone.
      Basically its a "splash screen" that has a transparent image.
      In a nutshell - Gui with a transparent gif.
      Enjoy...
      Download attachment....
       
      Splash Screen GUI.zip
    • nacerbaaziz
      By nacerbaaziz
      Hi guys
      I have an inquiry please
      I want an example of how to add an icon file to the compiled autoit file and how to use it in GUICtrlCreateIcon
      Preferably in a separate list within the resourceFor example myIcons
      I hope my request is clear and I hope you will help me solve this problem
      Because I found an example in the help files but I did not understand the method well
    • elsemieni
      By elsemieni
      Hey hello.
      I came here with maybe too specific questions about uncommon things, but as people says, I don't lose anything trying to asking here 
      There's long time that I have a little "experimental" idea: Use windows desktop and it icon system like old videogame consoles (where "sprites" are used to draw things on screen, can be manipulated/animated to make interesting things happen). Some of that inspiration came from another experiments from demoscene.
      Researching the possibilities of doing something like that (maybe not so intense) I found that the Windows Desktop uses a GuiListView to show and arrange icons (and of course, AutoIt provides UDF's for that  ). So, I'm used that UDF to create dummy icons (not putting files on Desktop, just modifiying the "GUI layer" of desktop for put non-working icons), setting custom values like coordinates, name and Icon (from a list of loaded icons in the GuiListView).  As you can see in next image works well in Windows XP... even in Windows 95 (that's not the case from Windows Vista to 10, but I already posted another question here about that... anyways, for now I'm working that with a isolated XP machine... sigh).

      Another video doing an animation with that:
      How I make that custom icons? Here:
      $hWnd = ControlGetHandle("Program Manager", "", "[CLASS:SysListView32; INSTANCE:1]") $newItem = _GUICtrlListView_AddItem ( $hWnd, "TEST", 32 ) ; with an icon of index 32 _GUICtrlListView_SetItemPosition ( $hWnd, $newItem, 300, 300 ) ; set some example property. Put in X=300 Y=300 Okay, so the next phase was changing the icons with custom ones. And here starts the issues. As AutoIT help says, icons from GuiListView came from a loaded GUIImageList, which, seeing past images I conclude that it's already preloaded with some sort of most used icons (something like an icon cache?). But If I modify it (or create another GUIImageList and then put into the GuiListView) the icons became corrupted and replaced with blank ones. (can be reverted deleting IconCache.db, just like when windows shows wrong icons in desktop).
      How I change icons? Here
      $hImage = _GUIImageList_Create(48, 48, 5) ; create an image list for 48x48 icons $newIcon = _GUIImageList_AddIcon($imageList, @SystemDir & "\shell32.dll", 110) ; just adding a new icon in the image list _GUICtrlListView_SetImageList($hWnd, $hImage, 0) ; $hwnd is the desktop hwnd Another option as workaround for setting icons was getting the desktop GUIImageList, and modifiyng it directly. I otbtain a GUIImageList handle, but ... without any images inside! (That's strange beacuse, when I set desktop item icons without altering the GUIImageList, it applies correctly). And finally if I try to add new ones, it returns -1 with @error setted.
      How I'm trying to get  desktop GUIImageList? Here.
      $imageList = _GUICtrlListView_GetImageList ( $hWnd, 0 ) MsgBox(0,_GUIImageList_GetImageCount ( $imageList ), $imageList) ; getting image count and GUIImageList handle $newIcon = _GUIImageList_AddIcon($imageList, @SystemDir & "\shell32.dll", 110) ; adding icons without success So, what is the question? There's something wrong I'm doing while trying to set the new icon set on desktop? Or desktop icons work in different way than the rest of the GuiListView's? Or there's something really stupid that I can't saw before that corrupts the icons? 
      Also... if there's not known solution for that, do you have some idea for doing a workaround for that? Or another crazy idea? (Maybe putting real files instead dummy icons could be a solution ... a very slow one). Or even maybe (maybe not, I sure about that xD) do you want to help with this "experiment".
      Thanks in advance, have a good day  
    • amimemeami
      By amimemeami
      I have a simple script that switches between IE and Chrome for the default browser, I even made a custom half chrome half ie icon for it. Question is, can I have the script toggle between two icons to signify the last browser it changed to? I would have the active browser's half of the icon in color, and inactive half grey scale. As a workaround, I put link next to it, and refresh the icon cache after it runs. 
      #RequireAdmin #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=..\..\Icons\IE_Chrome.ico #AutoIt3Wrapper_Outfile=..\..\..\..\Users\dmking\Desktop\Browser Switcher.exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** $sCurrentDefault = RegRead('HKCU\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice',"ProgId") if $sCurrentDefault = "IE.HTTP" Then     ChromeDefault() Else     IEDefault() EndIf ;~ Run("ie4uinit.exe -ClearIconCache") Run("C:\Windows\System32\ie4uinit.exe -ClearIconCache") Func IEDefault()     RegWrite("HKCU\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\ftp\UserChoice","Progid","REG_SZ","IE.FTP")     RegWrite("HKCU\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice","Progid","REG_SZ","IE.HTTP")     RegWrite("HKCU\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\https\UserChoice","Progid","REG_SZ","IE.HTTPS")     RegWrite("HKCU\Software\Clients\StartMenuInternet","","REG_SZ","IEXPLORE.EXE") EndFunc Func ChromeDefault()     RegWrite("HKCU\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\ftp\UserChoice","Progid","REG_SZ","ChromeHTML")     RegWrite("HKCU\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice","Progid","REG_SZ","ChromeHTML")     RegWrite("HKCU\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\https\UserChoice","Progid","REG_SZ","ChromeHTML")     RegWrite("HKCU\Software\Clients\StartMenuInternet","","REG_SZ","Google Chrome") EndFunc  
    • Chimp
      By Chimp
      If you set within a window, a given color as transparent, every area of that window painted with that color, act as an hole through wich you can see what's behind, and click on what's behind as well.
      What's funny is that if you embed a browser control within that window, the "transparent" color works even within the browser! This allow some interesting effects by simply opening any of the many javascript animations, or css effects or whatever within a browser control embedded into a GUI:
      Here, for example, is a simple effect of fishes swimming around on the screen.
      For lazyness I have embedded an ready made swf flash by a link to the web, but is of course possible embed any web page with javascripts css or whatever.....
      Have fun
      #include <WinAPI.au3> #include <WindowsConstants.au3> #include <Misc.au3> ; for _IsPressed (23 END key) Local $hDLL = DllOpen("user32.dll"), $oIE = ObjCreate("Shell.Explorer.2") Local $hBackground = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUPWINDOW, $WS_EX_LAYERED + $WS_EX_TOPMOST) Local $AlphaKey = 0xF0F7FF ; everything with color $AlphaKey within this window will be transparent ; even if within an embedded browser control!..... _WinAPI_SetLayeredWindowAttributes($hBackground, $AlphaKey, 0, $LWA_COLORKEY) GUISetState(@SW_SHOW, $hBackground) $hIE = GUICtrlCreateObj($oIE, 0, 0, @DesktopWidth, @DesktopHeight) ; <- embedd $oIE in the AutoIt GUI GUISetBkColor($AlphaKey, $hBackground) ; $AlphaKey $hBackground transparent $oIE.navigate('http://cdn.abowman.com/widgets/fish/fish.swf') ; $oIE.navigate('http://cdn.abowman.com/widgets/spider/spider.swf') ; a spider goes around on the screen .... ; !! to use the spider.swf, you need to set $AlphaKey = 0xffffff on line 7 "! While True If _IsPressed("23", $hDLL) Then ExitLoop ; END key was pressed Sleep(250) WEnd $oIE = "" $hDLL = "" GUIDelete($hBackground)