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

    • GordonFreeman
      By GordonFreeman
      Hi, i searched some topics but cannot found a simple way to do that:
      #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Form1", 615, 438, 192, 124) GUISetState(@SW_SHOW) ; I tried this but user reported that it work in 2006, not seems work actually $filemenu = GUICtrlCreateMenu ("&File") $fileitem = GUICtrlCreateMenuitem ("Open",$filemenu) GuiCtrlSetImage($fileitem, "shell32.dll", 4) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Also tried:
      #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Form1", 615, 438, 192, 124) GUISetState(@SW_SHOW) $filemenu = TrayCreateMenu("&File") $fileitem = TrayCreateItem("Open",$filemenu) ;GuiCtrlSetImage($fileitem, "shell32.dll", 4) ;GuiCtrlSetImage(TrayItemGetHandle($fileitem), "shell32.dll", 4) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Well.. thanks in advance!
       
      Ok. I found this working example from Yashied. If i cannot find a simple then i will go with it
      #Include <GUIConstantsEx.au3> #Include <GUIMenu.au3> #Include <Constants.au3> #Include <WinAPI.au3> #Include <WindowsConstants.au3> Opt('MustDeclareVars', 1) Global $hMenu, $hForm, $hFile = 1000, $idNew, $idExit $hForm = GUICreate('Menu', 400, 300) $hFile = _GUICtrlMenu_CreateMenu() _GUICtrlMenu_InsertMenuItem ($hFile, 0, ' &Favorites', $idNew) _GUICtrlMenu_InsertMenuItem ($hFile, 1, '', 0) _GUICtrlMenu_InsertMenuItem($hFile, 2, ' E&xit', $idExit) $hMenu = _GUICtrlMenu_CreateMenu() _GUICtrlMenu_InsertMenuItem($hMenu, 0, '&File', 0, $hFile) _GUICtrlMenu_SetMenu($hForm, $hMenu) _GUICtrlMenu_SetItemBmp($hFile, 0, _CreateBitmapFromIcon(_WinAPI_GetSysColor($COLOR_MENU), @SystemDir & '\shell32.dll', 43, 16, 16)) _GUICtrlMenu_SetItemBmp($hFile, 2, _CreateBitmapFromIcon(_WinAPI_GetSysColor($COLOR_MENU), @SystemDir & '\shell32.dll', 27, 16, 16)) GUISetState() Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Func _CreateBitmapFromIcon($iBackground, $sIcon, $iIndex, $iWidth, $iHeight) Local $hDC, $hBackDC, $hBackSv, $hIcon, $hBitmap $hDC = _WinAPI_GetDC(0) $hBackDC = _WinAPI_CreateCompatibleDC($hDC) $hBitmap = _WinAPI_CreateSolidBitmap(0, $iBackground, $iWidth, $iHeight) $hBackSv = _WinAPI_SelectObject($hBackDC, $hBitmap) $hIcon = _WinAPI_PrivateExtractIcon($sIcon, $iIndex, $iWidth, $iHeight) If Not @error Then _WinAPI_DrawIconEx($hBackDC, 0, 0, $hIcon, 0, 0, 0, 0, $DI_NORMAL) _WinAPI_DestroyIcon($hIcon) EndIf _WinAPI_SelectObject($hBackDC, $hBackSv) _WinAPI_ReleaseDC(0, $hDC) _WinAPI_DeleteDC($hBackDC) Return $hBitmap EndFunc ;==>_CreateBitmapFromIcon Func _WinAPI_PrivateExtractIcon($sIcon, $iIndex, $iWidth, $iHeight) Local $hIcon, $tIcon = DllStructCreate('hwnd'), $tID = DllStructCreate('hwnd') Local $Ret = DllCall('user32.dll', 'int', 'PrivateExtractIcons', 'str', $sIcon, 'int', $iIndex, 'int', $iWidth, 'int', $iHeight, 'ptr', DllStructGetPtr($tIcon), 'ptr', DllStructGetPtr($tID), 'int', 1, 'int', 0) If (@error) Or ($Ret[0] = 0) Then Return SetError(1, 0, 0) EndIf $hIcon = DllStructGetData($tIcon, 1) If ($hIcon = Ptr(0)) Or (Not IsPtr($hIcon)) Then Return SetError(1, 0, 0) EndIf Return $hIcon EndFunc ;==>_WinAPI_PrivateExtractIcon Ok, i noticed that is a pain create submenu with _GUICtrlMenu_CreatePopup to do like in Tray, and Tray better located, then i need images/icon with Tray functions, some workaround?? 
    • WoodGrain
      By WoodGrain
      Hi All,
      I'm using UseTraySetIcon("shell32.dll", xx) to set my tray icon to a specific icon while running, is there a way I can specify this icon when I compile my script into an exe so my exe icon is the same?
      Thanks!
    • 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