User Tools

Site Tools


right-click_20context_20menu

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

right-click_20context_20menu [2018/03/31 13:19]
127.0.0.1 external edit
right-click_20context_20menu [2018/04/16 14:25] (current)
richardrussell Added syntax highlighting
Line 1: Line 1:
 =====Right-click Context Menu===== =====Right-click Context Menu=====
  
-//by Richard Russell, March 2014//\\ \\  When the user right-clicks in a window a WM_CONTEXTMENU message is generated, which may be intercepted using **ON SYS** (so long as a ***SYS 1** command has been issued). On receipt of this message you should typically display a popup menu containing commands relevant to the context, for example if the user right-clicks in an editing pane it would often be appropriate to display the same menu as results from clicking on **Edit** in the menu bar. Typical code to achieve that would be as follows:\\ +//by Richard Russell, March 2014//\\ \\  When the user right-clicks in a window a WM_CONTEXTMENU message is generated, which may be intercepted using **ON SYS** (so long as a ***SYS 1** command has been issued). On receipt of this message you should typically display a popup menu containing commands relevant to the context, for example if the user right-clicks in an editing pane it would often be appropriate to display the same menu as results from clicking on **Edit** in the menu bar. Typical code to achieve that would be as follows: 
 + 
 +<code bb4w>
         X% = (lpar% << 16) >> 16         X% = (lpar% << 16) >> 16
         Y% = lpar% >> 16         Y% = lpar% >> 16
         IF wpar% = hEdit% THEN dummy% = FNtrackpopupmenu(EditMenu%,​ 0, X%, Y%)         IF wpar% = hEdit% THEN dummy% = FNtrackpopupmenu(EditMenu%,​ 0, X%, Y%)
-Here **wpar%** and **lpar%** correspond to the **@wparam%** and **@lparam%** values from the original ON SYS interrupt (typically via an [[http://​bb4w.wikispaces.com/​Queueing+event+interrupts|event queue]]), **hEdit%** is the window handle of the editing pane and **EditMenu%** is the handle of the popup edit menu.\\ \\  The WM_CONTEXTMENU message is also generated when the user presses the **Menu key** (usually to be found to the right of the space bar). If the message is generated by this means, **lpar%**, which normally contains the screen coordinates at which the popup menu should be displayed, instead contains -1. In this case you should use an alternative method of determining the location of the context menu, for example in the case of an editing pane it would be appropriate to display the menu at the position of the caret (text cursor) or current selection:\\ +</​code>​ 
 + 
 +Here **wpar%** and **lpar%** correspond to the **@wparam%** and **@lparam%** values from the original ON SYS interrupt (typically via an [[http://​bb4w.wikispaces.com/​Queueing+event+interrupts|event queue]]), **hEdit%** is the window handle of the editing pane and **EditMenu%** is the handle of the popup edit menu.\\ \\  The WM_CONTEXTMENU message is also generated when the user presses the **Menu key** (usually to be found to the right of the space bar). If the message is generated by this means, **lpar%**, which normally contains the screen coordinates at which the popup menu should be displayed, instead contains -1. In this case you should use an alternative method of determining the location of the context menu, for example in the case of an editing pane it would be appropriate to display the menu at the position of the caret (text cursor) or current selection: 
 + 
 +<code bb4w>
         IF lpar% = -1 THEN         IF lpar% = -1 THEN
           SYS "​SendMessage",​ hEdit%, EM_GETSEL, ^start%, ^finish%           SYS "​SendMessage",​ hEdit%, EM_GETSEL, ^start%, ^finish%
Line 15: Line 21:
         ENDIF         ENDIF
         IF wpar% = hEdit% THEN dummy% = FNtrackpopupmenu(EditMenu%,​ 0, X%, Y%)         IF wpar% = hEdit% THEN dummy% = FNtrackpopupmenu(EditMenu%,​ 0, X%, Y%)
-In the absence of a menu key the keyboard shortcut **Shift+F10** may be used, however in the BB4W 'main window'​ this keypress is intercepted and instead results in the code 170 (&AA) being inserted into the keyboard buffer. If you want Shift+F10 to bring up a context menu you can either respond to that character when it is received by GET or INKEY, or you can create (or add to) a keyboard accelerator in order to translate it to a WM_COMMAND message which can be handled by ON SYS:\\ +</​code>​ 
 + 
 +In the absence of a menu key the keyboard shortcut **Shift+F10** may be used, however in the BB4W 'main window'​ this keypress is intercepted and instead results in the code 170 (&AA) being inserted into the keyboard buffer. If you want Shift+F10 to bring up a context menu you can either respond to that character when it is received by GET or INKEY, or you can create (or add to) a keyboard accelerator in order to translate it to a WM_COMMAND message which can be handled by ON SYS: 
 + 
 +<code bb4w>
         nsc% = 1         nsc% = 1
         DIM accel{(nsc%-1) fVirt&, pad&, key{l&,​h&​},​ cmd{l&,​h&​}}         DIM accel{(nsc%-1) fVirt&, pad&, key{l&,​h&​},​ cmd{l&,​h&​}}
Line 24: Line 34:
         @haccel% = haccel%         @haccel% = haccel%
         @hwacc% = @hwnd%         @hwacc% = @hwnd%
 +</​code>​
 +
 Here **contextID%** is a the command code which will be generated. Here **contextID%** is a the command code which will be generated.
right-click_20context_20menu.txt · Last modified: 2018/04/16 14:25 by richardrussell