Hide

SftTree/DLL 7.5 - Tree Control

Display
Print

KeyHandling

Defines keystrokes intercepted during cell editing.

C

void WINAPI SftTree_GetKeyHandling(HWND hwndCtl, BYTE* lpVirtKeyIntercept,
      TCHAR* virtKey, BYTE* virtMask);
void WINAPI SftTree_SetKeyHandling(HWND hwndCtl, const BYTE* lpVirtKeyIntercept);
void WINAPI SftTreeSplit_GetKeyHandling(HWND hwndCtl, BYTE* lpVirtKeyIntercept,
      TCHAR* virtKey, BYTE* virtMask);
void WINAPI SftTreeSplit_SetKeyHandling(HWND hwndCtl, const BYTE* lpVirtKeyIntercept);

C++

void CSftTree::GetKeyHandling(BYTE* lpVirtKeyIntercept,
      TCHAR* virtKey, BYTE* virtMask) const;
void CSftTree::SetKeyHandling(const BYTE* lpVirtKeyIntercept);
void CSftTreeSplit::GetKeyHandling(BYTE* lpVirtKeyIntercept,
      TCHAR* virtKey, BYTE* virtMask) const;
void CSftTreeSplit::SetKeyHandling(const BYTE* lpVirtKeyIntercept);

Parameters

hwndCtl

The window handle of the tree control.

lpVirtKeyIntercept

The address of a 256 byte storage area (the keystroke table).

GetKeyHandling updates the area at the specified address with a copy of the currently defined keystroke table. This parameter may be NULL.

SetKeyHandling uses the area at the specified address and copies it to its keystroke table, making the new table the currently defined keystroke table. This parameter may be NULL, in which case the currently defined keystroke table is cleared.

virtKey

Returns the last intercepted keystroke. GetKeyHandling returns a valid virtKey value only while a SFTTREEN_KEYINTERCEPTED notification is being processed. This parameter may be NULL.

virtMask

Returns the last intercepted keystroke attribute. GetKeyHandling returns a valid virtMask value only while a SFTTREEN_KEYINTERCEPTED notification is being processed. This parameter may be NULL.

SFTTREE_HANDLEPUREThe keystroke was intercepted and was used without the Control and without the Shift key.
SFTTREE_HANDLECTRLThe keystroke was intercepted and occurred in combination with the Control key. This value can occur in combination with the SFTTREE_HANDLESHIFT value.
SFTTREE_HANDLESHIFTThe keystroke was intercepted and occurred in combination with the Shift key. This value can occur in combination with the SFTTREE_HANDLECTRL value.

Comments

The GetKeyHandling and SetKeyHandling functions define keystrokes intercepted during cell editing.

To simplify handling of special keystrokes such as Escape, Return, arrow keys, which are normally handled by a child window during cell editing, these can be intercepted by the application using SetKeyHandling. Once a key stroke for a child window is intercepted during cell editing, the SFTTREEN_KEYINTERCEPTED notification occurs. The intercepted key can be retrieved using the GetKeyHandling function. Using SetKeyHandling eliminates the need to subclass the child window, simplifying the implementation of cell editing.

To define intercepted keystrokes, the GetKeyHandling function is used to retrieve the current keystroke table. The keystroke table can then be modified, setting the desired attributes. Finally, the keystroke table is updated by a call to the SetKeyHandling function.

The keystroke table is a 256 byte storage area, one byte for each virtual key code (such as VK_ESCAPE, VK_RETURN, VK_UP, etc.). Each byte contains one or a combination of the following values defining how the virtual key is processed. The virtual key code is used as index into the keystroke table.

SFTTREE_HANDLENONEThe keystroke is not intercepted.
SFTTREE_HANDLEPUREThe keystroke is intercepted if it is used without the Control and without the Shift key.
SFTTREE_HANDLECTRLThe keystroke is intercepted if it is used with the Control key.
SFTTREE_HANDLESHIFTThe keystroke is intercepted if it is used with the Shift key.

Any keystroke that is intercepted during cell editing generates a SFTTREEN_KEYINTERCEPTED notification, to be handled by the application.

Examples

C

        SetFocus(m_hwndCombo);                /* Set input focus to the control */
        SendMessage(m_hwndCombo, CB_SHOWDROPDOWN, TRUE, 0);
    }

    // The following has been added to support key handling while cell editing
    // It is used to define keys to be intercepted
    {
        BYTE KeyTable[256];
        SftTree_GetKeyHandling(g_hwndTree, KeyTable, NULL, NULL);
        KeyTable[VK_TAB] = (SFTTREE_HANDLEPURE|SFTTREE_HANDLESHIFT|SFTTREE_HANDLECTRL);// handle Tab key
        KeyTable[VK_RETURN] = (SFTTREE_HANDLEPURE|SFTTREE_HANDLESHIFT|SFTTREE_HANDLECTRL);// handle Return key
        KeyTable[VK_HOME] = (SFTTREE_HANDLECTRL);// handle Control+Home key
        KeyTable[VK_END] = (SFTTREE_HANDLECTRL);// handle Control+End key
        if (m_hwndCombo) {
            KeyTable[VK_UP] = 0;                // don't handle Up arrow key
            KeyTable[VK_DOWN] = 0;              // don't handle Down arrow key

C++

        m_pCombo->SetFocus();                /* Set input focus to the control */
        m_pCombo->ShowDropDown();
    }

    // The following has been added to support key handling while cell editing
    // It is used to define keys to be intercepted
    {
        BYTE KeyTable[256];
        m_Tree.GetKeyHandling(KeyTable, NULL, NULL);
        KeyTable[VK_TAB] = (SFTTREE_HANDLEPURE|SFTTREE_HANDLESHIFT|SFTTREE_HANDLECTRL);// handle Tab key
        KeyTable[VK_RETURN] = (SFTTREE_HANDLEPURE|SFTTREE_HANDLESHIFT|SFTTREE_HANDLECTRL);// handle Return key
        KeyTable[VK_HOME] = (SFTTREE_HANDLECTRL);// handle Control+Home key
        KeyTable[VK_END] = (SFTTREE_HANDLECTRL);// handle Control+End key
        if (m_pCombo) {
            KeyTable[VK_UP] = 0;                // don't handle Up arrow key
            KeyTable[VK_DOWN] = 0;              // don't handle Down arrow key

See Also C/C++ API | Categories | Notifications