Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I create my own statusbar?

Tips -N- Tricks

How can I create my own statusbar?

by  ChrisRChamberlain  Posted    (Edited  )
If you need more from a StatusBar than either the native VFP or the MS StatusBar ActiveX control can offer, then creating your own InterNet Explorer style statusbar is not as difficult as you might imagine.

What this statusbar will not do is display the messages from a VFP menu.

What it will do is a whole lot more than the alternatives and is only really limited by your imagination as a developer! [smile]

In the following example a simple five panel statusbar bar is created.

Panel 1 - Bitmap + line of text

This is used to display a 16 x 16 bitmap and text string relative to the control passed over by the mouse, or any other bitmaps/messages you programatically send.

Panel 2 - Progressbar

This displays the progress of processing within a loop

Panel 3 - AVI Player

This displays 16 x 16 .avi files

Panel 4 - Time display

Time including seconds, (if you don't already have a timer running, you will need to add one)

Panel 5 - Date display

Today's date


The example comes from an MDI form which sits at the bottom of [color blue]_SCREEN[/color], so to include the statusbar in a form, you simply replace the [color blue]_SCREEN[/color] references with [color blue]THISFORM[/color].

The panels are containers with the following non-default properties
[color blue]
.Height = 20
.SpecialEffect = 1
[/color]
The containers for panels 1 - [color blue].cntPanel1[/color], 2 - [color blue].cntPanel2[/color] and 3 - [color blue].cntPanel3[/color], each have a form method relative to the container, [color blue].mCntPanel1()[/color], [color blue].mCntPanel2()[/color] and [color blue].mCntPanel3()[/color].

File names, messages etc are passed to the controls in the container through the methods as parameters.

The [color blue].Resize()[/color] event of the form adjusts the positions of the containers relative to the width of the form.
The width of [color blue].cntPanel1[/color] is adjusted relative to the width of the remaining space in the statusbar.

The code and controls required for the progressbar can be found in FAQ184-2366

You will not find many 16 x 16 .avi files but making your own is easy.

Let's assume you want the print icon or the save icon to flash during an operation. In animation terms you could use two bitmaps, a 16 x 16 bitmap with an image and 16 x 16 bitmap without an image. The player continuously plays the sequence and thus the display flashes, until told to stop.

To show the .avi file you need the OleClass MSComCt2.Animation.2 control to be found in the list of ActiveX controls.
To be able to create .avi files, download the freeware AviCreator 1.5 to be found through any Internet search engine.

If you don't want to take advantage of the possibilities presented by using the animation control, a simple workaround is to use an image control instead and use the timer event to toggle the [color blue].Visible[/color] property. This will cause the image control to appear/disappear every second.

The sizing of the controls is important - I suggest you use MS Sans Serif fontsize 9 for the labels and 16 x 16 for the image and olecontrol. The texbox use for the progressbar should be the same size as its container.

So how do you send messages to the statusbar?

In the [color blue].MouseEnter()[/color] or [color blue].MouseMove()[/color] event of a control such as a commandbutton of a toolbar, put :-
[color blue]
oStatusBar.mCntPanel1(THIS.Picture,THIS.ToolTipText)
[/color]
The code in the method [color blue].mCntPanel1()[/color] would be :-
[color blue]
LPARAMETERS cFile, cLine1

WITH THIS
[tab].cntPanel1.Image1.Picture = cFile
[tab].cntPanel1.Label1.Caption = cLine1
ENDWITH
[/color]
For form objects, you need to substitute [color blue]THIS.Picture[/color] with a path\filename.ext


To play/stop an .avi file
[color blue]
oStatusBar.mCntPanel3([avi\print.avi],[Play])
[/color]
or
[color blue]
oStatusBar.mCntPanel3([avi\print.avi],[Stop])
[/color]
The code in the method [color blue].mCntPanel3()[/color] would be :-
[color blue]
LPARAMETERS cFile, cAction

THIS.cntPanel3.oleAviPlayer.Open(cFile)
lcExpr = [THIS.cntPanel3.oleAviPlayer.] + cAction
&lcExpr
[color black]
The code from the form follows to enable you to put your own version together.
[color blue]
PUBLIC ofooter

ofooter=NEWOBJECT("footer")
ofooter.Show
RETURN


*************************************************
*-- Form: footer (c:\test\newfooter.scx)
*-- ParentClass: form
*-- BaseClass: form
*-- Time Stamp: 02/11/03 09:06:00 AM
*
DEFINE CLASS footer AS form


Top = 0
Left = 0
Height = 27
Width = 812
DoCreate = .T.
ShowTips = .T.
BorderStyle = 0
Caption = ""
ControlBox = .F.
Closable = .F.
FontName = "MS Sans Serif"
TitleBar = 0
WindowState = 0
AlwaysOnBottom = .T.
Name = "FOOTER"
lfullsize = .F.


ADD OBJECT cntpanel1 AS container WITH ;
Top = 4, ;
Left = 1, ;
Width = 53, ;
Height = 20, ;
SpecialEffect = 1, ;
Name = "cntPanel1"


ADD OBJECT footer.cntpanel1.image1 AS image WITH ;
Picture = "bitmaps\autoname.bmp", ;
BackStyle = 0, ;
Height = 16, ;
Left = 2, ;
Top = 2, ;
Width = 16, ;
Name = "Image1"


ADD OBJECT footer.cntpanel1.label1 AS label WITH ;
AutoSize = .T., ;
FontName = "MS Sans Serif", ;
Caption = "Label1", ;
Height = 15, ;
Left = 19, ;
Top = 4, ;
Width = 34, ;
Name = "Label1"


ADD OBJECT cntpanel2 AS container WITH ;
Top = 4, ;
Left = 277, ;
Width = 224, ;
Height = 20, ;
SpecialEffect = 1, ;
Name = "cntPanel2"


ADD OBJECT footer.cntpanel2.txtprogressbar AS textbox WITH ;
FontBold = .F., ;
FontName = "MS Sans Serif", ;
Alignment = 2, ;
BorderStyle = 1, ;
Enabled = .F., ;
Height = 20, ;
Left = 0, ;
ReadOnly = .T., ;
TabStop = .F., ;
Top = 0, ;
Visible = .F., ;
Width = 432, ;
DisabledBackColor = RGB(255,255,255), ;
DisabledForeColor = RGB(0,0,0), ;
Name = "txtProgressBar"


ADD OBJECT cntpanel3 AS container WITH ;
Top = 4, ;
Left = 523, ;
Width = 21, ;
Height = 20, ;
SpecialEffect = 1, ;
Name = "cntPanel3"


ADD OBJECT footer.cntpanel3.oleaviplayer AS olecontrol WITH ;
Top = 2, ;
Left = 2, ;
Height = 16, ;
Width = 16, ;
Name = "oleAviPlayer"


ADD OBJECT cntpanel4 AS container WITH ;
Top = 4, ;
Left = 547, ;
Width = 51, ;
Height = 20, ;
SpecialEffect = 1, ;
Name = "cntPanel4"


ADD OBJECT footer.cntpanel4.label1 AS label WITH ;
AutoSize = .T., ;
FontName = "MS Sans Serif", ;
Caption = "Label1", ;
Height = 15, ;
Left = 4, ;
Top = 4, ;
Width = 34, ;
Name = "Label1"


ADD OBJECT cntpanel5 AS container WITH ;
Top = 4, ;
Left = 600, ;
Width = 55, ;
Height = 20, ;
SpecialEffect = 1, ;
Name = "cntPanel5"


ADD OBJECT footer.cntpanel5.label1 AS label WITH ;
AutoSize = .T., ;
FontName = "MS Sans Serif", ;
Caption = "Label1", ;
Height = 15, ;
Left = 3, ;
Top = 4, ;
Width = 34, ;
Name = "Label1"


ADD OBJECT tmrtime AS timer WITH ;
Top = 0, ;
Left = 684, ;
Height = 23, ;
Width = 23, ;
Interval = 1000, ;
Name = "tmrTime"


PROCEDURE mcntlabel1
LPARAMETERS cFile, cLine1

WITH THIS
.cntPanel1.Image1.Picture = cFile
.cntPanel1.Label1.Caption = cLine1
ENDWITH
ENDPROC


PROCEDURE mcntlabel3
LPARAMETERS cFile, cAction

THIS.cntPanel3.oleAviPlayer.Open(cFile)
lcExpr = [THIS.cntPanel3.oleAviPlayer.] + cAction
&lcExpr
ENDPROC


PROCEDURE Resize
WITH THIS
.Height = 27
.Top = _SCREEN.Height - 27
.Width = _SCREEN.Width

WITH .cntPanel2
.Left = _SCREEN.Width - 338
.Width = 200
ENDW

WITH .cntPanel3
.Left = _SCREEN.Width - 136
ENDWITH

WITH .cntPanel4
.Left = _SCREEN.Width - 113
ENDWITH

WITH .cntPanel5
.Left = _SCREEN.Width - 60
ENDWITH

WITH .cntPanel1 && The one panel that resizes
.Left = 3
.Width = _SCREEN.Width - 343
ENDW
ENDW
ENDPROC


PROCEDURE Init
THIS.Resize()
THIS.mCntLabel1([],[This is a test, and an even bigger test])
THIS.mCntLabel2()
THIS.mCntLabel3([bitmaps\n3.avi],[Play])
ENDPROC


PROCEDURE Destroy
RELE oFooter
ENDPROC


PROCEDURE mcntlabel2
ENDPROC


PROCEDURE mcntlabel4
ENDPROC


PROCEDURE mcntlabel5
ENDPROC


PROCEDURE label1.MouseEnter
LPARAMETERS nButton, nShift, nXCoord, nYCoord
THIS.ToolTipText = THIS.Caption
ENDPROC


PROCEDURE label1.MouseEnter
LPARAMETERS nButton, nShift, nXCoord, nYCoord
THIS.ToolTipText = [The time is ] + THIS.Caption
ENDPROC


PROCEDURE label1.MouseEnter
LPARAMETERS nButton, nShift, nXCoord, nYCoord
THIS.ToolTipText = [The date is ] + THIS.Caption
ENDPROC


PROCEDURE tmrtime.Timer
THISFORM.cntPanel4.Label1.Caption = TIME()
ENDPROC


ENDDEFINE
*
*-- EndDefine: footer
**************************************************
[color black]
If anyone can work out a way of utilizing the messages from a VFP menu, please advise

Have fun

ChrisRChamberlain
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top