Enable/Disable a Main Menu

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

User avatar
CalScot
Posts: 303
Joined: Thu Mar 21, 2013 12:22 am
Location: California

Re: Enable/Disable a Main Menu

Post by CalScot »

Hi, Serge.

The program is exactly as given in my earlier message (i.e., copied complete and directly from the code), and the window (Form_1.fmg) is an IDE-generated form with the parameters set up as given in that message, but here's the form code:

Code: Select all

* HMG-IDE Form Designer Generated Code
* (c) Roberto Lopez - http://sites.google.com/site/hmgweb

DEFINE WINDOW TEMPLATE AT 138 , 235 WIDTH 400 HEIGHT 200 VIRTUAL WIDTH Nil VIRTUAL HEIGHT Nil TITLE "Blink test" ICON NIL MAIN CURSOR NIL ON INIT Nil ON RELEASE Nil ON INTERACTIVECLOSE Nil ON MOUSECLICK Nil ON MOUSEDRAG Nil ON MOUSEMOVE Nil ON SIZE Nil ON MAXIMIZE Nil ON MINIMIZE Nil ON PAINT Nil BACKCOLOR Nil NOTIFYICON NIL NOTIFYTOOLTIP NIL ON NOTIFYCLICK Nil ON GOTFOCUS Nil ON LOSTFOCUS Nil ON SCROLLUP Nil ON SCROLLDOWN Nil ON SCROLLLEFT Nil ON SCROLLRIGHT Nil ON HSCROLLBOX Nil ON VSCROLLBOX Nil

    DEFINE LABEL Label_1
        ROW    10
        COL    10
        WIDTH  150
        HEIGHT 24
        VALUE "Process 1 under way..."
        FONTNAME "Arial"
        FONTSIZE 9
        TOOLTIP ""
        FONTBOLD .F.
        FONTITALIC .F.
        FONTUNDERLINE .F.
        FONTSTRIKEOUT .F.
        HELPID Nil
        VISIBLE .T.
        TRANSPARENT .F.
        ACTION Nil
        AUTOSIZE .F.
        BACKCOLOR NIL
        FONTCOLOR NIL
    END LABEL

    DEFINE LABEL Label_2
        ROW    10
        COL    170
        WIDTH  120
        HEIGHT 24
        VALUE "Completed!"
        FONTNAME "Arial"
        FONTSIZE 9
        TOOLTIP ""
        FONTBOLD .F.
        FONTITALIC .F.
        FONTUNDERLINE .F.
        FONTSTRIKEOUT .F.
        HELPID Nil
        VISIBLE .F.
        TRANSPARENT .F.
        ACTION Nil
        AUTOSIZE .F.
        BACKCOLOR NIL
        FONTCOLOR NIL
    END LABEL

    DEFINE LABEL Label_3
        ROW    50
        COL    10
        WIDTH  150
        HEIGHT 24
        VALUE "Process 2 under way..."
        FONTNAME "Arial"
        FONTSIZE 9
        TOOLTIP ""
        FONTBOLD .F.
        FONTITALIC .F.
        FONTUNDERLINE .F.
        FONTSTRIKEOUT .F.
        HELPID Nil
        VISIBLE .F.
        TRANSPARENT .F.
        ACTION Nil
        AUTOSIZE .F.
        BACKCOLOR NIL
        FONTCOLOR NIL
    END LABEL

    DEFINE LABEL Label_4
        ROW    50
        COL    170
        WIDTH  120
        HEIGHT 24
        VALUE "Completed!"
        FONTNAME "Arial"
        FONTSIZE 9
        TOOLTIP ""
        FONTBOLD .F.
        FONTITALIC .F.
        FONTUNDERLINE .F.
        FONTSTRIKEOUT .F.
        HELPID Nil
        VISIBLE .F.
        TRANSPARENT .F.
        ACTION Nil
        AUTOSIZE .F.
        BACKCOLOR NIL
        FONTCOLOR NIL
    END LABEL

    DEFINE TIMER Timer_1 INTERVAL 400 ACTION  ( Blink(), lOnOff := ! lOnOff )

END WINDOW
Thanks for your interest!
CalScot
User avatar
CalScot
Posts: 303
Joined: Thu Mar 21, 2013 12:22 am
Location: California

Re: Enable/Disable a Main Menu

Post by CalScot »

Just to clarify:

The reason I set up a separate .fmg file (rather than defining the table in the code) was that if I included "Visible := .F." and "OnInit" in the code, the compiler rejected it.

Thanks.
CalScot
User avatar
serge_girard
Posts: 3161
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Enable/Disable a Main Menu

Post by serge_girard »

CalScot,

Look at my modifications. I changed INKEY(5) with

Code: Select all

for a = 1 to 5000000  // proces simulation
	do events
next a
then

Code: Select all

function sg()
if lOnOff 
	SetProperty('Form_1', cLabel, 'Value' , '' )
else
	SetProperty('Form_1', cLabel, 'Value' ,'Process 1 under way...' )  // to do proces 1...n
endif
lOnOff := ! lOnOff
And in .FMG:

Code: Select all

ON INIT (F1Procs(), sg())
This all could come close to your wishes?

Serge
There's nothing you can do that can't be done...
User avatar
serge_girard
Posts: 3161
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Enable/Disable a Main Menu

Post by serge_girard »

+ Form_1.Timer_1.Enabled := .F.
at the end....

Serge
There's nothing you can do that can't be done...
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: Enable/Disable a Main Menu

Post by andyglezl »

Hola CalScot

Y si lo ves desde otra perspectiva ?
--------------------------------------
Hello CalScot

And if you see it from another perspective?


Code: Select all

#include "hmg.ch" 

FUNCTION MAIN()
	
    DEFINE WINDOW WinMain AT 50 , 50 WIDTH 200 HEIGHT 300 TITLE "MAIN" BACKCOLOR RED MAIN NOMAXIMIZE NOMINIMIZE ON INIT Procesos()
		@ 10 , 00 LABEL LB_1 VALUE "" FONT "Arial" SIZE 16 WIDTH 200 HEIGHT 300 FONTCOLOR WHITE CENTERALIGN BOLD TRANSPARENT
	END WINDOW
	CENTER WINDOW WinMain
    ACTIVATE WINDOW WinMain
   
RETURN Nil
FUNCTION Procesos()
	
	Blink( "Inic Process..." )
	
	InKey( 5 )
   
	Blink( "Process 1" )
   
	InKey( 5 )
   
	Blink( "Process 2" )
   
	InKey( 5 )
   
	Blink( "End Process..." )   
	
RETURN
FUNCTION Blink(cText) 
	LOCAL lClr:=.T.

	PlayOk()
	
	WinMain.LB_1.Value:=WinMain.LB_1.Value+cText+HB_OsNewLine()
	
	FOR i1=1 TO 20
		*WinMain.LB_1.Backcolor:=IF( lClr,aClr1, aClr2 )
		IF lClr
			WinMain.Show
		ELSE
			WinMain.Hide
		ENDIF
		InKey( .2 )
		lClr:= ! lClr
	NEXT
		
	WinMain.Show
		
RETURN( Nil )
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
CalScot
Posts: 303
Joined: Thu Mar 21, 2013 12:22 am
Location: California

Re: Enable/Disable a Main Menu

Post by CalScot »

Thank you, Serge and Andy, for your suggestions and code.
I'm going to try both of them, even if the first one I try works; my continuing education!
It'll probably be tonight before I can get to them, but will post again afterwards.
Thanks again.
All of you guys are magnificent! :D You have no idea how much I appreciate the help!
CalScot
User avatar
CalScot
Posts: 303
Joined: Thu Mar 21, 2013 12:22 am
Location: California

Re: Enable/Disable a Main Menu

Post by CalScot »

OK - Here's a cleaned-up version with my changes to Serge's update of Carlos' code.
I'm posting it again mainly so that anyone who searches for a blinking label routine in the future will be able to find this working version.

I made only minor changes:
* Added variable cProc because Label_3 showed the wrong process name at the very end.
* Added a separate iteration of the function Sg() (I wonder why you called it Sg, Serge? :) ) near the end because the final blinking label sometimes didn't display when the process ended. I think that the value may have been set to <blank> when the timer was disabled.

Thanks again to everyone who helped solve this.
CalScot

Code: Select all

#include "hmg.ch"
Static lOnOff := .T.
Static cLabel := "Label_1"
Static cProc := "Process 1 running..."
****************
// Window (Form_1.fmg) defined in HMG-IDE using the following parameters:
// DEFINE WINDOW Form_1 AT 0,0 WIDTH 400 HEIGHT 200 TITLE 'Blink Test' MAIN
// @10,10  LABEL Label_1 VALUE "Process 1 running..." WIDTH 110
// @10,140 LABEL Label_2 VALUE "Completed!" WIDTH 100
// @50,10  LABEL Label_3 VALUE "Process 2 running..." WIDTH 110
// @50,140 LABEL Label_4 VALUE "Completed!" WIDTH 100
// DEFINE TIMER Timer_1 INTERVAL 400 ACTION ( Blink(), lOnOff := ! lOnOff )
// Form_1.fmg also has: ON INIT (F1Procs(), sg()) 
//                 and: Labels 2,3 & 4 are set to VISIBLE := .F.
Function Main
Load Window Form_1
Center Window Form_1
Activate Window Form_1
Return
********************
Function F1Procs()
   For a = 1 to 4000000       && Simulates running Process 1
      Do Events
   Next a
// Process 1 complete: Turn off Label_1 blink, Show Label_2, Turn on blinking Label_3
   BlinkOff()
   Form_1.Label_2.Visible := .T.
   cLabel := "Label_3"
   cProc := "Process 2 running..."
   Form_1.Timer_1.Enabled := .T.
   Form_1.Label_3.Visible := .T.
   For a = 1 to 4000000        && Simulates running Process 2
      Do Events
   Next a
// Process 2 complete: Turn off Label_3 blink, Show Label_4, End.
   BlinkOff()
   Form_1.Timer_1.Enabled := .F.
   lOnOff := .T.
   Sg()
   Form_1.Label_4.Visible := .T.
RETURN
******************
Function Blink()
   Form_1.&( cLabel ).Visible := lOnOff
Return
*********************
Function BlinkOff()
   Form_1.Timer_1.Enabled := .F.
   Form_1.&( cLabel ).Visible := .T.
Return
***************
Function Sg()
If lOnOff 
   SetProperty('Form_1', cLabel, 'Value' , '' )
Else
   SetProperty('Form_1', cLabel, 'Value', cProc )
EndIf
lOnOff := ! lOnOff
Return
*******
User avatar
serge_girard
Posts: 3161
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Enable/Disable a Main Menu

Post by serge_girard »

Hi Scot,

I'm glad it works now!

Personally I think it would be more easy to use progressbars + labels showing the process progress.
I think the timer function will comsume lots of CPU which would be better to give to the underlying processes.


Greetings & succes!

Serge
There's nothing you can do that can't be done...
User avatar
CalScot
Posts: 303
Joined: Thu Mar 21, 2013 12:22 am
Location: California

Re: Enable/Disable a Main Menu

Post by CalScot »

Bad news: The processes (which are mostly Do While !Eof() routines) seem to suspend or preempt the timer! (I think that must have been the problem with InKey(), too.)

I put the blinking code into my application, but it had no effect. Then I put For/Next loops before and after the the actual processes, and the blinking works until the process starts, then it stops until the process completes, then it starts again until the code turns it off.

I'm going to keep playing with it, but now I'm much less optimistic that there is actually a way to do it. (I'm surprised that no one has tried this before!!) I thought of putting some sort of counter inside the processes, but that could become a nightmare. Is there any way to make the timer have priority over other processes?
I've never used a ProgressBar, but does it update during processes, or only after each process in a sequence? I'll give it a try.

Any other suggestions?

Thanks again.
CalScot
User avatar
CalScot
Posts: 303
Joined: Thu Mar 21, 2013 12:22 am
Location: California

Re: Enable/Disable a Main Menu

Post by CalScot »

Hi, Serge.

Our messages crossed! As I mentioned, I will definitely give the ProgressBar a try. (And will probably have more questions about that - apologies in advance!)

Thanks, yet again, for your help.
CalScot.
Post Reply