Enable/Disable a Main Menu

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

User avatar
CalScot
Posts: 230
Joined: Thu Mar 21, 2013 12:22 am
Location: California
Been thanked: 1 time

Enable/Disable a Main Menu

Post by CalScot » Wed Nov 20, 2013 9:46 am

Until recently, I’ve used only buttons and radio groups to trigger processes within my applications, but now I have an application with a main menu and I’m having two specific problems in trying to get it to behave exactly the way I want:

1. I can disable the menu when a menu item is chosen, as in:

Code: Select all

Main.Item_1_Name.Enabled := .F.
Although this works and the menu item can’t be re-clicked, the menu appearance doesn’t change from black to gray until a subsequent window is activated, which takes some processing time. I’ve tried using a hidden window and Nowait and various other dummy processes, but I can’t seem to find a way to make it go instantly gray without disrupting other parts of the application.

2. When the process triggered by the menu is complete and an action is taken, I reverse the process, as in:

Code: Select all

Main.Item_1_Name.Enabled := .T.
Again, this works, but the menu items remain gray until I hover over them, rather than instantly changing back to black. I’ve tried various forms of SetFocus, Recall, Restore, etc., but I just can’t seem to find anything that works.

Both of these problems are cosmetic, but I would really appreciate it if someone can point me in the right direction.

I’m using HMG 3.1.5 (but same result w/ 3.1.1 and 3.1.3) and XP (SP3)

Thanks.
CalScot

User avatar
esgici
Posts: 4324
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Has thanked: 209 times
Been thanked: 76 times
Contact:

Post by esgici » Wed Nov 20, 2013 10:04 am

Hi Scotty

I hope you will like inspect this ( if didn't see already )

Menu_Dynamic.Demo.rar; one of wonders of our doctor ;)

By the way, IMO your requests not cosmetic, but important necessities :arrow:

Happy HMG :D
Viva INTERNATIONAL HMG :D

User avatar
srvet_claudio
Posts: 1935
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Has thanked: 28 times
Been thanked: 113 times
Contact:

Post by srvet_claudio » Wed Nov 20, 2013 1:17 pm

Hi CalScot.
Try with:

Code: Select all

Function Main
...
   REFRESHMENU (Form_1.HANDLE)
...
Return

#pragma BEGINDUMP
#include <windows.h>
#include "hbapi.h"

HB_FUNC ( REFRESHMENU )
{
   DrawMenuBar((HWND) hb_parnl(1));
}

#pragma ENDDUMP
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com

User avatar
Rathinagiri
Posts: 5149
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 124 times
Been thanked: 126 times
Contact:

Post by Rathinagiri » Wed Nov 20, 2013 3:30 pm

Very nice Claudio. :)
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

User avatar
Pablo César
Posts: 4058
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil
Has thanked: 100 times
Been thanked: 176 times

Post by Pablo César » Wed Nov 20, 2013 6:28 pm

srvet_claudio wrote:

Code: Select all

Function Main
...
   REFRESHMENU (Form_1.HANDLE)
...
Return

#pragma BEGINDUMP
#include <windows.h>
#include "hbapi.h"

HB_FUNC ( REFRESHMENU )
{
   DrawMenuBar((HWND) hb_parnl(1));
}

#pragma ENDDUMP
Hi Claudio, thanks for this new function I guess is usefull too.

There are functions:
  • _EnableMenuItem
    _DisableMenuItem
    _DefineSeparator
    _CheckMenuItem
    _UncheckMenuItem
Whith this your new function, is it possible to create a _DeleteMenuItem at runtime ?
I guess would be nice when have to change user/login with different acces of menu and wish do not show some special items at MENU. Is it possible ?
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein

User avatar
srvet_claudio
Posts: 1935
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Has thanked: 28 times
Been thanked: 113 times
Contact:

Post by srvet_claudio » Wed Nov 20, 2013 11:43 pm

Pablo César wrote:Whith this your new function, is it possible to create a _DeleteMenuItem at runtime ?
Maybe, I will study the issue.
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com

User avatar
CalScot
Posts: 230
Joined: Thu Mar 21, 2013 12:22 am
Location: California
Been thanked: 1 time

Post by CalScot » Thu Nov 21, 2013 1:52 am

Thank you, everyone, for your help.

I'm still working through it, more than a little confused and trying to understand what's happening and why, but here's an update:

I downloaded MENU_Dynamic_Demo.rar and hmg.3.1.1_patch2.rar, ran the dynamic menu under 3.1.5, and it worked perfectly - thank you.

I applied the patch to 3.1.1 and changed [ CSMain.Item_1_Name.Enabled := .F. ] to [ Release Main Menu Of CSMain ]. It certainly releases the menu (it disappears completely!), but, for now, it also kills the entire application (without any window, warning or text) when the subsequent window's "Done" button is clicked.

Also, I've tried implementing the #Pragma code, but am having trouble getting it to compile. I keep getting:
Error E0030 Syntax error "syntax error at '.'
from the line
REFRESHMENU (CSMain.Handle)

Another long evening ahead, I think! But it's all part of the learning process, right?)

Thanks again.
CalScot

User avatar
Pablo César
Posts: 4058
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil
Has thanked: 100 times
Been thanked: 176 times

Post by Pablo César » Thu Nov 21, 2013 11:03 am

CalScot wrote:I downloaded MENU_Dynamic_Demo.rar and hmg.3.1.1_patch2.rar ..//..

I applied the patch to 3.1.1 and changed [ CSMain.Item_1_Name.Enabled := .F. ] to [ Release Main Menu Of CSMain ]. It certainly releases the menu (it disappears completely!), but, for now, it also kills the entire application (without any window, warning or text) when the subsequent window's "Done" button is clicked.
Hi CalScot, I think you couldn't make this path on HMG 3.1.5 version. That path IMO is for 3.1.1 version. Probably this is causing the error...
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein

User avatar
CalScot
Posts: 230
Joined: Thu Mar 21, 2013 12:22 am
Location: California
Been thanked: 1 time

Post by CalScot » Tue Nov 26, 2013 3:46 am

I’ve spent the last few days driving myself crazy, trying – unsuccessfully - to resolve the menu problem I had, so I’ve set that aside for now and have gone back to a menu made of Buttons and RadioGroups, which works just fine. Thanks, though, for all the suggestions – they gave me a lot of things to try, and I will try again in the future (when my brain has recovered!).

But now I have another problem, to which I have a working solution, but I think that there must be a better way:

I have a window that displays while multiple (lengthy) steps take place in the background, and I want to update the window as each step is completed.
The window after the final step will show five rows of two labels that say “Processing step 1…” then “Done” (or a numeric result for the step), and “Processing step 2…” then “Done”, and so on.
But, after the window is activated and in a wait state, it won’t allow automatic updates. I’ve solved this by having five windows that are exactly the same, which superimpose on each other, with Window1 showing just “Processing step 1…” and with an OnInit function that triggers step 1, which ends by activating Window2, which adds “Done” to step 1 and “Processing step 2…”. This is repeated until all steps are completed. The final window has a button that waits for user input.

I tried using just a single window, and setting Visible off and on, and releasing and activating the same window, but this produced flicker and some other issues which I’d like to avoid.

As I said, the process described above works, but it’s a lot of code and windows for something for which I think there must be a much simpler way. Any/all suggestions welcomed!

Thanks,
CalScot

User avatar
andyglezl
Posts: 835
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Has thanked: 7 times
Been thanked: 20 times
Contact:

Post by andyglezl » Tue Nov 26, 2013 5:12 am

Hola CalScot

Quiza esto te pudiera servir...
-------------------------------------------
Hello CalScot

Maybe this could serve you ...

Code: Select all

#include "hmg.ch" 

FUNCTION MAIN()

    DEFINE WINDOW Win1 AT 0 , 0 WIDTH 500 HEIGHT 500 TITLE "Show Status" MAIN ON INIT VariosProcs()
		   @ 070 , 070 LABEL LB_Status VALUE "Status..." WIDTH 200 HEIGHT 20 FONT 'Verdana' SIZE 12 FONTCOLOR WHITE BACKCOLOR BLACK BOLD
		   
	END WINDOW
	CENTER WINDOW Win1
    ACTIVATE WINDOW Win1
RETURN Nil
FUNCTION VariosProcs()
	Proc(1)
	INKEY(5)
	Proc(2)
	INKEY(5)
	Proc(3)
	INKEY(5)
	Proc(4)
	INKEY(5)
	Win1.LB_Status.Value:="End..."
	PlayOk()
RETURN
FUNCTION Proc( nProc )

IF nProc=1
	Win1.LB_Status.Value:="Running Proc. 1"
ELSEIF nProc=2
	Win1.LB_Status.Value:="Running Proc. 2"
ELSEIF nProc=3
	Win1.LB_Status.Value:="Running Proc. 3"
ELSE
	Win1.LB_Status.Value:="Running Proc. 4"
ENDIF

RETURN
Andrés González López
Desde Guadalajara, Jalisco. México.

Post Reply