Microsoft KB Archive/19751

INF: Trapping the INS and DEL Keys

PSS ID Number: Q19751 Article last modified on 11-04-1993

2.x 3.00 WINDOWS

= SYMPTOMS =

When running the TRACK sample application application, a message box appears verifying that a key was pressed. This works for most keys except INS and DEL. However, the DLGC_WANTALLKEYS code would not trap the INS and DEL keys as expected. TRACK.C can be found in the Software/Data Library by searching on the keyword TRACK, the Q number of this article, or S12038. TRACK was archived using the PKware file-compression utility.

= CAUSE =

A list box does not use the INS or DEL keys. If you want to trap the VK_DELETE and VK_INSERT keys, you must add a switch statement to the List Box window procedure.

= RESOLUTION =

You must add a switch statement to the List Box procedure for VK_DELETE and VK_INSERT.

= MORE INFORMATION =

The following is the list box procedure from TRACK.C with a switch statement added for VK_DELETE and VK_INSERT:

/******************************************************************** * This is the new window procedure for the ListBox control.  *******************************************************************/ long FAR PASCAL NewListWndProc(hwnd, message, wParam, lParam) HWND hwnd; unsigned message; WORD wParam; LONG lParam; { char temp[80]; /* added / switch (message) { case WM_GETDLGCODE: /********************************************************** * When the parent needs to know what keys the control   needs to process, it sends this message and it is   up to the control to let it know. In this case   here, the control would like all the keys.  **********************************************************/ return (DLGC_WANTALLKEYS); break; case WM_KEYDOWN: switch(wParam) { case VK_DELETE: MessageBox(hwnd,(LPSTR)“Del”,(LPSTR)“hit”,MB_OK); break; case VK_INSERT: MessageBox(hwnd,(LPSTR)“Ins”,(LPSTR)“hit”,MB_OK); break; } break; case WM_CHAR: /*********************************************************** * Warning: Make sure that when you intercept messages   and then pass them on, make sure they are going to the   correct Window, or in some cases to the PARENT.   A case of this may be where you want to convert a ENTER  into a TAB; you will want to pass the converted TAB   to the PARENT or the HANDLE to the DIALOG in this case. **********************************************************/ sprintf(temp,“%x was pressed”,wParam); MessageBox(hwnd, (LPSTR)temp, (LPSTR)“WM_CHAR Hit”, MB_OK); if (wParam == VK_TAB ||wParam == VK_RETURN) { /* Let’s send a message to the parent to let it know what’s going on / SendMessage (hParent, WM_USER,0,0L); SetActiveWindow (hPushButton); / put focus on next control / return TRUE; } else return CallWindowProc(lpfnListOld, hwnd, message, wParam, lParam); break; default: /********************************************************* * This returns all the unprocessed messages back to   the original procedure.  *********************************************************/ return CallWindowProc(lpfnListOld, hwnd, message, wParam, lParam); } /* end switch */ }

Additional reference words: 2.x 3.00 KBCategory: KBSubcategory: UsrCtlListbox Copyright Microsoft Corporation 1993.