Page 1 of 4

Enable/Disable a Main Menu

Posted: Wed Nov 20, 2013 9:46 am
by CalScot
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

Re: Enable/Disable a Main Menu

Posted: Wed Nov 20, 2013 10:04 am
by esgici
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

Re: Enable/Disable a Main Menu

Posted: Wed Nov 20, 2013 1:17 pm
by srvet_claudio
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

Re: Enable/Disable a Main Menu

Posted: Wed Nov 20, 2013 3:30 pm
by Rathinagiri
Very nice Claudio. :)

Re: Enable/Disable a Main Menu

Posted: Wed Nov 20, 2013 6:28 pm
by Pablo César
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 ?

Re: Enable/Disable a Main Menu

Posted: Wed Nov 20, 2013 11:43 pm
by srvet_claudio
Pablo César wrote:Whith this your new function, is it possible to create a _DeleteMenuItem at runtime ?
Maybe, I will study the issue.

Re: Enable/Disable a Main Menu

Posted: Thu Nov 21, 2013 1:52 am
by CalScot
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

Enable/Disable a Main Menu

Posted: Thu Nov 21, 2013 11:03 am
by Pablo César
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...

Re: Enable/Disable a Main Menu

Posted: Tue Nov 26, 2013 3:46 am
by CalScot
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

Re: Enable/Disable a Main Menu

Posted: Tue Nov 26, 2013 5:12 am
by andyglezl
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