* VB-CODE (1)
Tip 103: Preventing the CTRL+TAB and CTRL+F6 Key Combinations from Activating
         Child Windows

June 5, 1995

A multiple-document interface (MDI) window can contain multiple child windows. A
user can switch between child windows by pressing the CTRL+TAB or CTRL+F6 key
combinations. This article explains how you can prevent the user from using these
keys to switch to another child window.

Using Message Blaster to Disable Keystrokes
Many Microsoft® Windows®-based applications use multiple-document interface (MDI)
windows to display several child windows to the user. For instance, Word for
Windows lets you work with several different documents at the same time. Each text
file is displayed in its own child window.

When users want to switch from one child window to another, they press either
CTRL+TAB or CTRL+F6. The next window in the list is then brought to the top of
the window list (that is, it becomes the currently active window).
In a Visual Basic® application, you can disable this window-switching by
intercepting the messages sent to Windows. The WM_SYSCOMMAND message triggers the
event that switches between child windows. The Message Blaster custom control can
be used to process this WM_SYSCOMMAND message in your Visual Basic program. You
can retrieve Message Blaster from the Microsoft Development Library. For
information on the Message Blaster custom control, see "Additional References" at
the end of this article.

The general idea, however, is to capture the WM_SYSCOMMAND that is sent to
Windows when the CTRL+F6 or CTRL+TAB combination is pressed. To do this, you must
register the Message Blaster control to the target controlin this case, the first
child window (Form1). To prevent a user from activating other child windows,
execute the following statement:


After you have disabled a child window in this manner, the user will not be able
to minimize or maximize the target window. In addition, the resize and move
options are also disabled.

Example Program
This program shows how to disable the CTRL+F6 and CTRL+TAB key combinations so
that the user cannot move to the next MDI child window. Run the example program
by pressing F5. The program displays two child windows (Form1 and Form2) within
an MDI document window. Normally, you can press the CTRL+TAB or CTRL+F6 keys to
switch between the child windows. The Message Blaster control has been used to
disable these two key combinations if you try to use them in Form1. Click Form2
to bring that child window to the top. Unlike Form 1, the Form 2 child window
will process the CTRL+TAB and CTRL+F6 key combinations.

 1. Create a new project in Visual Basic. Form1 is created by default.
 2. From the Visual Basic Insert menu, select MDI Form. MDIForm1 is created by
 3. Set Form1's MDIChild property to True.
 4. From the Visual Basic Insert menu, select Form. Form2 is created by default.
 5. Set the Form 2 MDIChild property to True.
 6. From the Visual Basic Tools menu, select Custom Controls. Add a Message
    Blaster control to Form1. MsgBlaster1 is created by default.
 7. Add the following code to the General Declarations section of Form1:

Option Explicit

 8. Add the following code to the Form_Load event for Form1:

Private Sub Form_Load()
    MsgBlaster1.hWndTarget = Form1.hWnd
    MsgBlaster1.MsgList(0) = WM_SYSCOMMAND
End Sub

 9. Add the following code to the MsgBlaster1_Message event for Form1 (note that
    the first two lines below must be typed as a single line of code):

Private Sub MsgBlaster1_Message(MsgVal As Integer, wParam As Integer,
   lParam As Long, ReturnVal As Long)
    MsgBlaster1.MsgPassage(0) = 0
End Sub

10. Add the following code to the Form_Load event for MDIForm1:

Private Sub MDIForm_Load()
End Sub

Additional References
"The Elements of MDI." (Development Library, Books and Periodicals,
   "Programming Windows 3.1" by Charles Petzold, PART 5 Data Exchange and Links,
   Chapter 18 The Multiple-Document Interface [MDI])
Knowledge Base Q110104. "Using MSGBLAST.VBX Control to Process Windows Messages."
"Message Blaster: Processing Messages in Visual Basic." (Development Library,
   Technical Articles, Visual Basic Articles)
"Switching Between MDI Child Windows." (Development Library,
   Product Documentation, SDKs, Windows Interface Guidelines for Software Design,
   Chapter 9 Window Management, Multiple-Document Interface)