BUG: Property Page Flickers and Application Stops Responding When You Press the ESCAPE Key in the Microsoft Management Console (311163)
The information in this article applies to:
- Microsoft Platform Software Development Kit (SDK) 1.0
- Microsoft Management Console
- Microsoft Visual Basic Professional Edition for Windows 6.0
- Microsoft Visual Basic Enterprise Edition for Windows 6.0
- Microsoft Visual Basic Learning Edition for Windows 6.0
This article was previously published under Q311163 SYMPTOMSIn Microsoft Management Console (MMC), you open a property page of an Active Directory Users
and Computers snap-in that has a MultiLine property, and then you click in the MultiLine property text box. If you press the ESCAPE key (ESC), the property page may start to flicker
and MMC may stop responding. This problem occurs only if the MultiLine property is set to True.CAUSEThis problem occurs because the property page does not receive a WM_KEYUP message from Microsoft Windows. When you press ESC, the
property page must receive a WM_KEYUP message to dismiss the property page. However, the property page does not receive this
message. Instead, it receives only a WM_KEYDOWN message. Therefore, MMC may stop responding.
Note This problem does not occur when the MultiLine property is set to False. Also, this problem occurs
only for an Active Directory Users
and Computers snap-in.WORKAROUNDTo work around this problem, use a keyboard hook to intercept keyboard events before the property page handles them. Use a filter
function to handle the intercepted keyboard events. To do this,
follow these steps. Note These steps are based on the sample that is discussed in the "More Information" section.
- Right-click the taskbar, and then click Task
Manager.
- Under Processes, click mmc.exe, and then click End Process.
- In the Task Manager
Warning dialog box that appears, click Yes to quit MMC.
- Open the existing Visual Basic Snap-in project.
- On the Project menu, click Add
Module, and then click Open. By default, Module1.bas is added to the project.
- Add the following code to Module1:
Option Base 0
Option Explicit
' Declare references to external procedures that are in User32.dll:
Public Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Public Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hMod As Long, ByVal dwThreadId As Long) As Long
Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function GetActiveWindow Lib "user32" () As Long
Public Declare Function SetFocus Lib "user32" (ByVal hWnd As Long) As Long
' Constants to be passed as parameters to external procedures:
Public Const WH_KEYBOARD = 2
Public Const WM_KEYDOWN = 256
Public Const WM_CLOSE = 16
' Handle to the hook that intercepts keyboard events:
Public hHook As Long
' Filter function to process keyboard events before the property page handles them:
Public Function KeyboardFilterFunction(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
' Variable to store the result of calls to external procedures:
Dim Result As Long
' Verify that the hook code is valid:
If nCode >= 0 Then
' Verify that ESC is pressed:
If wParam = vbKeyEscape Then
' Set the return value to 1:
KeyboardFilterFunction = 1
' Set the focus to the property page:
Result = SetFocus(GetActiveWindow())
' Send a WM_CLOSE message to the parent window to close the window:
Result = PostMessage(GetActiveWindow, WM_CLOSE, 0, 0)
Exit Function
End If
End If
' Call the next function in the filter function chain:
KeyboardFilterFunction = CallNextHookEx(hHook, nCode, wParam, lParam)
End Function - In Project Explorer, right-click
PropertyPage1, and then click View Code.
- Add the following code to PropertyPage1:
Private Sub Text1_GotFocus()
' Set the keyboard hook:
hHook = SetWindowsHookEx(WH_KEYBOARD, AddressOf KeyboardFilterFunction, 0, App.ThreadID)
End Sub
Private Sub Text1_LostFocus()
' Reset the keyboard hook by unhooking:
Call UnhookWindowsHookEx(hHook)
End Sub - On the File menu, click Make
Project1.dll.
- Start MMC, and then click
Add/Remove Snap-in on the Console menu.
- Click the Active Directory Users and
Computers snap-in, and then click Remove to remove the
existing snap-in.
- Click Add, and then click the
Active Directory Users and Computers snap-in that you created in step 9.
- Click Add, and then click
OK to add the Active Directory Users and Computers snap-in to
MMC.
- Expand Active Directory Users and
Computers.
- Click Users, right-click
Guest, and then click Properties.
- Click the MultiLine property page, and
then click in the text box.
- Press ESC.
Notice that the property
page is dismissed and MMC does not stop responding.
STATUS
Microsoft has confirmed that this is a bug in the MMC Snap-in Designer for Microsoft Visual Basic that is included with the Microsoft Platform Software Development Kit (SDK).
REFERENCESFor more information, visit the following Microsoft Web
sites:
Modification Type: | Minor | Last Reviewed: | 7/11/2005 |
---|
Keywords: | kbpending kbSnapIn kbSDK kbPropSheet kbMsg kbFilter kbDesigner kbActiveDirectory kbUser kbConsole kbDirServices kbControl kbCtrl kbProgramming kbbug kbui KB311163 kbAudDeveloper |
---|
|