A context menu (or popup menu) is easily implemented with SftBox/DLL. A context menu is typically displayed when the user right-clicks an item or a column header, for example to offer commands for the item or to hide and display columns.
A combo box control consists of several windows, so the WM_CONTEXTMENU message Windows generates for a right-click (or for the Shift+F10 key combination) does not always reach the parent window of the combo box. The combo box sends a notification instead, which describes the portion of the combo box where the context menu was requested. The notification is sent to the parent window as a WM_COMMAND message.
| Mouse | Keyboard | Sent when a context menu is requested |
|---|---|---|
| SFTBOXN_CONTEXTMENU_STATIC | SFTBOXN_CONTEXTMENU_KBD_STATIC | in the static portion of a dropdown list combo box, on the dropdown button or on any other part of the combo box which is not the edit control or the dropdown portion. |
| SFTBOXN_CONTEXTMENU_EDIT | SFTBOXN_CONTEXTMENU_KBD_EDIT | in the edit control portion of a simple or dropdown combo box. |
| SFTBOXN_CONTEXTMENU_DD | SFTBOXN_CONTEXTMENU_KBD_DD | in the dropdown portion. |
The SFTBOXN_CONTEXTMENU_KBD_... notifications are sent when the context menu is requested using the keyboard (the WM_CONTEXTMENU message does not provide a mouse location). The context menu should then be displayed at a suitable location, for example at the selected item (see GetItemRect). The keyboard request is sent for the portion that has the input focus, the edit control portion or the static portion. The dropdown portion never has the input focus.
Before displaying a context menu, an application should always send a WM_CANCELMODE message to the combo box control.
The notification does not provide the mouse location. Use the Windows function GetCursorPos to retrieve the location (in screen coordinates) and display the menu, for example with TrackPopupMenu. To determine what was clicked, convert the location to client coordinates of the combo box and use CalcIndexFromPoint or CalcCellFromPoint, which return the item (and cell) and whether the location is in the static portion or the dropdown portion.
A right-click on an item also sends the mouse click notifications, such as SFTBOXN_RBUTTONDOWN_TEXT or SFTBOXN_RBUTTONDOWN_CELL, before the context menu notification (unless the combo box was created with the SFTBOXSTYLE_LEFTBUTTONONLY window style). For a right-click on the static portion, these notification codes are wrapped using SFTBOXN_MAIN_NOTIFICATION.
The dropdown portion remains shown when a context menu is requested in the dropdown portion.
An edit control has its own popup menu (Undo, Cut, Copy, Paste, etc.). After SFTBOXN_CONTEXTMENU_EDIT or SFTBOXN_CONTEXTMENU_KBD_EDIT has been sent, the edit control displays this menu, unless the application has sent a WM_CANCELMODE message to the combo box while handling the notification. An application which displays its own context menu for the edit control portion must therefore send WM_CANCELMODE, as described above. An application which doesn't handle the notification doesn't have to do anything to offer the standard menu.
In a simple combo box, the dropdown portion is a part of the combo box itself. A context menu requested in the dropdown portion sends SFTBOXN_CONTEXTMENU_DD only, as in the other combo box styles.