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.
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 control—in this case, the first child window (Form1). To prevent a user from activating other child windows, execute the following statement:
MsgBlaster1=MsgPassage(0)
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.
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.
Option Explicit
Const WM_SYSCOMMAND = &H112
Private Sub Form_Load()
MsgBlaster1.hWndTarget = Form1.hWnd
MsgBlaster1.MsgList(0) = WM_SYSCOMMAND
End Sub
Private Sub MsgBlaster1_Message(MsgVal As Integer, wParam As Integer,
lParam As Long, ReturnVal As Long)
MsgBlaster1.MsgPassage(0) = 0
End Sub
Private Sub MDIForm_Load()
Form1.Show
Form2.Show
End Sub
"The Elements of MDI." (MSDN Library Archive, 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."