System and Nonsystem Keystrokes

The ”SYS“ in WM_SYSKEYDOWN and WM_SYSKEYUP stands for ”system“ and refers to keystrokes that are more important to Windows than to the Windows application. The WM_SYSKEYDOWN and WM_SYSKEYUP messages are usually generated for keys typed in combination with the Alt key. These keystrokes invoke options on the program's menu or system menu, or they are used for system functions such as switching the active window (Alt-Tab or Alt-Esc) or for system menu accelerators (Alt in combination with a function key). Programs usually ignore the WM_SYSKEYUP and WM_SYSKEYDOWN messages and pass them to DefWindowProc. Because Windows takes care of all the Alt-key logic, you really have no need to trap these messages. Your window procedure will eventually receive other messages concerning the result of these keystrokes (such as a menu selection). If you want to include code in your window procedure to trap the system keystroke messages (as we will do in the KEYLOOK program later in this chapter), pass the messages to DefWindowProc after you process them so that Windows can still use them for their normal purposes.

But think about this for a moment. Almost everything that affects your program's window passes through your window procedure first. Windows does something with the message only if you pass the message to DefWindowProc. For instance, if you add the lines:

case WM_SYSKEYDOWN :

case WM_SYSKEYUP :

case WM_SYSCHAR :

return 0 ;

to a window procedure, then you effectively disable all Alt-key operations (menu commands, Alt-Tab, Alt-Esc, and so on) when your program has the input focus. Although I doubt you would want to do this, I trust you're beginning to sense the power in your window procedure.

The WM_KEYDOWN and WM_KEYUP messages are usually generated for keys that are pressed and released without the Alt key. Your program may use or discard these keystroke messages. Windows itself doesn't care about them.