SAMPLE: Preventing Windows from Switching Tasks

Last reviewed: April 7, 1997
Article ID: Q80822
3.00 3.10 WINDOWS kbprg kbfile

The information in this article applies to:

  • Microsoft Windows Software Development Kit (SDK) for Windows versions 3.0 and 3.1

SUMMARY

Certain types of applications, such as security applications and possibly some setup programs, require the ability to disable task switching under Windows. To disable task switching, the program must prevent the user from accessing the Task List, using mouse or keystroke combinations to switch to other applications, and so forth.

The NOSWITCH application in the Microsoft Software Library demonstrates how an application can disable the task switch.

Download NOSWITCH.EXE, a self-extracting file, from the Microsoft Software Library (MSL) on the following services:

  • Microsoft Download Service (MSDL)

          Dial (206) 936-6735 to connect to MSDL
          Download NOSWITCH.EXE (size: 24034 bytes) 
    
  • Internet (anonymous FTP)

          ftp ftp.microsoft.com
          Change to the \SOFTLIB\MSLFILES directory
          Get NOSWITCH.EXE (size: 24034 bytes) 
    

MORE INFORMATION

NOSWITCH demonstrates how an application can disable task switching. The application must take the following four steps to disable task switching:

  1. Subclass the desktop window to prevent the Task List from being displayed when the user double-clicks the desktop window.

  2. Prevent the user from using key combinations to switch to another task by trapping the following three wParam values for the WM_SYSCOMMAND message: SC_NEXTWINDOW, SC_PREVWINDOW, and SC_TASKLIST.

  3. Prevent other applications from activating themselves by enumerating all top-level windows, and disabling the windows that do not belong to this application.

  4. Each time a WM_INITMEMUPOPUP message is received for the system menu, disable the menu items that relate to switching tasks.

Before exiting the application, reverse the effects of any actions taken to prevent switching tasks. Refer to the NOSWITCH sample for complete details.

There is a simpler, more limited, method to disable task switching. If the application is run as a maximized window, then step 2 above is enough to prevent switching tasks. However, the application must prevent the window from being restored or minimized. The limitation to this method is that the application must run as a maximized window.


Additional reference words: 3.00 3.10 softlib NOSWITCH.EXE
KBCategory: kbprg kbfile
KBSubcategory: UsrWndw
Keywords : UsrWndw kbfile kbprg
Version : 3.00 3.10
Platform : WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 7, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.