home *** CD-ROM | disk | FTP | other *** search
/ Dan Appleman's Visual Bas…s Guide to the Win32 API / Dan.Applmans.Visual.Basic.5.0.Programmers.Guide.To.The.Win32.API.1997.Ziff-Davis.Press.CD / VB5PG32.mdf / articles / vbbultn / source / ctrl_esc.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1994-04-06  |  3.9 KB  |  104 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "Ctrl Esc Blocker"
  5.    ClientHeight    =   2325
  6.    ClientLeft      =   1095
  7.    ClientTop       =   1485
  8.    ClientWidth     =   4440
  9.    Height          =   2730
  10.    Left            =   1035
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   2325
  13.    ScaleWidth      =   4440
  14.    Top             =   1140
  15.    Width           =   4560
  16.    Begin CheckBox Check1 
  17.       Caption         =   "Block Ctrl-Esc only when this App is active"
  18.       Height          =   285
  19.       Left            =   120
  20.       TabIndex        =   3
  21.       Top             =   1260
  22.       Width           =   3975
  23.    End
  24.    Begin ccWinHook WinHook1 
  25.       Left            =   120
  26.       Messages        =   CTRL_ESC.FRX:0000
  27.       Monitor         =   6  'Systemwide
  28.       Top             =   1680
  29.    End
  30.    Begin CommandButton Exit 
  31.       Caption         =   "Exit"
  32.       Height          =   555
  33.       Left            =   3000
  34.       TabIndex        =   0
  35.       Top             =   1680
  36.       Width           =   1305
  37.    End
  38.    Begin Label Label2 
  39.       Caption         =   "This allows you to bring up the system Task List only from the System-Switch To menu command."
  40.       Height          =   405
  41.       Left            =   90
  42.       TabIndex        =   2
  43.       Top             =   690
  44.       Width           =   4245
  45.    End
  46.    Begin Label Label1 
  47.       Caption         =   "This sample program prevents the Ctl+Esc key from bringing up the system TaskList."
  48.       Height          =   465
  49.       Left            =   360
  50.       TabIndex        =   1
  51.       Top             =   90
  52.       Width           =   3675
  53.    End
  54. Option Explicit
  55. Const BLOCK_THISTASKACTIVE = 4
  56. Const BLOCK_ALWAYS = 6
  57. Const WM_SYSCOMMAND = &H112
  58. Const SC_TASKLIST = &HF130
  59. Sub Check1_Click ()
  60.     If Check1.Value Then
  61.         ' block the Ctl+Esc key from bringing up the task list only
  62.         ' if this is the active application
  63.         WinHook1.Monitor = BLOCK_THISTASKACTIVE
  64.     Else
  65.         ' always block the Ctl+Esc key from bringing up the task list
  66.         WinHook1.Monitor = BLOCK_ALWAYS
  67.     End If
  68. End Sub
  69. Sub Exit_Click ()
  70.     Unload Me
  71. End Sub
  72. Sub Form_Load ()
  73.     If Check1.Value Then
  74.         ' block the Ctl+Esc key from bringing up the task list only
  75.         ' if this is the active application
  76.         WinHook1.Monitor = BLOCK_THISTASKACTIVE
  77.     Else
  78.         ' always block the Ctl+Esc key from bringing up the task list
  79.         WinHook1.Monitor = BLOCK_ALWAYS
  80.     End If
  81. End Sub
  82. Sub WinHook1_WndMessage (wnd As Integer, msg As Integer, wp As Integer, lp As Long, nodef As Integer)
  83.     ' When the user hits the Ctrl+Esc key, Windows sends a WM_SYSCOMMAND message to the active
  84.     ' application.  The information in the message tells the active application to bring up
  85.     ' the Task List.  You cannot use tbe Keyboard Hook to throw the Ctrl-Esc key message away
  86.     ' because the WM_SYSCOMMAND message is sent before the Key message.
  87.     If msg = WM_SYSCOMMAND Then
  88.         If wp = SC_TASKLIST Then
  89.             ' When the user selects the "Switch To..." command from the System menu, lp
  90.             ' contains the cursor coordinates.  When the user hits the Ctrl+Esc key, lp
  91.             ' is not used, and is set to 0.  By blocking the WM_SYSCOMMAND message only
  92.             ' when lp = 0, we allow the user to bring up the Task List via the System menu.
  93.             If lp = 0 Then
  94.                 ' Set nodef to True to prevent other windows hooks from processing the message
  95.                 ' and set msg to 0 (Windows will ignore the message if it is 0).  Refer to the
  96.                 ' SpyWorks-VB manual's section on the nodef parameter in SBCHOOK.VBX on why
  97.                 ' we cannot just set nodef = True.
  98.                 nodef = True
  99.                 msg = 0
  100.             End If
  101.         End If
  102.     End If
  103. End Sub
  104.