Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Message while execute code
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
Miscellaneous
Thread ID:
01411762
Message ID:
01411812
Views:
55
Hi Moises,

>Which is the best way to display a message while executing a code
>and hide it after code is executed ?

This really depends on what your goal is... Maybe it's easier to start with the limitations. FoxPro executes code on the UI thread. That means as long as VFP is running code it won't update the screen. This makes it impossible to use, for instance, animated GIFs or other animation that are painted in the UI thread. They simply won't show up. Animating images in a loop often doesn't look smooth.

Depending on the project I use different way to show messages. In some projects, I display a toolbar windows to indicate what the program is doing, right now. The toolbar window has got the advantage of never becoming the active window in VFP. This means that the form's Activate and Deactivate event aren't firing:
Public gox
gox = CreateObject("ShowMsg","Infecting computer... please wait.")
gox.Show()

*========================================================================================
* Message class
*========================================================================================
Define Class ShowMsg as Toolbar

	BackColor = Rgb(255,255,217)
	ControlBox = .F.
	Sizable = .F.
	Movable = .F.
	Themes = .F.
	Caption = ""

Procedure Init
LParameter tcText

	*--------------------------------------------------------------------------------------
	* Add objects
	*--------------------------------------------------------------------------------------
	This.AddObject("cnt","Container")
	This.cnt.BackStyle = 0
	This.cnt.BorderWidth = 0
	This.cnt.Height = 80
	This.cnt.AddObject("Label1","label")
	This.cnt.Label1.Move(26,26,26,26)
	This.cnt.Label1.FontName = "Verdana"
	This.cnt.Label1.FontSize = 13
	This.cnt.Label1.BackStyle = 0
	This.cnt.Label1.ForeColor = Rgb(0,0,160)
	This.cnt.Label1.Visible = .T.
	This.cnt.Visible = .T.

	*--------------------------------------------------------------------------------------
	* Determine default text
	*--------------------------------------------------------------------------------------
	Local lcText
	If Vartype(m.tcText) == "C"
		lcText = m.tcText
	Else
		lcText = "Please wait..."
	EndIf
	
	*--------------------------------------------------------------------------------------
	* Determine the length of the windows
	*--------------------------------------------------------------------------------------
	Local lnLen
	lnLen = TxtWidth(m.lcText,"Arial",14,"B") * Fontmetric(6,"Arial",14,"B")
	This.cnt.Width = 25 + m.lnLen + 25
	This.cnt.Label1.Caption = m.lcText
	This.cnt.Label1.Width = m.lnLen
	
	*--------------------------------------------------------------------------------------
	* Position on the screen centered.
	*--------------------------------------------------------------------------------------
	This.Move( ;
		(_Screen.Width - This.cnt.Width - 6) / 2, ;
		(_Screen.Height - This.cnt.Height - 20) / 2 ;
	)

EndProc
EndDefine 
--
Christof
Previous
Reply
Map
View

Click here to load this message in the networking platform