Is there a way to set the BackColor of a panel in a StatusBar?
> 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 ---
Also the CCRP project has a really nice full featured statusbar, that
uses their downloadable ccrpsbrb.ocx.
"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
Q. Would it also be possible to change the font color in the statusbar?
"MikeD" wrote:
> .
>
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...
"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
"LondonLad" <Lond...@discussions.microsoft.com> wrote in message
news:47FE43E7-0895-45BF...@microsoft.com...
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.
--
Mike
"Jack T." <anyw...@anywhere.com> wrote in message
news:#6x29Dwi...@TK2MSFTNGP04.phx.gbl...
"MikeD" <nob...@nowhere.edu> wrote in message
news:%23OHCvSw...@TK2MSFTNGP05.phx.gbl...
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. :-)
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
"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
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
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?
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
Good point. I'd only amend that to say "which _may_ be a problem."
--