Jump to content

_GUICtrlStatusBarSetBKColor not working with Vista & Win7


 Share

Recommended Posts

Good Day folks,

I've searched the forums and found some old articles related to this and did not want to bring back a necro post.

The _GUICtrlStatusBarSetBKColor($handle, $icolor) will not work on Vista or Win/7, unless it's set to XPtheme or so it seems. Has a fix or work around been sorted for this function. Maybe an alternative way of doing it ?

I use a status bar to dialog ongoing processes to the users. I'd like to be able to set 1 of 3 colours depending on the status dialog: 1) normal, 2) yellow (warn) & 3) Red (error) in order to draw attention to the dialog. I am already using icons "_GUICtrlStatusBar_SetIcon($StatusBar1, 0, 0, ".\Images\" & $iconfile)" which is fine BUT does not attract enough attention should there be an error.

Below is the code that I found that does work, as long as you flip to XPTheme which is not an option.

#include <GuiConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <WinAPI.au3>
#include <Constants.au3>
Dim $XS_n
$Debug_SB = False ; Check ClassName being passed to functions, set to True and use a handle to another control to see it work
_Main()
Func _Main()
    Local $hGUI, $hStatus
    Local $aParts[3] = [75, 150, -1]
    ; Create GUI
XPStyle(1)
    $hGUI = GUICreate("(Example 1) StatusBar Set BkColor", 400, 300)
    $hStatus = _GUICtrlStatusBar_Create ($hGUI)
    GUISetState()
    ; Set parts
    _GUICtrlStatusBar_SetParts ($hStatus, $aParts)
    _GUICtrlStatusBar_SetText ($hStatus, "Part 1")
    _GUICtrlStatusBar_SetText ($hStatus, "Part 2", 1)
    ; Set background color
    _GUICtrlStatusBar_SetBkColor ($hStatus, $CLR_MONEYGREEN)
    ; Loop until user exits
     XPStyle(0)
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>_Main
Func XPStyle($OnOff = 1)
    If $OnOff And StringInStr(@OSTYPE, "WIN32_NT") Then
        $XS_n = DllCall("uxtheme.dll", "int", "GetThemeAppProperties")
        DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 0)
        Return 1
    ElseIf StringInStr(@OSTYPE, "WIN32_NT") And IsArray($XS_n) Then
        DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", $XS_n[0])
        $XS_n = ""
        Return 1
    EndIf
    Return 0
EndFunc   ;==>XPStyle

PS: I tried using the [ AutoIt ] button in the editor menu to post the code here but it refuses to post and when I try to cancel it says "options changed" so I just posted it with manually putting that code highlighting in. A wee bug in the forum software or ( Keyboard<->Chair ) interface issue ? ;)

Thanks in Advance for the help

WhiteStar

~ WhiteStar Magic

Always tuned to http://www.superbluesradio.com/  Tune in at http://87.117.217.41:8036/

Link to comment
Share on other sites

that problem has been reported quite some time ago. it's quite possible that it even stopped working as far back as windows xp. for sure that function doesn't work in vista or 7

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Try it this way, this sets the theme for the control only, and not the entire window.

#include <GuiConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <WinAPI.au3>
#include <Constants.au3>
Dim $XS_n
$Debug_SB = False ; Check ClassName being passed to functions, set to True and use a handle to another control to see it work
_Main()
Func _Main()
    Local $hGUI, $hStatus
    Local $aParts[3] = [75, 150, -1]
    ; Create GUI
;~  XPStyle(1)

    $hGUI = GUICreate("(Example 1) StatusBar Set BkColor", 400, 300)
    $hStatus = _GUICtrlStatusBar_Create($hGUI)
    GUISetState()
    ; Set parts
    _GUICtrlStatusBar_SetParts($hStatus, $aParts)
    _GUICtrlStatusBar_SetText($hStatus, "Part 1")
    _GUICtrlStatusBar_SetText($hStatus, "Part 2", 1)
    ; Set background color
    ; Loop until user exits
;~  XPStyle(0)
    _GUICtrlStatusBar_SetBkColor($hStatus, $CLR_MONEYGREEN)
    _SetTheme($hStatus)
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>_Main
Func XPStyle($OnOff = 1)
    If $OnOff And StringInStr(@OSType, "WIN32_NT") Then
        $XS_n = DllCall("uxtheme.dll", "int", "GetThemeAppProperties")
        DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 0)
        Return 1
    ElseIf StringInStr(@OSType, "WIN32_NT") And IsArray($XS_n) Then
        DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", $XS_n[0])
        $XS_n = ""
        Return 1
    EndIf
    Return 0
EndFunc   ;==>XPStyle
Func _SetTheme($iControl = -1)
    Local $aReturn = DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", $iControl, "wstr", 0, "wstr", 0)
    If @error Then Return SetError(1, 1, 0)
    Return $aReturn[0]
EndFunc   ;==>_ProgressSetTheme

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Thanks BrewManNH,

That seems to do the trick for the most part. There is an unpleasant side effect though.

At first, I thought it was because I use USkins.dll and skin my app but after commenting that out the issue still occurs. see below;

I'm using HTML Safe Colour Charts:

http://www.w3schools.com/html/html_colors.asp & http://www.tayloredmktg.com/rgb/ & http://www.febooti.com/products/iezoom/online-help/html-color-names-safe-color-chart.html which are identical for the values. So I know I'm not confused, even rechecked with PaintNET for a sanity check.

For an error, I want to set "0xFF0000" which is RED but ... it shows up as Blue and much closer to "0000FF" ! BUT this get's even MORE fun !!! Oivey...

If I put in "0x0000FF" I get the RED that I was after but that is the Safe Code for the Blue !

SO.... Now I'm totally confused with the colour rendering in AutoIT... What's the scoop ?

Thanks

~ WhiteStar Magic

Always tuned to http://www.superbluesradio.com/  Tune in at http://87.117.217.41:8036/

Link to comment
Share on other sites

I'd need to see your code, because you're describing it as if it's putting the colors on in BGR instead of RGB.

I just looked at the help file for _GUICtrlStatusBar_SetBkColor, you have to use BGR color codes in hex for that function.

color passed in must be BGR Hex color or RGB COLORREF

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Right on the money I was using RGB instead of BGR.... I been using RGB for things forever but I'm sure there is some good reason for BGR. I found this Snippet to make life easier http://www.autoitscript.com/wiki/Snippets_(_Graphics_)#SwitchColor.28.29_.7E_Author_-_RazerM

Thanks for all the help, Much appreciated.

~ WhiteStar Magic

Always tuned to http://www.superbluesradio.com/  Tune in at http://87.117.217.41:8036/

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...