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

SYMPTOMS

In 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.

CAUSE

This 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.

WORKAROUND

To 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.
  1. Right-click the taskbar, and then click Task Manager.
  2. Under Processes, click mmc.exe, and then click End Process.
  3. In the Task Manager Warning dialog box that appears, click Yes to quit MMC.
  4. Open the existing Visual Basic Snap-in project.
  5. On the Project menu, click Add Module, and then click Open. By default, Module1.bas is added to the project.
  6. 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
  7. In Project Explorer, right-click PropertyPage1, and then click View Code.
  8. 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
  9. On the File menu, click Make Project1.dll.
  10. Start MMC, and then click Add/Remove Snap-in on the Console menu.
  11. Click the Active Directory Users and Computers snap-in, and then click Remove to remove the existing snap-in.
  12. Click Add, and then click the Active Directory Users and Computers snap-in that you created in step 9.
  13. Click Add, and then click OK to add the Active Directory Users and Computers snap-in to MMC.
  14. Expand Active Directory Users and Computers.
  15. Click Users, right-click Guest, and then click Properties.
  16. Click the MultiLine property page, and then click in the text box.
  17. 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).

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Start Visual Basic 6.0. Create a SnapIn for Active Directory Users and Computers.
  2. On the Project menu, click Add Property Page.
  3. Click Property Page, and then click Open. By default, PropertyPage1 is added to the project.
  4. Add the following code in Snap-in Designer:
    ' Add PropertyPage1 to the existing, built-in property sheet:
    Private Sub Project1_CreatePropertyPages(ByVal DataObject As SnapInLib.MMCDataObject, ByVal PropertySheet As SnapInLib.MMCPropertySheet)
       Call PropertySheet.AddPage("PropertyPage1", "Multiline")
    End Sub
  5. In the Toolbox, double-click TextBox. By default, Text1 is added to PropertyPage1.
  6. Click Text1, and then set the MultiLine property to True.
  7. On the Project menu, click Make Project1.dll.
  8. In the Make Project dialog box that appears, click OK to compile the snap-in. By default, Project1.dll is created.
  9. Start MMC, and then click Add/Remove Snap-in on the Console menu.
  10. Click Add, and then click the Active Directory Users and Computers snap-in that you created in step 7.
  11. Click Add, and then click OK to add the Active Directory Users and Computers snap-in to MMC.
  12. Expand Active Directory Users and Computers.
  13. Click Users, right-click Guest, and then click Properties.
  14. Click the MultiLine property page, and then click in the text box.
  15. Press ESC.

    Notice that the MultiLine property page starts to flicker and MMC stops responding.

Modification Type:MinorLast Reviewed:7/11/2005
Keywords:kbpending kbSnapIn kbSDK kbPropSheet kbMsg kbFilter kbDesigner kbActiveDirectory kbUser kbConsole kbDirServices kbControl kbCtrl kbProgramming kbbug kbui KB311163 kbAudDeveloper