Deactivation of main or context menu

Moderator: Rathinagiri

User avatar
mol
Posts: 3718
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Deactivation of main or context menu

Post by mol »

When you activate main or context menu (by hotkey :lol: (I like hotkey lastdays :lol: )), there is no way to dewactivate it eg. by pressing ESCAPE. It's annoying in my opinion, because when I'm working with keyboard, I need to use mouse to click in any other place on the screen.
User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Re: Deactivation of main or context menu

Post by Roberto Lopez »

mol wrote:When you activate main or context menu (by hotkey :lol: (I like hotkey lastdays :lol: )), there is no way to dewactivate it eg. by pressing ESCAPE. It's annoying in my opinion, because when I'm working with keyboard, I need to use mouse to click in any other place on the screen.
I've just come out from bed and don't took my morning coffee yet...but... What do you exactly mean with 'activate a menu via a hotkey'?
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
mol
Posts: 3718
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: Deactivation of main or context menu

Post by mol »

Simply, I define main menu with positions:
FILE
TOOLS
HELP....

When I presss Alt-F - main menu is activated.
But, there is no way to deactivate it by keyboard, when no action from menu is needed.
User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Re: Deactivation of main or context menu

Post by Roberto Lopez »

mol wrote:Simply, I define main menu with positions:
FILE
TOOLS
HELP....

When I presss Alt-F - main menu is activated.
But, there is no way to deactivate it by keyboard, when no action from menu is needed.
Ok. I'll check it, but, anyway, IMHO this is not a bug... maybe a missing feature, but not a bug...

I'll add to wish list...
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Re: Deactivation of main or context menu

Post by Roberto Lopez »

mol wrote:I didn't know, where to place it....
Anyway... could be you so kind to post a sample?

TIA.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
mol
Posts: 3718
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: Deactivation of main or context menu

Post by mol »

I've prepared sample.
Please, open second window by button.

then press Alt-F (top menu of second window will be activated)
then try to press ESC

Code: Select all

#include <hmg.ch>

Function Main

	DEFINE WINDOW Main ;
		AT 0,0 ;
		WIDTH 550 ;
		HEIGHT 350 ;
		TITLE 'Menu Test' ;
		MAIN 
		 DEFINE MAIN MENU
				DEFINE POPUP "File"
					MENUITEM "exit" ACTION Main.Release
				END POPUP
				DEFINE POPUP "Help"
					MENUITEM "About..." ACTION MsgInfo("Test of Main Menu")
					MENUITEM "About HMG" ACTION MsgBox(HmgVersion())
				END POPUP
			END MENU

		@ 80,160 BUTTON Button_1 ;
			CAPTION "Press to activate second window" ;
			ACTION SecondWindow() ;
			WIDTH  200 ;
			HEIGHT 60 
    END WINDOW

		On KEY ESCAPE OF Main Action {|| msgBox("Ending program"), Main.Release}
        Main.Center
        Main.Activate
Return
*-----------------------------------------

function SecondWindow
	DEFINE WINDOW Second ;
		AT 200,200 ;
		WIDTH 550 ;
		HEIGHT 350 ;
		TITLE 'Menu Test' ;
		MODAL

		DEFINE MAIN MENU
			DEFINE POPUP "File"
				MENUITEM "Close this window" ACTION Second.Release
			END POPUP
			DEFINE POPUP "Help"
				MENUITEM "About..." ACTION MsgInfo("Test of Main Menu")
				MENUITEM "About HMG" ACTION MsgBox(HmgVersion())
			END POPUP
		END MENU

		@ 20,40 LABEL Label_1 WIDTH  260 HEIGHT 20 ;
			VALUE "This is second window" ;
			FONT "Arial" SIZE 14 

		@ 60,40 LABEL Label_2 WIDTH  380 HEIGHT 20 ;
			VALUE "Try to activate main menu pressing Alt-F" ;
			FONT "Arial" SIZE 14 

		@ 100,40 LABEL Label_3 WIDTH  320 HEIGHT 30 ;
			VALUE "Then press ESC key to close it" ;
			FONT "Arial" SIZE 14 

	END WINDOW
	// when you change code to like this:
	// Message is displayed, but releasing window Second is omitted.
	//On Key ESCAPE OF Second Action {|| msgbox("I'm closing second window") , Second.Release}

	On Key ESCAPE OF Second Action Second.Release

	activate window Second
 return
User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Re: Deactivation of main or context menu

Post by Roberto Lopez »

mol wrote:I've prepared sample.
Thanks!
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Re: Deactivation of main or context menu

Post by Roberto Lopez »

Roberto Lopez wrote:
mol wrote:I've prepared sample.
Thanks!
Well...

I've been working with your sample and I've found some interesting things.

At first, I've not fully understood the problem in a first read, so, my prior answer was incorrect.

1. The problem is related with ON KEY ESCAPE command, so, if you do not use it, menus are processing escape key correctly.

2. The problem arises only in non-main windows.

Both, menus and msg* functions, process ESC key automatically.

When you point the fact that only first part of your code block is processed, the true fact is that the MsgBox is capturing the escape key for itself avoiding further processing.

If you exit from MsgBox with <return> you'll see that the block is fully executed.

Taking apart this, and attempting to release the windows without displaying a message, a similar conflict appears to be between menu automatic escape key processing and predefined ON KEY ESCAPE.

I'll continue researching to determine if this behavior is inherited from Windows API or not and (in both cases) if it is 'fixable'.

The fix (if possible) could take a long time for me to make it, so, if someone has additional information that helps on this, please post here!

TIA.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: Deactivation of main or context menu

Post by esgici »

Roberto Lopez wrote: ... if someone has additional information that helps on this, please post here!
Hi

No additional information, only personal thought:

IMHO problem is ON KEY ESCAPE .. command. When this line discarded, everything work well:

- If menu activated by Alt key (or clicked), escape key deactivate it,
- If pressed a letter key after Alt key (or highlighted by mouse) and sub menu open, escape key close sub menu

These are standard OS ( Windows API ) behaviors. And if program set a key for other than standard action, system quit this standard action and obey this command.

I'm not a Win API expert, this is only my humble opinion.

Regards

--

Esgici
Viva INTERNATIONAL HMG :D
Post Reply