<< Return to Main Index

< Return to Class Index

CGXGridCore::ProcessKeys

virtual BOOL ProcessKeys(CWnd* pSender, UINT nMessage, UINT nChar, UINT nRepCnt = 1, UINT flags = 0);

pSender

Points to the calling window object. Both the grid window and the active edit-control call this method.

nMessage

Specifies the message. This can be WM_KEYDOWN, WM_CHAR or WM_SYSKEYDOWN.

nChar

Specifies the virtual-key code of the given key.

nRepCnt

Repeat count (the number of times the keystroke is repeated as a result of the user holding down the key).

flags

Specifies the scan code, key-transition code, previous key state, and context code, as shown in CWnd::OnKeyDown.

Return Value

TRUE when the keystroke has been processed; it is FALSE if the keystroke could not be interpreted.

Remarks

Overridable method which interprets keyboard strokes sent either from the edit-control or the grid-window.

The default behavior of the method is:

You can override this method if you want to process keystrokes. Be careful to call the base-class version of this method.

Example

This example illustrates how to override the ProcessKeys-method and process the F1 and TAB keys. If the user presses TAB at the bottom-right cell, a new row will be added to the table.

BOOL CGSampleView::ProcessKeys(CWnd* pSender, UINT nMessage, UINT nChar, UINT nRepCnt, UINT flags)
{
   BOOL bCtl = GetKeyState(VK_CONTROL) & 0x8000;
   BOOL bShift = GetKeyState(VK_SHIFT) & 0x8000;

   if (nMessage == WM_KEYDOWN)
   {
      switch (nChar)
      {
      case VK_HELP:      // F1
         // display a message box with help
         if (bShift)
         {
            MessageBox("Help!");
            return TRUE;
         }
      case VK_TAB:      // Tab-Key
         {
            ROWCOL nRow = 1, nCol = 1;
            GetCurrentCell(nRow, nCol);
            if (!bShift)
            {
               // Jump to the right cell or move down a row,
               // if cell positioned at last cell
               if (nCol < GetColCount( ))
                  MoveCurrentCell(GX_RIGHT);
               else if (nRow < GetRowCount( ))
               {
                  if (MoveCurrentCell(GX_MOSTLEFT))
                     MoveCurrentCell(GX_DOWN);
               }
               else
               {
                  // Add a new row
                  SetRowCount(GetRowCount( )+1);
                  if (MoveCurrentCell(GX_MOSTLEFT))
                     MoveCurrentCell(GX_DOWN);
               }
            }
            else
            {
               // Jump to the left cell or move up a row
               if (nCol > 1)
                  MoveCurrentCell(GX_LEFT);
               else if (nRow > 1)
               {
                  if (MoveCurrentCell(GX_MOSTRIGHT))
                     MoveCurrentCell(GX_UP);
               }
               else
               {
                  MoveCurrentCell(GX_BOTTOMRIGHT);
               }
            }
            return TRUE;
         }
      }
   }
   return CGXGridView::ProcessKeys(pSender, nMessage, nChar, nRepCnt, flags);
}

See Also

CGXGridCore::MoveCurrentCellEx CGXControl::KeyPressed

CGXGridCore

Class Overview | Class Members