Announcement

Collapse
No announcement yet.

Keyboard shortcuts to menu

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Keyboard shortcuts to menu

    Hello everyone,

    Coming from VB6 and using Vista, I had to decide whether I follow the .net line or go for something completely (or not that too) different. So here I am, a new PB owner who is learning-by-doing by porting some applications from VB to PB.

    While the first application was - hmmm- quite easy to code in PB, the second one I try puts me to a problem.

    Here is why:

    I drew a simple dialog and added a menu bar in PBForms 1.51. Then I added some keyboard shortcuts (accellerators) by adding an ampersand to the caption of the top level menu (hpopup1).
    Now, when I test drive the form in PBForms, all seems to work ok.
    But then in PBEdit, while debugging or after compiling, the keyboard shortcuts don't work. All that happens is the appearence of the underscore when pressing [alt]. Mouse-clicks do work, of course.

    I looked through the samples (which work) and another code I found here in this board but could not find any
    significant difference in the seemingly relevant parts.

    Can anyone push me in the right direction?

    Thanks in advance

    Greetings from Switzerland,
    Markus


    -> here's the code in question:


    Code:
    #PBFORMS CREATED V1.51
    '------------------------------------------------------------------------------
    '------------------------------------------------------------------------------
    #COMPILE EXE
    #DIM ALL
    '------------------------------------------------------------------------------
    '   ** Includes **
    '------------------------------------------------------------------------------
    #PBFORMS BEGIN INCLUDES
    #IF NOT %DEF(%WINAPI)
        #INCLUDE "WIN32API.INC"
    #ENDIF
    #PBFORMS END INCLUDES
    '------------------------------------------------------------------------------
    '------------------------------------------------------------------------------
    '   ** Constants **
    '------------------------------------------------------------------------------
    #PBFORMS BEGIN CONSTANTS
    %IDD_DIALOG1          =  101
    %IDR_MENU1            =  102
    %IDM_FILE_NEW         = 1001
    %IDM_OPTIONS_CLOSE    = 1002
    #PBFORMS END CONSTANTS
    '------------------------------------------------------------------------------
    '------------------------------------------------------------------------------
    '   ** Declarations **
    '------------------------------------------------------------------------------
    DECLARE FUNCTION AttachMENU1(BYVAL hDlg AS DWORD) AS DWORD
    DECLARE CALLBACK FUNCTION ShowDIALOG1Proc()
    DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
    #PBFORMS DECLARATIONS
    '------------------------------------------------------------------------------
    '------------------------------------------------------------------------------
    '   ** Main Application Entry Point **
    '------------------------------------------------------------------------------
    FUNCTION PBMAIN()
        ShowDIALOG1 %HWND_DESKTOP
    END FUNCTION
    '------------------------------------------------------------------------------
    '------------------------------------------------------------------------------
    '   ** Menus **
    '------------------------------------------------------------------------------
    FUNCTION AttachMENU1(BYVAL hDlg AS DWORD) AS DWORD
    #PBFORMS BEGIN MENU %IDR_MENU1->%IDD_DIALOG1
        LOCAL hMenu   AS DWORD
        LOCAL hPopUp1 AS DWORD
        LOCAL hPopUp2 AS DWORD
        MENU NEW BAR TO hMenu
        MENU NEW POPUP TO hPopUp1
        MENU ADD POPUP, hMenu, "&File", hPopUp1, %MF_ENABLED
            MENU ADD STRING, hPopUp1, "New", %IDM_FILE_NEW, %MF_ENABLED
        MENU NEW POPUP TO hPopUp1
        MENU ADD POPUP, hMenu, "&Options", hPopUp1, %MF_ENABLED
            MENU ADD STRING, hPopUp1, "Close", %IDM_OPTIONS_CLOSE, _
                %MF_ENABLED
        MENU ATTACH hMenu, hDlg
    #PBFORMS END MENU
        FUNCTION = hMenu
    END FUNCTION
    '------------------------------------------------------------------------------
    '------------------------------------------------------------------------------
    '   ** CallBacks **
    '------------------------------------------------------------------------------
    CALLBACK FUNCTION ShowDIALOG1Proc()
        SELECT CASE AS LONG CBMSG
            CASE %WM_INITDIALOG
                ' Initialization handler
            CASE %WM_NCACTIVATE
                STATIC hWndSaveFocus AS DWORD
                IF ISFALSE CBWPARAM THEN
                    ' Save control focus
                    hWndSaveFocus = GetFocus()
                ELSEIF hWndSaveFocus THEN
                    ' Restore control focus
                    SetFocus(hWndSaveFocus)
                    hWndSaveFocus = 0
                END IF
            CASE %WM_COMMAND
                ' Process control notifications
                SELECT CASE AS LONG CBCTL
                    CASE %IDM_FILE_NEW
                        MSGBOX "%IDM_FILE_NEW=" + FORMAT$(%IDM_FILE_NEW), _
                            %MB_TASKMODAL
                    CASE %IDM_OPTIONS_CLOSE
                        MSGBOX "%IDM_OPTIONS_CLOSE" + _
                            FORMAT$(%IDM_OPTIONS_CLOSE), %MB_TASKMODAL
                END SELECT
        END SELECT
    END FUNCTION
    '------------------------------------------------------------------------------
    '------------------------------------------------------------------------------
    '   ** Dialogs **
    '------------------------------------------------------------------------------
    FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
        LOCAL lRslt AS LONG
    #PBFORMS BEGIN DIALOG %IDD_DIALOG1->%IDR_MENU1->
        LOCAL hDlg  AS DWORD
        DIALOG NEW hParent, "Dialog1", 70, 70, 201, 132, TO hDlg
        AttachMENU1 hDlg
    #PBFORMS END DIALOG
        DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt
    #PBFORMS BEGIN CLEANUP %IDD_DIALOG1
    #PBFORMS END CLEANUP
        FUNCTION = lRslt
    END FUNCTION
    '------------------------------------------------------------------------------
    Last edited by Markus Saegesser; 10 Jul 2008, 02:09 PM.

  • #2
    I haven't figured out why that doesn't work but if this helps at all until we figure it out.

    For your MENU ITEMS (using PBForms menu dialog) when the NEW and the CLOSE are selected you can put hot key in the Accelerator Keys textbox by holding down the shift key and pressing a letter. For example for the MENU ITEM "NEW" hold down shift-press N. Cntl-N will appear in the txtbox and on the menu.

    You can then Press CONTROL-N and activate the NEW option in your compiled program.

    I will look for some of my other to see if the same thing is occurring there, and I just never noticed it.

    Rod
    Rod
    I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

    Comment


    • #3
      Hi Rod,

      This one I already knew (and it works great).

      Thanks anyway - also for looking through your other...

      Markus

      Comment


      • #4
        The keyboard mnemonics will work, if you press alt, release alt, then the hotkey.

        I have seen this behavior before, but only when there are zero controls (enabled) on the dialog.

        If you will add one control, even if it is a label, the problem will go away. If you are wanting a dialog with no visible controls, you can do the following:

        Code:
        CONTROL ADD LABEL, hDlg, -1, "", 0,0,0,0
        Adam Drake
        Drake Software

        Comment


        • #5
          Markus,
          Adam's suggestion is the closest I can see to any solution. All programs that I checked have controls and the Menu works as it should, so does yours when you add a control.
          This doesn't mean I understand why you have to have a control in the dialog.
          Rod
          Last edited by Rodney Hicks; 10 Jul 2008, 11:54 AM. Reason: grammar correction
          Rod
          I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

          Comment


          • #6
            Thank you!!

            Geez, a few hours investigating, testing and code comparing for a non issue.

            Well, for the next time I'll know this.

            (of course there will be other controls on the dialog)


            Thank you both!

            Regards,
            Markus

            Comment


            • #7
              I think I had an issue back a long time ago with the same solution too. I think it concerned the Cancel/Esc action and either I had no controls or didn't have a control defined as cancel and my apps kept beeping on closing them.
              sigpic
              Mobile Solutions
              Sys Analyst and Development

              Comment

              Working...
              X