Announcement

Collapse
No announcement yet.

Navigation buttons on Mouse

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

  • Navigation buttons on Mouse

    Hi,

    Could someone please point me in the right direction on the subject?

    I have an application built similar to a web-browser and would like to add the ability to navigate Back and Forward in the history using the mouse buttons (button #4 and #5 I guess).

    Thanks in advance.

    /Tonny

  • #2
    WM_XBUTTON[DOWN|UP]

    The WM_XBUTTONDOWN message is posted when the user presses the first or second X button while the cursor is in the client area of a window. If the mouse is not captured, the message is posted to the window beneath the cursor. Otherwise, the message is posted to the window that has captured the mouse
    ???
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Thanks Michael,

      My first wake testing doesn't look promissing - but kick me in the right direction:

      Mouse Back and Forward Buttons

      Some Microsoft mouse devices have five buttons. The fourth and fifth buttons typically navigate back and forward in Web browsers such as Internet Explorer. These buttons are referred to as X buttons and are supported natively in Windows 2000, Windows Millennium Edition, and Windows XP.

      Six new messages have been added for these mouse buttons: WM_XBUTTONDBCLK, WM_XBUTTONDOWN, WM_XBUTTONUP, WM_NCXBUTTONDBCLK, WM_NCXBUTTONDOWN, and WM_NCXBUTTONUP. The messages are similar to those provided for the first three mouse buttons, the main difference being that the high-order WORD of wParam specifies which button the message refers to.

      When an X button is pressed, an X button message is first generated and a corresponding Back or Forward WM_APPCOMMAND message is later sent to the application. Therefore, if an application implements Back and Forward functionality, it is recommended that the WM_APPCOMMAND message be handled rather than the X button messages. This will allow Back and Forward functionality from mouse, keyboard, and other devices.

      If an application uses the X buttons for a mouse-related action, such as activating a tool or menu in a CAD program, the X button messages should be handled directly.

      An application may have to listen both to X button messages and WM_APPCOMMAND messages to achieve the desired behavior. For example, the X buttons may activate a tool, and the Back and Forward hot keys on a Microsoft keyboard may navigate the view like a Web browser.


      /Tonny

      Comment


      • #4
        http://msdn2.microsoft.com/en-us/library/ms646275.aspx

        (WM_APPCOMMAND notification).
        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          Originally posted by Michael Mattias View Post
          Yes, I have read that one as well. But can't make it work.

          Late last night I made a Mouse Hook and checked WM_XBUTTONDOWN.
          I got it working in that sense I could see (actually hear -> BEEP) the buttons be pressed. But checking the Hiword of wParam to identify which XBUTTON was being pressed - turned out to be quite a task??! I never got it working (maybe because it was 3 in the morning).

          Any input will be appreciated

          Regards,
          Tonny

          Comment


          • #6
            >Yes, I have read that one as well. But can't make it work.

            Show failing code.

            But just as comments:

            1. Get rid of the hook and just process WM_APPCOMMAND.

            2. HIWRD(wParam) does not identify which button was pressed. You need to use the GET_APPCOMMAND_LAPARM and the other two macros documented on the linked page to know exactly which event has occurred.
            Michael Mattias
            Tal Systems (retired)
            Port Washington WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #7
              You need to use the GET_APPCOMMAND_LAPARM and the other two macros documented on the linked page to know exactly which event has occurred.
              Hmmm... the reason why I dropped processing %WM_APPCOMMAND were simply because I can't find the GET_APPCOMMAND_LAPARM macro in any of the API include files. That is why I tried the mouse hook.

              Regards,
              Tonny

              Comment


              • #8
                Hey Tonny,

                Try the following...

                Code:
                #COMPILE EXE '#Win 8.04#
                #DIM ALL
                #INCLUDE "Win32Api.inc" '#2005-01-27#
                 
                %AppCommandCmd     = 101
                %AppCommandDevice  = 102
                %AppCommandKey     = 103
                 
                MACRO GET_APPCOMMAND_LPARAM = (HI(WORD, CBLPARAM) AND &h0FFF)
                MACRO GET_DEVICE_LPARAM     = (HI(WORD, CBLPARAM) AND &hF000) 'See %FAPPCOMMAND_MASK
                MACRO GET_KEYSTATE_LPARAM   =  LO(WORD, CBLPARAM)
                '______________________________________________________________________________
                 
                CALLBACK FUNCTION PBMainCallBack
                 LOCAL sBuffer   AS STRING
                 LOCAL cmd       AS WORD
                 LOCAL uDevice   AS WORD
                 LOCAL dwKeys    AS WORD
                 
                 SELECT CASE CBMSG
                 
                   CASE %WM_APPCOMMAND
                     'CBWPARAM = handle to window (DWORD)
                     'CBLPARAM = command, device, and virtual keys
                     '  cmd     = GET_APPCOMMAND_LPARAM(lParam)     MACRO (HI(WORD, CBLPARAM) AND &h0FFF)
                     '  uDevice = GET_DEVICE_LPARAM(lParam)         MACRO (HI(WORD, CBLPARAM) AND &hF000) 'See %FAPPCOMMAND_MASK
                     '  dwKeys  = GET_KEYSTATE_LPARAM(lParam)       MACRO  LO(WORD, CBLPARAM)
                 
                     'Identify witch command
                     Cmd = GET_APPCOMMAND_LPARAM 'Macro
                     SELECT CASE Cmd
                       CASE %APPCOMMAND_BROWSER_BACKWARD                  : sBuffer = "APPCOMMAND_BROWSER_BACKWARD"
                       CASE %APPCOMMAND_BROWSER_FORWARD                   : sBuffer = "APPCOMMAND_BROWSER_FORWARD"
                       CASE %APPCOMMAND_BROWSER_REFRESH                   : sBuffer = "APPCOMMAND_BROWSER_REFRESH"
                       CASE %APPCOMMAND_BROWSER_STOP                      : sBuffer = "APPCOMMAND_BROWSER_STOP"
                       CASE %APPCOMMAND_BROWSER_SEARCH                    : sBuffer = "APPCOMMAND_BROWSER_SEARCH"
                       CASE %APPCOMMAND_BROWSER_FAVORITES                 : sBuffer = "APPCOMMAND_BROWSER_FAVORITES"
                       CASE %APPCOMMAND_BROWSER_HOME                      : sBuffer = "APPCOMMAND_BROWSER_HOME"
                       CASE %APPCOMMAND_VOLUME_MUTE                       : sBuffer = "APPCOMMAND_VOLUME_MUTE"
                       CASE %APPCOMMAND_VOLUME_DOWN                       : sBuffer = "APPCOMMAND_VOLUME_DOWN"
                       CASE %APPCOMMAND_VOLUME_UP                         : sBuffer = "APPCOMMAND_VOLUME_UP"
                       CASE %APPCOMMAND_MEDIA_NEXTTRACK                   : sBuffer = "APPCOMMAND_MEDIA_NEXTTRACK"
                       CASE %APPCOMMAND_MEDIA_PREVIOUSTRACK               : sBuffer = "APPCOMMAND_MEDIA_PREVIOUSTRACK"
                       CASE %APPCOMMAND_MEDIA_STOP                        : sBuffer = "APPCOMMAND_MEDIA_STOP"
                       CASE %APPCOMMAND_MEDIA_PLAY_PAUSE                  : sBuffer = "APPCOMMAND_MEDIA_PLAY_PAUSE"
                       CASE %APPCOMMAND_LAUNCH_MAIL                       : sBuffer = "APPCOMMAND_LAUNCH_MAIL"
                       CASE %APPCOMMAND_LAUNCH_MEDIA_SELECT               : sBuffer = "APPCOMMAND_LAUNCH_MEDIA_SELECT"
                       CASE %APPCOMMAND_LAUNCH_APP1                       : sBuffer = "APPCOMMAND_LAUNCH_APP1"
                       CASE %APPCOMMAND_LAUNCH_APP2                       : sBuffer = "APPCOMMAND_LAUNCH_APP2"
                       CASE %APPCOMMAND_BASS_DOWN                         : sBuffer = "APPCOMMAND_BASS_DOWN"
                       CASE %APPCOMMAND_BASS_BOOST                        : sBuffer = "APPCOMMAND_BASS_BOOST"
                       CASE %APPCOMMAND_BASS_UP                           : sBuffer = "APPCOMMAND_BASS_UP"
                       CASE %APPCOMMAND_TREBLE_DOWN                       : sBuffer = "APPCOMMAND_TREBLE_DOWN"
                       CASE %APPCOMMAND_TREBLE_UP                         : sBuffer = "APPCOMMAND_TREBLE_UP"
                       CASE %APPCOMMAND_MICROPHONE_VOLUME_MUTE            : sBuffer = "APPCOMMAND_MICROPHONE_VOLUME_MUTE"
                       CASE %APPCOMMAND_MICROPHONE_VOLUME_DOWN            : sBuffer = "APPCOMMAND_MICROPHONE_VOLUME_DOWN"
                       CASE %APPCOMMAND_MICROPHONE_VOLUME_UP              : sBuffer = "APPCOMMAND_MICROPHONE_VOLUME_UP"
                       CASE %APPCOMMAND_HELP                              : sBuffer = "APPCOMMAND_HELP"
                       CASE %APPCOMMAND_FIND                              : sBuffer = "APPCOMMAND_FIND"
                       CASE %APPCOMMAND_NEW                               : sBuffer = "APPCOMMAND_NEW"
                       CASE %APPCOMMAND_OPEN                              : sBuffer = "APPCOMMAND_OPEN"
                       CASE %APPCOMMAND_CLOSE                             : sBuffer = "APPCOMMAND_CLOSE"
                       CASE %APPCOMMAND_SAVE                              : sBuffer = "APPCOMMAND_SAVE"
                       CASE %APPCOMMAND_PRINT                             : sBuffer = "APPCOMMAND_PRINT"
                       CASE %APPCOMMAND_UNDO                              : sBuffer = "APPCOMMAND_UNDO"
                       CASE %APPCOMMAND_REDO                              : sBuffer = "APPCOMMAND_REDO"
                       CASE %APPCOMMAND_COPY                              : sBuffer = "APPCOMMAND_COPY"
                       CASE %APPCOMMAND_CUT                               : sBuffer = "APPCOMMAND_CUT"
                       CASE %APPCOMMAND_PASTE                             : sBuffer = "APPCOMMAND_PASTE"
                       CASE %APPCOMMAND_REPLY_TO_MAIL                     : sBuffer = "APPCOMMAND_REPLY_TO_MAIL"
                       CASE %APPCOMMAND_FORWARD_MAIL                      : sBuffer = "APPCOMMAND_FORWARD_MAIL"
                       CASE %APPCOMMAND_SEND_MAIL                         : sBuffer = "APPCOMMAND_SEND_MAIL"
                       CASE %APPCOMMAND_SPELL_CHECK                       : sBuffer = "APPCOMMAND_SPELL_CHECK"
                       CASE %APPCOMMAND_DICTATE_OR_COMMAND_CONTROL_TOGGLE : sBuffer = "APPCOMMAND_DICTATE_OR_COMMAND_CONTROL_TOGGLE"
                       CASE %APPCOMMAND_MIC_ON_OFF_TOGGLE                 : sBuffer = "APPCOMMAND_MIC_ON_OFF_TOGGLE"
                       CASE %APPCOMMAND_CORRECTION_LIST                   : sBuffer = "APPCOMMAND_CORRECTION_LIST"
                       CASE %APPCOMMAND_MEDIA_PLAY                        : sBuffer = "APPCOMMAND_MEDIA_PLAY"
                       CASE %APPCOMMAND_MEDIA_PAUSE                       : sBuffer = "APPCOMMAND_MEDIA_PAUSE"
                       CASE %APPCOMMAND_MEDIA_RECORD                      : sBuffer = "APPCOMMAND_MEDIA_RECORD"
                       CASE %APPCOMMAND_MEDIA_FAST_FORWARD                : sBuffer = "APPCOMMAND_MEDIA_FAST_FORWARD"
                       CASE %APPCOMMAND_MEDIA_REWIND                      : sBuffer = "APPCOMMAND_MEDIA_REWIND"
                       CASE %APPCOMMAND_MEDIA_CHANNEL_UP                  : sBuffer = "APPCOMMAND_MEDIA_CHANNEL_UP"
                       CASE %APPCOMMAND_MEDIA_CHANNEL_DOWN                : sBuffer = "APPCOMMAND_MEDIA_CHANNEL_DOWN"
                     END SELECT
                     CONTROL SET TEXT CBHNDL, %AppCommandCmd, sBuffer
                 
                     'What device issued the command
                     uDevice = GET_DEVICE_LPARAM 'Macro
                     SELECT CASE uDevice
                       CASE %FAPPCOMMAND_KEY   : sBuffer = "uDevice = Keyboard"
                       CASE %FAPPCOMMAND_MOUSE : sBuffer = "uDevice = Mouse"
                       CASE %FAPPCOMMAND_OEM   : sBuffer = "uDevice = OEM"
                     END SELECT
                     CONTROL SET TEXT CBHNDL, %AppCommandDevice, sBuffer
                 
                     'Was any control keys pressed when command occured
                     dwKeys = GET_KEYSTATE_LPARAM 'Macro
                     sBuffer = ""
                     IF (dwKeys AND %MK_SHIFT)    THEN sBuffer = "Shift, "              'Shift key is down
                     IF (dwKeys AND %MK_CONTROL)  THEN sBuffer = sBuffer & "Ctrl, "     'Ctrl key is down
                     IF (dwKeys AND %MK_LBUTTON)  THEN sBuffer = sBuffer & "Left, "     'Left mouse button is down
                     IF (dwKeys AND %MK_MBUTTON)  THEN sBuffer = sBuffer & "Middle, "   'Middle mouse button is down
                     IF (dwKeys AND %MK_RBUTTON)  THEN sBuffer = sBuffer & "Right, "    'Right mouse button is down
                     IF (dwKeys AND %MK_XBUTTON1) THEN sBuffer = sBuffer & "xButton1, " 'X1 mouse button is down
                     IF (dwKeys AND %MK_XBUTTON2) THEN sBuffer = sBuffer & "xButton2, " 'X2 mouse button is down
                     IF LEN(sBuffer) THEN
                       sBuffer = LEFT$(sBuffer, LEN(sBuffer) - 2) 'Remove last ", "
                     ELSE
                       sBuffer = "Nil"
                     END IF
                     CONTROL SET TEXT CBHNDL, %AppCommandKey, "dwKeys = " & sBuffer
                 
                     'Return %TRUE if key is processed
                     'FUNCTION = %TRUE
                 
                 END SELECT
                 
                END FUNCTION
                '______________________________________________________________________________
                 
                FUNCTION PBMAIN
                 LOCAL hDlg AS DWORD
                 
                 DIALOG NEW %HWND_DESKTOP, "WM_AppCommand", , , 210, 70, %WS_CAPTION OR %WS_MINIMIZEBOX OR %WS_SYSMENU TO hDlg
                 SetClassLong hDlg, %GCL_HICON, LoadIcon(BYVAL %NULL, BYVAL %IDI_INFORMATION) 'Set a nice icon
                 
                 CONTROL ADD LABEL, hDlg, %AppCommandCmd,    "AppCommandCmd:"   & $TAB & "Try ""Volume up"" on keyboard !"  , 10, 15, 200, 13
                 CONTROL ADD LABEL, hDlg, %AppCommandDevice, "AppCommandDevice" & $TAB & "Keyboard, OEM or mouse."          , 10, 30, 200, 13
                 CONTROL ADD LABEL, hDlg, %AppCommandKey,    "AppCommandKey"    & $TAB & "Shift key, control, mouse-button.", 10, 45, 200, 13
                 
                 DIALOG SHOW MODAL hDlg, CALL PBMainCallBack
                 
                END FUNCTION
                '______________________________________________________________________________
                Last edited by Pierre Bellisle; 23 Nov 2007, 10:53 AM.

                Comment


                • #9
                  Originally posted by Pierre Bellisle View Post
                  Hey Tonny,

                  Try the following...

                  Code:
                  MACRO GET_APPCOMMAND_LPARAM = (HI(WORD, CBLPARAM) AND &h0FFF)
                  MACRO GET_DEVICE_LPARAM     = (HI(WORD, CBLPARAM) AND &hF000)
                  MACRO GET_KEYSTATE_LPARAM   =  LO(WORD, CBLPARAM)
                  Thanks a lot Pierre

                  I could have used that input late last night

                  I made this until a more solid way (like yours) came along one way or the other. Not sure it will hold water in the long run - but does the trick:

                  Code:
                      CASE %WM_APPCOMMAND
                      
                        SELECT CASE [B]CBYT(HI(WORD,CBLPARAM))[/B]
                          CASE %APPCOMMAND_BROWSER_FORWARD  : MSGBOX "FORWARD"
                          CASE %APPCOMMAND_BROWSER_BACKWARD : MSGBOX "BACKWARD"
                        END SELECT
                  It handles both the keybord back/forward navigation buttons and the mouse back/forward navigation buttons in the same run.

                  Thanks again both!

                  Regards,
                  Tonny
                  Last edited by Tonny Bjorn; 22 Nov 2007, 03:59 PM.

                  Comment


                  • #10
                    That's a really great little demo program, Pierre. Why don't you post it in the Source Code Forum with a title containing logical search keys, eg. "Mouse Navigation X-Button Demo" or something like that?

                    I know when I look for code, my first search is always "message title, source code forum" and I'm sure that's how many others start.
                    Michael Mattias
                    Tal Systems (retired)
                    Port Washington WI USA
                    [email protected]
                    http://www.talsystems.com

                    Comment


                    • #11
                      Originally posted by Michael Mattias View Post
                      That's a really great little demo program, Pierre. Why don't you post it in the Source Code Forum with a title containing logical search keys, eg. "Mouse Navigation X-Button Demo" or something like that?
                      Pierre, I absolutely agree with Michael on this

                      Thanks again for sharing!

                      Regards,
                      Tonny

                      Comment


                      • #12
                        the reason why I dropped processing %WM_APPCOMMAND were simply because I can't find the GET_APPCOMMAND_LAPARM macro in any of the API include files
                        I think you can get a complete set of header files by downloading the SDK from Microsoft; but IIRC that is many, many (many) megabytes.

                        I downloaded the free Borland 'C' compiler; much, much smaller. That includes all the "windows header files," too. That's where I found these macros.

                        (All I use from that compiler is the "include" directory which gets created at install).
                        Michael Mattias
                        Tal Systems (retired)
                        Port Washington WI USA
                        [email protected]
                        http://www.talsystems.com

                        Comment

                        Working...
                        X