Announcement

Collapse
No announcement yet.

Detect menu getting the focus

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

  • Ralph Brereton
    replied
    Merci, Pierre. Your code covers many situations. I have retained a copy for future use. Best wishes, Ralph.

    Leave a comment:


  • Ralph Brereton
    replied
    Thank you, Kev Peel. Both of your suggestions worked. WM_MENUSELECT is the easy one because it covers menu selection by keyboard or mouse. I found it interesting that menu selection by keyboard (the ALT key) doesn't require a menu item to be clicked, whereas selection by mouse does. I wonder why?

    Leave a comment:


  • Kev Peel
    replied
    You need to skip the first four bits of the (low-order) wParam value that is supplied with WM_SYSCOMMAND. Try the following instead:

    Code:
    SELECT CASE LoWrd(wParam) And &HFFF0
    Alternatively, the WM_MENUSELECT message may provide an easier method to do what you require. It's good for displaying menu tips in the status bar when a menu item is selected.

    Is it because I'm using a laptop with a touchpad ?
    No. That does not affect how windows passes messages. To applications, (most) mouse/touchpad/touchscreen actions are handled the same way.
    Last edited by Kev Peel; 24 Mar 2008, 04:51 PM.

    Leave a comment:


  • Pierre Bellisle
    replied
    Hi Ralph,

    The following should give you all the control you need...

    Code:
    #COMPILE EXE '#Win 8.04#
    #DIM ALL
    #REGISTER NONE
    #INCLUDE "Win32Api.inc" '#2005-01-27#
     
    GLOBAL hDlg    AS DWORD
    GLOBAL hMenu   AS DWORD
    GLOBAL hPopup1 AS DWORD
    GLOBAL hPopup2 AS DWORD
     
    %Label       = 101
    %MenuOpen    = 401
    %MenuExit    = 402
    %MenuHelp    = 403
    %MenuAbout   = 404
    '______________________________________________________________________________
     
    CALLBACK FUNCTION DlgProc
     LOCAL MousePosition AS POINTAPI
     LOCAL MenuSensor    AS LONG
     
     SELECT CASE CBMSG
     
       CASE %WM_SETCURSOR
          GetCursorPos MousePosition
          MenuSensor = MenuItemFromPoint(CBHNDL, hMenu , MousePosition.x, MousePosition.y)
          IF MenuSensor = -1 THEN
            CONTROL SET TEXT CBHNDL, %Label, "Waiting for menu..."
          ELSE
            CONTROL SET TEXT CBHNDL, %Label, "sMenu " & HEX$(MenuSensor)
          END IF
     
       CASE %WM_INITMENU
         CONTROL SET TEXT CBHNDL, %Label, "iMenu " & HEX$(LO(WORD, CBWPARAM))
     
       CASE %WM_MENUSELECT
         CONTROL SET TEXT CBHNDL, %Label, "mMenu " & HEX$(LO(WORD, CBWPARAM))
     
       CASE %WM_EXITMENULOOP
         CONTROL SET TEXT CBHNDL, %Label, "Waiting for menu..."
     
      END SELECT
     
    END FUNCTION
    '______________________________________________________________________________
     
    FUNCTION PBMAIN()
     
     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 POPUP,  hMenu,   "&File", hPopup1, %MF_ENABLED
     
     MENU NEW POPUP TO hPopup2
     MENU ADD STRING, hPopup2, "&Info", %MenuHelp, %MF_ENABLED
     MENU ADD STRING, hPopup2, "&About", %MenuAbout, %MF_ENABLED
     MENU ADD POPUP,  hMenu,   "&Help", hPopup2, %MF_ENABLED
     
     DIALOG NEW %HWND_DESKTOP, "Menu sensor", , , 200, 100, _
       %WS_CAPTION OR %WS_MINIMIZEBOX OR %WS_SYSMENU, 0 TO hDlg
     
     SetClassLong hDlg, %GCL_HICON, LoadIcon(BYVAL %NULL, BYVAL %IDI_INFORMATION) 'Set a nice dialog icon
     
     CONTROL ADD LABEL, hDlg, %Label, "Waiting for menu, key or mouse...", 70, 35, 125, 20
     
     MENU ATTACH hMenu, hDlg
     
     DIALOG SHOW MODAL hDlg, CALL DlgProc
     
    END FUNCTION
    '______________________________________________________________________________
    '
    Last edited by Pierre Bellisle; 24 Mar 2008, 05:00 PM.

    Leave a comment:


  • Ralph Brereton
    replied
    %SC_KEYMENU and %SC_MOUSEMENU

    I also tried this:
    CASE %WM_SYSCOMMAND
    SELECT CASE CBWPARAM
    CASE %SC_KEYMENU
    MSGBOX "Remove advertising" 'this works
    CASE %SC_MOUSEMENU
    MSGBOX "Remove advertising" 'this doesn't work
    END SELECT

    %SC_KEYMENU detects the user moving to the menu by using the keyboard (ALT). He doesn't have to click on a menu item. It works.

    %SC_MOUSEMENU should detect the user moving to the menu by using the mouse. It doesn't work for me.

    Does anyone know why ?
    Is it because I'm using a laptop with a touchpad ?

    Leave a comment:


  • Ralph Brereton
    replied
    Thank you, Peter. It worked first time. So easy when you know how.

    Leave a comment:


  • Peter Jinks
    replied
    Wm_initmenu

    From MSDN:
    WM_INITMENU Message
    The WM_INITMENU message is sent when a menu is about to become active. It occurs when the user clicks an item on the menu bar or presses a menu key. This allows the application to modify the menu before it is displayed.

    A window receives this message through its WindowProc function.
    Seems what you're after. The article is here.

    Regards,

    Pete.

    Leave a comment:


  • Ralph Brereton
    started a topic Detect menu getting the focus

    Detect menu getting the focus

    The main dialog is displayed with a menu attached.
    There are also some labels on the dialog.
    These contain some advertising.
    I want to kill the labels as soon as the user presses ALT to highlight the menubar.
    I also want to kill the labels if the user uses the mouse to highlight the menubar.
    This means, I think, that I want to kill the labels as soon as the menu bar gets the focus.
    Does anyone know how to detect the menu bar receiving the focus ?

    There is a secondary issue.
    Those labels are a very inelegant way to handle the advertising.
    A graphic, with a picture and some text, would be so much better.
    But we would still have to detect the menu getting the focus.
Working...
X