Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Set backcolor in a StatusBar ?

20 views
Skip to first unread message

Martin

unread,
Dec 30, 2009, 2:59:18 PM12/30/09
to
I've googled around a bit but couldn't find anything.

Is there a way to set the BackColor of a panel in a StatusBar?

mscir

unread,
Dec 30, 2009, 3:39:07 PM12/30/09
to
Martin wrote:

> I've googled around a bit but couldn't find anything.
> Is there a way to set the BackColor of a panel in a StatusBar?

If you're willing to use a picturebox... I don't remember where I
downloaded this so unfortunately I can't give credit to the author.

Option Explicit

Private Declare Function SetParent Lib "user32" (ByVal hWndChild As _
Long, ByVal hWndNewParent As Long) As Long
Private Declare Function SendMessageAny Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, lParam _
As Any) As Long

Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Const WM_USER As Long = &H400
Private Const SB_GETRECT As Long = (WM_USER + 10)

Private Sub Form_Load()
With StatusBar1
.Panels.Clear
.Panels.Add
.Panels.Add
End With
With Picture1(0)
.BorderStyle = 1
.AutoRedraw = True
.BackColor = vbRed
.ForeColor = vbWhite
End With
Picture1(0).Print "Testing.."
'Do another
Load Picture1(1)
With Picture1(1)
.BorderStyle = 1
.AutoRedraw = True
.BackColor = vbBlue
.ForeColor = vbWhite
End With
Picture1(1).Print "123..."
End Sub

Private Sub Form_Resize()
Dim PB As PictureBox
For Each PB In Picture1
Call ShowInStatusBar(PB, PB.Index)
Next
End Sub

Private Sub ShowInStatusBar(ByRef PB As PictureBox, ByVal PanelIndex As
Integer)
Dim tRC As RECT
' Get the size of the Panel Rectangle from the status bar
SendMessageAny StatusBar1.hwnd, SB_GETRECT, PanelIndex, tRC
' and convert it to twips....
With tRC
.Top = (.Top * Screen.TwipsPerPixelY)
.Left = (.Left * Screen.TwipsPerPixelX)
.Bottom = (.Bottom * Screen.TwipsPerPixelY) - .Top
.Right = (.Right * Screen.TwipsPerPixelX) - .Left
End With
' Now Reparent the Picturebox to the statusbar
With PB
SetParent .hwnd, StatusBar1.hwnd
.Move tRC.Left, tRC.Top, tRC.Right, tRC.Bottom
.Visible = True
End With
End Sub

--- news://freenews.netfront.net/ - complaints: ne...@netfront.net ---

mscir

unread,
Dec 30, 2009, 3:43:57 PM12/30/09
to
Martin wrote:
> I've googled around a bit but couldn't find anything.
>
> Is there a way to set the BackColor of a panel in a StatusBar?

Also the CCRP project has a really nice full featured statusbar, that
uses their downloadable ccrpsbrb.ocx.

http://ccrp.mvps.org/

MikeD

unread,
Dec 30, 2009, 7:00:31 PM12/30/09
to

"Martin" <ironwoo...@gmail.com> wrote in message
news:n4cnj5hpgpd71uma9...@4ax.com...


> I've googled around a bit but couldn't find anything.
>
> Is there a way to set the BackColor of a panel in a StatusBar?

Send it a SB_SETBKCOLOR message.

Option Explicit

Private Const CCM_SETBKCOLOR As Long = &H2001&
Private Const SB_SETBKCOLOR As Long = CCM_SETBKCOLOR
Private Const CLR_DEFAULT As Long = &HFF000000
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As
Any) As Long

Private Sub Form_Click()

Call SendMessage(StatusBar1.hwnd, SB_SETBKCOLOR, 0&, ByVal RGB(255, 0,
0))

End Sub


Note that if the status bar has a sizing handle, the sizing handle doesn't
change color. So, this "works" best if the status bar is using the simple
style.

--
Mike

LondonLad

unread,
Jan 1, 2010, 7:11:01 AM1/1/10
to
Hi MikeD

Q. Would it also be possible to change the font color in the statusbar?

"MikeD" wrote:

> .
>

Jack T.

unread,
Jan 1, 2010, 11:39:31 AM1/1/10
to
Yes

hFont = CreateFont(13, 0, 0, 0, 700, 1, 0, 0, 1, 0, 0, 0, 0, "Verdana")

SendMessage statusbar.hwnd, WM_SETFONT, hFont, ByVal True


"LondonLad" <Lond...@discussions.microsoft.com> wrote in message
news:47FE43E7-0895-45BF...@microsoft.com...

MikeD

unread,
Jan 1, 2010, 11:41:19 AM1/1/10
to

"LondonLad" <Lond...@discussions.microsoft.com> wrote in message
news:47FE43E7-0895-45BF...@microsoft.com...

> Hi MikeD
>
> Q. Would it also be possible to change the font color in the statusbar?
>

Not that I know of. There is no message for setting the text color. If you
can make a StatusBar owner-drawn, then maybe...but I don't see anything in
its documentation for making it owner-drawn. You could probably fake it by
overlaying a picture box and then either printing directly onto the picture
box or using Label controls contained in the picture box. But it's not
something I would really recommend. For that matter, I really don't even
recommend changing the backcolor except for short durations to temporarily
bring attention to something in the status bar.

--
Mike

Jack T.

unread,
Jan 1, 2010, 11:42:12 AM1/1/10
to
Opps, sorry for my last post. I should have read the whole thing.


"LondonLad" <Lond...@discussions.microsoft.com> wrote in message
news:47FE43E7-0895-45BF...@microsoft.com...

Nobody

unread,
Jan 1, 2010, 11:49:28 AM1/1/10
to
"Jack T." <anyw...@anywhere.com> wrote in message
news:%236x29Dw...@TK2MSFTNGP04.phx.gbl...

> Yes
>
> hFont = CreateFont(13, 0, 0, 0, 700, 1, 0, 0, 1, 0, 0, 0, 0, "Verdana")
>
> SendMessage statusbar.hwnd, WM_SETFONT, hFont, ByVal True

TRUE in C/Windows API = +1 (0000 0001 Hex)
True in VB = -1 (FFFF FFFF Hex)

Use "ByVal 1&" to pass TRUE to API functions.


MikeD

unread,
Jan 1, 2010, 12:05:51 PM1/1/10
to

I don't see where that in itself changes the font's color. Also, you
omitted some important information in that you must destroy the font
resource by calling DeleteObject.

--
Mike


"Jack T." <anyw...@anywhere.com> wrote in message

news:#6x29Dwi...@TK2MSFTNGP04.phx.gbl...

Jack T.

unread,
Jan 1, 2010, 12:13:20 PM1/1/10
to
Read my follow up post. I realized I answered the wrong question.


"MikeD" <nob...@nowhere.edu> wrote in message
news:%23OHCvSw...@TK2MSFTNGP05.phx.gbl...

C. Kevin Provance

unread,
Jan 1, 2010, 12:21:40 PM1/1/10
to
"MikeD" <nob...@nowhere.edu> wrote in message
news:uSFbBFwi...@TK2MSFTNGP04.phx.gbl...

| Not that I know of. There is no message for setting the text color. If you
| can make a StatusBar owner-drawn, then maybe...but I don't see anything in
| its documentation for making it owner-drawn. You could probably fake it by
| overlaying a picture box and then either printing directly onto the
picture
| box or using Label controls contained in the picture box. But it's not
| something I would really recommend. For that matter, I really don't even
| recommend changing the backcolor except for short durations to temporarily
| bring attention to something in the status bar.

It can be done with subclassing.

In a nutshell, subclass the statusbar for WM_DRAWITEM + CCM_FIRST. Copy the
lp to a DRAWITEMSTRUCT (uDIS). The panel item would then be uDIS.itemID +
1.

Then changing the backcolor and text can be done in one stroke.

CopyRect the uDIS.rcItem to a RECT type. SetTextColor using uDIS.hDC and
the desired forecolor. Then CreateSolidBrush and FillRect to set the
backcolor. Now the actual text will have to be drawn, so the RECT type
should be adjusted as necessary +/- 3 or however long one might want the
indent to be. SetBkMode to 1 and then DrawText with whatever flags desired.
Doing this also requires trapping WM_PRINTCLIENT and WM_ERASEBKGND and
eating them.

Of course, all of this assumes the OP knows his stuff. I didn't bang out
all the code since it requires subclassing and each person uses their own
method. I encapusulated all of this in a class module so I could handle
each property properly (and used Karl's IHookSink to do all the subclassing.

Piece of cake. :-)


Karl E. Peterson

unread,
Jan 8, 2010, 6:13:41 PM1/8/10
to
After serious thinking Nobody wrote :

> Use "ByVal 1&" to pass TRUE to API functions.

Most API functions use 0 for False, and <>0 as True, though, just as VB
does. Occassionally you run across the dipsh!t subsystem coder who
tested for a specific value, but those are very rare.

--
.NET: It's About Trust!
http://vfred.mvps.org


MikeD

unread,
Jan 9, 2010, 7:20:48 AM1/9/10
to

"Karl E. Peterson" <ka...@exmvps.org> wrote in message
news:eSbm5gLk...@TK2MSFTNGP05.phx.gbl...


> After serious thinking Nobody wrote :
>> Use "ByVal 1&" to pass TRUE to API functions.
>
> Most API functions use 0 for False, and <>0 as True, though, just as VB
> does. Occassionally you run across the dipsh!t subsystem coder who tested
> for a specific value, but those are very rare.
>

Yes, but there's really no way of knowing which API functions specifically
are coded to be 1 and which are coded to be <>0; so, to be safe, it's best
(at least IMO) to always use 1 for an API TRUE. Not -1 and not VB's
intrinsic True.

--
Mike

Ralph

unread,
Jan 9, 2010, 7:52:48 AM1/9/10
to

"MikeD" <nob...@nowhere.edu> wrote in message
news:OTapwYSk...@TK2MSFTNGP05.phx.gbl...

Actually the only thing you can be sure about is that zero, null, nul, and
'empty' is false and anything else is true. But this is only of any real
interest when examining the result from comparison operators, in which case
assuming a result of "1" as true will always get you into trouble sooner or
later.

Confusing "Success" with True and False will also get you into trouble.

All functions in the Win32 API, and those libraries not formally in
Win32API, but considered as part of the Windows API, clearly document what
is expected.

-ralph


Karl E. Peterson

unread,
Jan 11, 2010, 3:48:06 PM1/11/10
to
MikeD pretended :
> "Karl E. Peterson" <ka...@exmvps.org> wrote...

>> After serious thinking Nobody wrote :
>>> Use "ByVal 1&" to pass TRUE to API functions.
>>
>> Most API functions use 0 for False, and <>0 as True, though, just as VB
>> does. Occassionally you run across the dipsh!t subsystem coder who tested
>> for a specific value, but those are very rare.
>
> Yes, but there's really no way of knowing which API functions specifically
> are coded to be 1 and which are coded to be <>0; so, to be safe, it's best
> (at least IMO) to always use 1 for an API TRUE. Not -1 and not VB's
> intrinsic True.

Nothing wrong with erring on the side of correctness, I suppose. <g> I
tend to use True myself, until I get "unexpected" results, because I
find the code more readable that way. Trade-offs, huh?

Nobody

unread,
Jan 11, 2010, 4:12:17 PM1/11/10
to

"Karl E. Peterson" <ka...@exmvps.org> wrote in message
news:umIEi9vk...@TK2MSFTNGP05.phx.gbl...

Using "True" in API parameter declared as BOOL, which is 4 bytes works if
the declaration in VB uses "As Long". If the VB declaration uses As Any,
which is rare, then VB would only pass 2 bytes, which is a problem.


Karl E. Peterson

unread,
Jan 11, 2010, 6:54:52 PM1/11/10
to
Nobody was thinking very hard :

Good point. I'd only amend that to say "which _may_ be a problem."

Ralph

unread,
Jan 11, 2010, 7:02:06 PM1/11/10
to

Karl E. Peterson wrote:
> Nobody was thinking very hard :
>>
>> Using "True" in API parameter declared as BOOL, which is 4 bytes
>> works if the declaration in VB uses "As Long". If the VB declaration
>> uses As Any, which is rare, then VB would only pass 2 bytes, which
>> is a problem.
>
> Good point. I'd only amend that to say "which _may_ be a problem."

But if it is - it WILL always happen at 5:30pm just at the start of a 3 day
weekend with the family packed and waiting.

-ralph


Karl E. Peterson

unread,
Jan 11, 2010, 7:11:18 PM1/11/10
to
Nobody was thinking very hard :

Good point. I'd only amend that to say "which _may_ be a problem."

--

0 new messages