Announcement

Collapse
No announcement yet.

Code click Menu

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

  • Code click Menu

    Somehow, I would like to programmatically Select, Dropdown, Highlight, and Click a menu item in the top of my "Dialog/Window" (Not a "Popup" which I believe is more commonly what happens when you "Right-Click" and a menu "pops-up")

    I could have sworn I asked this before, but searching I may not have, but I did find some similar quests with some interesting ideas including what may be most promising is tracking the "WM_MENUSELECT" and then replicate it (which I figured would be something like
    Code:
    SendMessage HwndMain, %WM_MENUSELECT, mak(dword, lo(word,1), Hi(word,%MF_SYSMENU)), hMenu
    where "1" was my 1st attempt just to see if I could click a menu (anyyyyy menu) item which failed miserably, so I got to go back and read again and figure it out.

    Anyways, I am sure it MUST have been asked and answered before, and I am just not searching the correct terms to find an example.

    Eventually, I would like to write a routine that if running a tutorial, or a demo of the product, that I could actually show where the menu item is located (vs what currently I have to say stuff like "Tools--->Troubleshooting--->I have a problem with _______" instead of showing where the menu item is that could have a tool to solve your problem)

    "Eventually" may be a ways off, but I figure if I can take "Baby Steps" showing the user why something opened rather than just calling the function that opens the tool, it could go a long way towards easing the users experience until the time I can take the time and "Hand-Hold" or "Walk-Thru" each step with each user
    Engineer's Motto: If it aint broke take it apart and fix it

    "If at 1st you don't succeed... call it version 1.0"

    "Half of Programming is coding"....."The other 90% is DEBUGGING"

    "Document my code????" .... "WHYYY??? do you think they call it CODE? "

  • #2
    Take a look at Wink (http://www.debugmode.com/wink/)

    Comment


    • #3
      WM_MENUSELECT is a notification message... it tells you what has happened, it does not make something happen.

      I think what might work is simulating the keystrokes the user would hit to show the various memus and submenus... eg.
      Alt+F ==> shows "File" Menu
      then "M" ==> shows the popop "More" menu

      (Assumes menu is built with accelerators defined , eg "&File" and "&More")

      See Keybd_event function in your WinAPI reference to simulate a keystroke.
      Michael Mattias
      Tal Systems Inc. (retired)
      Racine WI USA
      [email protected]
      http://www.talsystems.com

      Comment


      • #4
        I had not thought about keyboard strokes, but that would mean putting accelerators on all the menu items.

        What I am more thinking is just like when a mouse moves over the top menu, that menu is highlighted. Then if I click a top menu, the menu drops down, and each each highlights as you move over them.

        Pseudo-code
        Code:
             Highlight "Edit"
             Click "Edit" (Edit menu drops down)
             Highlight each item until I reach "Copy"
             Click "Copy" (Edit menu items roll back up out of sight)
        Just as if I had moved the mouse to do it, it would show the same sequence
        Engineer's Motto: If it aint broke take it apart and fix it

        "If at 1st you don't succeed... call it version 1.0"

        "Half of Programming is coding"....."The other 90% is DEBUGGING"

        "Document my code????" .... "WHYYY??? do you think they call it CODE? "

        Comment


        • #5
          So use Alt+F, down arrow, down arrow, <enter> or whatever.

          AFAIK, if you want what happens on keystrokes or mouse clicks to happen, you need either real or simulated keystrokes or mouse clicks.

          FWIW, There is a "mouse_event" API function which can simulate the mouse moving...but I would not want to calculate all those movements in pixels.

          And BTW...
          >but that would mean putting accelerators on all the menu items

          A. You don't already create your menus with Hot keys? How is the "mouse-challenged but really good with the keyboard user" supposed to use your software?

          B. Is it really too much work to change the text from "File" to "&File" ???? That's all you have to do, put the ampersand into the text string!

          MCM
          Michael Mattias
          Tal Systems Inc. (retired)
          Racine WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            Hi Cliff,

            Here is a demo based on "PostMessage %WM_SYSCOMMAND, %SC_KEYMENU",
            thank to Börje Hagsten and Dominic Mitchell.

            Code:
            #COMPILE EXE '#Win 8.04#
            #DIM ALL
            #INCLUDE "Win32Api.inc" '#2005-01-27#
             
            %ButtonTest  = 101
            %ButtonQuit  = 102
            %MenuOpen    = 201
            %MenuExit    = 202
            %MenuOption1 = 203
            %MenuOption2 = 204
            %MenuHelp    = 205
            %MenuAbout   = 206
            %TimerOne    = 301
            '______________________________________________________________________________
             
            CALLBACK FUNCTION DlgProc()
             STATIC NextStep AS LONG
             
             SELECT CASE CBMSG
             
               CASE %WM_COMMAND
                 SELECT CASE LOWRD(CBWPARAM)
             
                   CASE %ButtonTest
                     IF NextStep = 0 THEN
                       SetTimer CBHNDL, %TimerOne, 500, BYVAL %NULL
                       NextStep = 1
                       CONTROL SET TEXT CBHNDL, %ButtonTest, "&Stop"
                     ELSE
                       KillTimer CBHNDL, %TimerOne
                       NextStep = 0
                       CONTROL SET TEXT CBHNDL, %ButtonTest, "&Start"
                     END IF
             
                   CASE %MenuOpen TO %MenuAbout
                    ' MessageBox CBHNDL, BYCOPY "%Menu id" & STR$(CBWPARAM), _
                    '   BYCOPY "Pop menu", %MB_ICONINFORMATION OR %MB_OK
             
                   CASE %ButtonQuit
                     DIALOG END CBHNDL, 0
             
                 END SELECT
             
               CASE %WM_TIMER
                 IF CBWPARAM = %TimerOne THEN
                   IF NextStep >= 1 THEN
                     SELECT CASE NextStep
                       CASE  1 : PostMessage CBHNDL, %WM_SYSCOMMAND, %SC_KEYMENU, %VK_F 'ALT-F
                       CASE  2 : PostMessage CBHNDL, %WM_KEYDOWN, %VK_M, 0              'M key
                       CASE  3 : PostMessage CBHNDL, %WM_KEYDOWN, %VK_DOWN, 0           'Down arrow
                       CASE  4 : PostMessage CBHNDL, %WM_KEYDOWN, %VK_LEFT, 0           'Left arrow
                       CASE  5 : PostMessage CBHNDL, %WM_KEYDOWN, %VK_UP, 0             'Up arrow
                       CASE  6 : PostMessage CBHNDL, %WM_KEYDOWN, %VK_MENU, 0           'A second ALT key to exit menu
                       CASE  7 : PostMessage CBHNDL, %WM_SYSCOMMAND, %SC_KEYMENU, %VK_H 'ALT-H
                       CASE  8 : PostMessage CBHNDL, %WM_KEYDOWN, %VK_DOWN, 0           'Down arrow
                       CASE  9 : PostMessage CBHNDL, %WM_KEYDOWN, %VK_UP, 0             'Up arrow
                       CASE 10 : PostMessage CBHNDL, %WM_KEYDOWN, %VK_DOWN, 0           'Down arrow
                       CASE 11 : PostMessage CBHNDL, %WM_KEYDOWN, %VK_A, 0              'A key
                       CASE 12 : 'Do a half seconds pause
                       CASE ELSE : NextStep = 0
                     END SELECT
                     INCR NextStep
                   END IF
                 END IF
             
               CASE %WM_ENTERSIZEMOVE
                 IF NextStep >= 1 THEN
                   NextStep = -1
                 END IF
             
               CASE %WM_EXITSIZEMOVE
                 IF NextStep = -1 THEN
                   NextStep = 1
                 END IF
             
               CASE %WM_NCACTIVATE
                 IF CBWPARAM THEN 'Application is getting focus
                   IF NextStep = -1 THEN
                     NextStep = 1
                   END IF
                 ELSE 'Application is about to loose focus
                   IF NextStep THEN
                     NextStep = -1
                   END IF
                 END IF
             
               CASE %WM_DESTROY
                 IF NextStep THEN KillTimer CBHNDL, %TimerOne
             
             END SELECT
             
            END FUNCTION
            '______________________________________________________________________________
             
            FUNCTION PBMAIN () AS LONG
             LOCAL hDlg    AS DWORD
             LOCAL hMenu   AS DWORD
             LOCAL hPopup1 AS DWORD
             LOCAL hPopup2 AS DWORD
             LOCAL hPopup3 AS DWORD
             
             MENU NEW BAR TO hMenu
             
             MENU NEW POPUP TO hPopup1
             MENU ADD STRING, hPopup1, "&Open", %MenuOpen, %MF_ENABLED
             MENU ADD STRING, hPopup1, "&Exit", %MenuExit, %MF_ENABLED
             MENU ADD STRING, hPopup1, "-",      0, 0
             MENU ADD POPUP, hMenu, "&File", hPopup1, %MF_ENABLED
             
             MENU NEW POPUP TO hPopup2
             MENU ADD STRING, hPopup2, "Option &1", %MenuOption1, %MF_ENABLED
             MENU ADD STRING, hPopup2, "Option &2", %MenuOption2, %MF_ENABLED
             
             MENU ADD POPUP, hPopup1, "&More Options", hPopup2, %MF_ENABLED
             
             MENU NEW BAR TO hPopup3
             MENU ADD STRING, hPopup3, "&Help", %MenuHelp, %MF_ENABLED
             MENU ADD STRING, hPopup3, "-",      0, 0
             MENU ADD STRING, hPopup3, "&About", %MenuAbout, %MF_ENABLED
             
             MENU ADD POPUP, hMenu, "&Help", hPopup3, %MF_ENABLED
             
             DIALOG NEW %HWND_DESKTOP, "Provoke menu", , ,160, 80, _
               %DS_CENTER OR %WS_SYSMENU OR %WS_MINIMIZEBOX TO hDlg
             
             SetClassLong hDlg, %GCL_HICON, LoadIcon(BYVAL %NULL, BYVAL %IDI_INFORMATION) 'Set a nice icon
             
             MENU ATTACH hMenu, hDlg
             
             CONTROL ADD BUTTON, hDlg, %ButtonTest, "&Start", 110, 8, 40, 14
             CONTROL ADD BUTTON, hDlg, %ButtonQuit, "&Quit", 110, 28, 40, 14, 0
             
             DIALOG SHOW MODAL hDlg, CALL DlgProc
             
            END FUNCTION
            '______________________________________________________________________________
            Last edited by Pierre Bellisle; 14 Nov 2007, 05:28 PM.

            Comment


            • #7
              Thank You Pierre!!!!!!!!!!! :happy:
              Also thax to your posting where you got bits and bites from so thank you to Börje Hagsten and Dominic Mitchell.

              1st 10 second test...does EXACTLY :exactly: what I want to do.
              In the morning I will break it all down but the best lead yet

              MCM...
              The whole reason I was avoiding "Hot Keys" is that only those that are used to the program and how it works, would tend to use "Hot Keys" (and in 99.9% of those cases they would NOT be using my code, but use their own to achieve equal or better results)

              (Although I will be the 1st to admit that depending on the program I fall into that trap as well, and yesterday watched a new user wonder why F1 did not bring up a help file)

              ________________________________________________________________

              Anyways adding in "Hot Keys" is not a bad thing, but I do not want to fall into the trap of ("What I think should be a hot-key, may not be intuitive to the user")
              case in point...if you look at Mozilla Firefox...what would you think "Page S<underline>ource" key would be? (I would think Cntrl-O or Alt-O...but noooo it is Cntrl-U)

              Anyway, I think Pierre's thought is along the side of what I am trying to do. So thank you to you and all who helped you before :wavey:

              I guess my next question after I break things down would be for demo's or tutorials....(who would be for, or who would be against) your mouse pointer "Auto-magically" moving to each item as if you had clicked it yourself?

              (I can see both sides of the argument there, but had to ask)
              Engineer's Motto: If it aint broke take it apart and fix it

              "If at 1st you don't succeed... call it version 1.0"

              "Half of Programming is coding"....."The other 90% is DEBUGGING"

              "Document my code????" .... "WHYYY??? do you think they call it CODE? "

              Comment


              • #8
                if you look at Mozilla Firefox...what would you think "Page S<underline>ource" key would be? (I would think Cntrl-O or Alt-O...but noooo it is Cntrl-U)
                I think you may be confusing additional keyboard accelerators (Ctrl+U above) with the "hot key" used when a menu is already presented (The underlined "S").

                To open a popup ("dropdown") menu, ALT+underlined key works; to select any item on that popup menu all you need to type is the letter itself.

                In this example, Ctrl+U directly selects an item on the popup menu without the need to first show that menu with Alt+(P?)

                Also in this example, Ctrl+U would not exactly be an informative demo... since the viewer would not see you "type" Ctrl+U.

                Unless.. (and wouldn't this be a cool demo?) you showed a little window with a picture of a keyboard, and highlighted the keys being 'pressed'........
                Michael Mattias
                Tal Systems Inc. (retired)
                Racine WI USA
                [email protected]
                http://www.talsystems.com

                Comment


                • #9
                  Here is an alternative.. note that i will wait until a menu is clicked.

                  Code:
                      Local hMenu As Long
                      Local R As RECT    
                      Local hSubMenu As Long
                      
                      hMenu = GetMenu( nCbHndl )
                      hSubMenu = GetSubmenu( hMenu, 1 )
                      
                      HiliteMenuItem( nCbHndl, hMenu, 1, %MF_BYPOSITION Or %MF_HILITE )
                  
                      GetMenuItemRect( nCbHndl, hMenu, 1, R )
                      
                      TrackPopupMenu( hSubMenu, %TPM_LEFTALIGN, R.nLeft, R.nBottom, 0, nCbHndl, ByVal 0& )
                  
                      HiliteMenuItem( nCbHndl, hMenu, 1, %MF_BYPOSITION Or %MF_UNHILITE )
                  Last edited by Edwin Knoppert; 15 Nov 2007, 07:32 AM.
                  hellobasic

                  Comment


                  • #10
                    MCM....Funny you mentioned this
                    Unless.. (and wouldn't this be a cool demo?) you showed a little window with a picture of a keyboard, and highlighted the keys being 'pressed'........
                    cause one example I did do (not relative to the menu's) but the keys to hit for the demo you see the key pressed whether you click the key with the mouse, or press the key on the keyboard

                    I thought it pretty cool even though it did bloat my 32K app to a whopping 782K or so, but did not care since it still fit on a floppy and "A picture is worth a 1000 words" so it was a fair trade-off

                    Maybe I should keep it in for future tutorials since just the user manual is wayyyy bigger than that, its a small price to pay for size for the return on "Showing is doing"
                    Engineer's Motto: If it aint broke take it apart and fix it

                    "If at 1st you don't succeed... call it version 1.0"

                    "Half of Programming is coding"....."The other 90% is DEBUGGING"

                    "Document my code????" .... "WHYYY??? do you think they call it CODE? "

                    Comment


                    • #11
                      "For What It's Worth...."

                      My most recent demo shows menu hot keys in action. Just run the executable: a link is provided with the source code at Add a 'Favorite Files' menu to your application 10-25-07

                      You'll see how you just hit the letter code once the popup menu is shown (I used 'A' thru 'Z' ; and I thought of that all by myself).

                      But I like Edwin's idea of using TrackPopupMenu for this particular application.... the menu will stay in place regardless of external actions until the user does something. 'Regular' popup menus seem to disappear if you move the mouse anywhere.
                      Michael Mattias
                      Tal Systems Inc. (retired)
                      Racine WI USA
                      [email protected]
                      http://www.talsystems.com

                      Comment


                      • #12
                        but the keys to hit for the demo you see the key pressed whether you click the key with the mouse, or press the key on the keyboard...

                        I thought it pretty cool...
                        Maybe I should keep it in for future tutorials ...
                        Or maybe, just maybe, you can express your appreciation to Forum Members for their help on your other challenges by cleaning it up, adding a few comments and posting it in the source code forum for all to use.

                        MCM
                        Michael Mattias
                        Tal Systems Inc. (retired)
                        Racine WI USA
                        [email protected]
                        http://www.talsystems.com

                        Comment


                        • #13
                          Or maybe, just maybe, you can express your appreciation to Forum Members for their help on your other challenges by cleaning it up, adding a few comments and posting it in the source code forum for all to use.
                          Not a bad idea
                          It's not often that I have some small piece that I could contribute. I guess I had not thought of it since its part of a larger application.

                          I noticed on your posted code you had embedded hex for a resource, and thanx to your acknowledgment notes, I tracked down binbas (which I am playing with now since I usually shy away from these types of examples, just because I am too busy at the time I first see them. so this will give me the incentive to "Just Try it")
                          Engineer's Motto: If it aint broke take it apart and fix it

                          "If at 1st you don't succeed... call it version 1.0"

                          "Half of Programming is coding"....."The other 90% is DEBUGGING"

                          "Document my code????" .... "WHYYY??? do you think they call it CODE? "

                          Comment


                          • #14
                            Originally posted by Pierre Bellisle View Post
                            Hi Cliff,

                            Here is a demo based on "PostMessage %WM_SYSCOMMAND, %SC_KEYMENU",
                            Pierre,

                            Just tried your code. It compiles but does not display (JFPro). I've had this before but forget if it's a setting in JFP or it's something in the program itself.

                            ========================================================
                            "It ain't what they call you, it's what you answer to."
                            W. C. Fields
                            ========================================================


                            [quote]
                            It's a pretty day. I hope you enjoy it.

                            Gösta

                            JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
                            LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

                            Comment


                            • #15
                              Originally posted by Edwin Knoppert View Post
                              Here is an alternative.. note that i will wait until a menu is clicked.
                              EXACTLY what I was looking for, Edwin. Thx a load.

                              =============================================
                              "Opportunities multiply as they are seized."
                              Sun Tzu
                              =============================================
                              It's a pretty day. I hope you enjoy it.

                              Gösta

                              JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
                              LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

                              Comment


                              • #16
                                About JFPro,
                                I think you had to remove any remark on the #Compile line...

                                Code:
                                Change
                                #COMPILE EXE '#Win 8.04#
                                 
                                to
                                #COMPILE EXE

                                Comment


                                • #17
                                  Originally posted by Pierre Bellisle View Post
                                  About JFPro,
                                  I think you had to remove any remark on the #Compile line...

                                  Code:
                                  Change
                                  #COMPILE EXE '#Win 8.04#
                                   
                                  to
                                  #COMPILE EXE
                                  Right on, mon frere.

                                  ==============================================
                                  "Sometimes a scream is better than a thesis."
                                  Ralph Waldo Emerson (1803-1882)
                                  ==============================================
                                  It's a pretty day. I hope you enjoy it.

                                  Gösta

                                  JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
                                  LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

                                  Comment

                                  Working...
                                  X