Author Topic: Change the color of the statusbar/window  (Read 2415 times)

clamicun

  • Member
  • ***
  • Posts: 347
Change the color of the statusbar/window
« on: May 05, 2019, 02:57:21 AM »
I thought it would be easy to change the statuswindow color.

mov status_hnd, rv(CreateWindowEx,0,"msctls_statusbar32","Some text", WS_CHILD or WS_VISIBLE,0,0,0,0,main_hwnd,0,0,0)

RGB 0,0,255   
invoke SendMessage,status_hnd,SB_SETBKCOLOR,0,eax

Returns  4278190080  0xFF000000

It isn't because the color doesn't change

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 6868
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Change the color of the statusbar/window
« Reply #1 on: May 05, 2019, 04:55:05 AM »
A status bar colour is set by the settings in your operating system, its not adjustable. You can code your own but its no fun.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

clamicun

  • Member
  • ***
  • Posts: 347
Re: Change the color of the statusbar/window
« Reply #2 on: May 05, 2019, 05:13:47 AM »
A status bar colour is set by the settings in your operating system, its not adjustable. You can code your own but its no fun.

The  SB_SETBKCOLOR message is good for what ?

fearless

  • Member
  • ***
  • Posts: 469
    • LetTheLightIn
fearless

CM690II Case, HX1000 PSU, Asus Z97, Intel i7-4790K, Seidon 120v Cooler, 16GB DDR3, MSI GTX 980TI

My Github  Twitter

jj2007

  • Member
  • *****
  • Posts: 9928
  • Assembler is fun ;-)
    • MasmBasic
Re: Change the color of the statusbar/window
« Reply #4 on: May 05, 2019, 12:53:59 PM »
No rocket science, it works fine on Win7-64 - source attached (if you don't have RichMasm, open the *.asc file in WordPad). And yes, this is an ordinary CreateStatusWindowW bar.

The  SB_SETBKCOLOR message is good for what ?

It is good for setting the statusbar colour in case you have disabled "visual styles", "aero themes", whatever you want to call that crap. My method works also with Aero.

clamicun

  • Member
  • ***
  • Posts: 347
Re: Change the color of the statusbar/window
« Reply #5 on: May 05, 2019, 08:34:18 PM »
Beautiful, jj

Tryin to understand it

TimoVJL

  • Member
  • ***
  • Posts: 488
Re: Change the color of the statusbar/window
« Reply #6 on: May 05, 2019, 08:45:04 PM »
Disabling a Theme from statusbar is an option too.

EDIT: this wasn't tested yet ?
Code: [Select]
sUXT db "UxTheme.dll",0
sFunc db "SetWindowTheme",0
swNull dw 0
Wnd dd ?

INVOKE LoadLibraryA, ADDR sUXT
.if eax
INVOKE GetProcAddress, eax, ADDR sFunc
.if eax
push OFFSET swNull
push OFFSET swNull
push [Wnd]
call eax
.endif
.endif
« Last Edit: May 05, 2019, 09:48:23 PM by TimoVJL »
May the source be with you

clamicun

  • Member
  • ***
  • Posts: 347
Re: Change the color of the statusbar/window
« Reply #7 on: May 05, 2019, 09:04:26 PM »
To make it a bit easier.

ok. seems to be difficult to change the color of a "real" status bar-
Trying this one.

.if uMsg == WM_CREATE

INVOKE GetClientRect,main_hwnd,offset client
sub client.bottom,23

mov status_hnd, rv(CreateWindowEx,0,"Static","Some text", WS_CHILD or WS_VISIBLE,0,client.bottom,client.right,23,main_hwnd,0,0,0)

This looks like a status bar
How to change the background of this child window ?

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 6868
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Change the color of the statusbar/window
« Reply #8 on: May 05, 2019, 10:08:19 PM »
It is set in your WNDCLASSEX for the window.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

Vortex

  • Member
  • *****
  • Posts: 2062
Re: Change the color of the statusbar/window
« Reply #9 on: May 06, 2019, 02:03:52 AM »
Hi clamicun,

Here is how to create a status bar and change the color :

Code: [Select]
    .IF uMsg==WM_INITDIALOG

        invoke  CreateStatusWindow,WS_CHILD or WS_VISIBLE,\
                ADDR sbtext,hWnd,IDW_STATBAR

        mov     hStatusBar,eax
        RGB     200,210,50
        invoke  SendMessage,hStatusBar,SB_SETBKCOLOR,0,eax

jj2007

  • Member
  • *****
  • Posts: 9928
  • Assembler is fun ;-)
    • MasmBasic
Re: Change the color of the statusbar/window
« Reply #10 on: May 06, 2019, 03:12:01 AM »
Hi Erol,

As explained above, Windows ignores SB_SETBKCOLOR if an Aero resp "visual" theme is active.

TimoVJL

  • Member
  • ***
  • Posts: 488
Re: Change the color of the statusbar/window
« Reply #11 on: May 06, 2019, 03:17:19 AM »
In Reply #3 from fearless is a link
Quote
So, disable theme for status bar (SetWindowTheme) and color it using SB_SETBKCOLOR.
May the source be with you

Vortex

  • Member
  • *****
  • Posts: 2062
Re: Change the color of the statusbar/window
« Reply #12 on: May 06, 2019, 03:19:39 AM »
Hi Jochen,

I tested the example on a Windows 7 64-bit system with the aero effect enabled. No any problem.

AW

  • Member
  • *****
  • Posts: 2519
  • Let's Make ASM Great Again!
Re: Change the color of the statusbar/window
« Reply #13 on: May 06, 2019, 03:25:49 AM »
I tested the example on a Windows 7 64-bit system with the aero effect enabled. No any problem.


I don't think it will work with Visual Styles enabled and "all" applications use to have Visual Styles enabled:

Code: [Select]
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
    version="1.0.0.0"
    processorArchitecture="*"
    name="CompanyName.ProductName.YourApplication"
    type="win32"
/>
<description>Your application description here.</description>
<dependency>
    <dependentAssembly>
        <assemblyIdentity
            type="win32"
            name="Microsoft.Windows.Common-Controls"
            version="6.0.0.0"
            processorArchitecture="*"
            publicKeyToken="6595b64144ccf1df"
            language="*"
        />
    </dependentAssembly>
</dependency>
</assembly>

It is possible to turn off Visual Styles on some controls by calling SetWindowTheme.

So this works with Visual Styles enabled (modified Vortex code, thank  you):

Code: [Select]
include SetStatBarCol.inc

RGB MACRO red,green,blue

    xor     eax,eax
    mov     ah,blue
    shl     eax,8
    mov     ah,green
    mov     al,red

ENDM


DlgProc PROTO :DWORD,:DWORD,:DWORD,:DWORD

IDW_STATBAR equ 1000

.data

DlgBox      db 'DLGBOX',0
sbtext      db 'Status bar',0

includelib \masm32\lib\UxTheme.lib
SetWindowTheme proto :HWND, :ptr, :ptr

.data

hStatusBar  dd ?
nada db 0

.code

start:

    invoke  GetModuleHandle,0
    invoke  DialogBoxParam,eax,ADDR DlgBox,0,ADDR DlgProc,0
    invoke  ExitProcess,eax

DlgProc PROC hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM

    .IF uMsg==WM_INITDIALOG

        invoke  CreateStatusWindow,WS_CHILD or WS_VISIBLE,\
                ADDR sbtext,hWnd,IDW_STATBAR

        mov     hStatusBar,eax
invoke SetWindowTheme, hStatusBar, offset nada, offset nada

        RGB     255,0,0

        invoke  SendMessage,hStatusBar,SB_SETBKCOLOR,0,eax

    .ELSEIF uMsg==WM_CLOSE

        invoke  EndDialog,hWnd,0

    .ELSE

        xor     eax,eax
        ret

    .ENDIF

    mov     eax,1
    ret

DlgProc ENDP

END start

jj2007

  • Member
  • *****
  • Posts: 9928
  • Assembler is fun ;-)
    • MasmBasic
Re: Change the color of the statusbar/window
« Reply #14 on: May 06, 2019, 08:52:30 AM »
Hi Jochen,

I tested the example on a Windows 7 64-bit system with the aero effect enabled. No any problem.

Hi Erol,

I just built your code and tested it, and strangely enough, it works with Aero enabled. This is weird, my SB_SETBKCOLOR message refuses to work with Aero (and it works fine with a non-Aero theme). Mysteries of Windows... :(

Mine is a window, yours is a dialog - could that make a difference?