Page 1 of 1

How to prevent quit when ESC in MENU

Posted: Fri May 10, 2019 5:15 am
by alepap
Hi,

Here is a simple menu. I would like to prevent quitting the application when ESC is pressed. Instead, I would like to have the equivalent of ALT-F on the last ESC. Now, the last ESC quits the application.

Thanks,

Alexandre

Code: Select all

#INCLUDE "adsdbe.CH"
#include "AppEvent.ch"
#include "Dmlb.ch"
#include "FileIO.ch"
#INCLUDE "xbp.ch"
#INCLUDE "inkey.CH"
#INCLUDE "dccolor.CH"
#INCLUDE "dcdialog.CH"
#include "Directry.ch"
#include "os.ch"
#include "Dmlb.ch"
#include "DLL.CH"

MEMVAR dCCOLOR
MEMVAR oMainWindow

*******************************************************************************
FUNCTION Main()

   LOCAL Getlist[0], GetOptions, ;
         oMenuBar, oMenuFiles, oMenuConfig, oMenuHelp
         
   PUBLIC pPath := DC_CurPath()
   PUBLIC oMainWindow

   DCMENUBAR oMenuBar

      DCSUBMENU oMenuFiles PROMPT 'Files' PARENT oMenuBar

         DCMENUITEM 'Sales' PARENT oMenuFiles ;
            WHEN {||Empty(oMainWindow:drawingArea:childList())} ;
            ACTION {|o|o:=Thread():new(),o:Start({||sGUI_SAL()})} // TRANSACTIONS: SALES QUOTE ...

         DCMENUITEM 'Customers' PARENT oMenuFiles ;
            WHEN {||Empty(oMainWindow:drawingArea:childList())} ;
            ACTION {|o|o:=Thread():new(),o:Start({||sGUI_CUS()})} // CUSTOMER

         DCMENUITEM 'Quit' PARENT oMenuFiles ;
            ACTION {|o|o:=Thread():new(),o:Start({||sGUI_QUIT()})} // QUIT
            
      DCSUBMENU oMenuConfig PROMPT 'Configuration' PARENT oMenuBar

         DCMENUITEM 'Transaction Date' PARENT oMenuConfig ;
            WHEN {||Empty(oMainWindow:drawingArea:childList())} ;
            ACTION {|o|o:=Thread():new(),o:Start({||sGUI_TRADAT()})} // SET DATE AUTORIZED

         DCMENUITEM 'Currency' PARENT oMenuConfig ;
            WHEN {||Empty(oMainWindow:drawingArea:childList())} ;
            ACTION {|o|o:=Thread():new(),o:Start({||sGUI_CUR()})} // SET ALL CURRENCYS


      DCSUBMENU oMenuHelp PROMPT 'Help' PARENT oMenuBar

         DCMENUITEM 'Manual' PARENT oMenuHelp ;
            WHEN {||Empty(oMainWindow:drawingArea:childList())} ;
            ACTION {|o|o:=Thread():new(),o:Start({||sGUI_MANUAL()})} // 

         DCMENUITEM 'About' PARENT oMenuHelp ;
            WHEN {||Empty(oMainWindow:drawingArea:childList())} ;
            ACTION {|o|o:=Thread():new(),o:Start({||sGUI_ABOUT()})} // 

   DCGETOPTIONS WINDOWWIDTH 1100 WINDOWHEIGHT 650 ;

   DCREAD GUI TITLE 'SEGOVI' PARENT @oMainWindow  ;
      OPTIONS GetOptions ;
      EVAL {|o|o:setFrameState(XBPDLG_FRAMESTAT_MAXIMIZED)}


RETURN nil
********************************************************************************
PROC appsys ; RETURN
********************************************************************************
FUNCTION SalesReport()

  DCMSGBOX 'In Sales Report'

RETURN nil
********************************************************************************
FUNCTION sGUI_SAL()

RETURN nil
********************************************************************************
FUNCTION sGUI_CUS()

RETURN nil
********************************************************************************
FUNCTION sGUI_QUIT()

   QUIT

RETURN nil
********************************************************************************
FUNCTION sGUI_TRADAT ; RETURN nil 
FUNCTION sGUI_CUR() ; RETURN nil 

FUNCTION sGUI_MANUAL() ; RETURN nil 
FUNCTION sGUI_ABOUT() ; RETURN nil 


Re: How to prevent quit when ESC in MENU

Posted: Fri May 10, 2019 5:27 am
by Tom

Code: Select all

DCGETOPTIONS ... NOESCAPEKEY
Edit:

Change this:

Code: Select all

 DCMENUITEM 'Quit' PARENT oMenuFiles ;
            ACTION {|o|o:=Thread():new(),o:Start({||sGUI_QUIT()})} // QUIT
to this:

Code: Select all

 DCMENUITEM 'Quit' PARENT oMenuFiles ;
            ACTION {||sGUI_QUIT()} ACCELKEY xbeK_ALT_F // QUIT
There's no need to start a thread for quitting the app.

Re: How to prevent quit when ESC in MENU

Posted: Fri May 10, 2019 5:35 am
by alepap
Thank you Tom.

Re: How to prevent quit when ESC in MENU

Posted: Fri May 10, 2019 5:49 am
by alepap
NOESCAPEKEY works fine. It will not quit the application.

Is it possible to show the File menu if ESC is pressed in this context.

step1
the menu is showing the submenu config.
User hits ESC.

step2
the menu show File Config Help (the menubar only)
User hits ESC

step3
At this point only the MENUBAR is showed.
On ESC, I want to show the submenu File

Thank you,


Alexandre

Re: How to prevent quit when ESC in MENU

Posted: Fri May 10, 2019 6:14 am
by rdonnay
There is very little control you have over the menu system in Windows.

Almost every Xbase++ class accepts the posting of an event, except XbpMenu and XbpMenuBar.

Windows requires that the user press and release the ALT key, then press the ENTER key.

Re: How to prevent quit when ESC in MENU

Posted: Fri May 10, 2019 7:50 am
by alepap
Ok, very well, I will get use to it. The main problem was the ESC that quits.
Perfect!

Choo choo !!!