Microsoft KB Archive/311163

= BUG: Property Page Flickers and Application Stops Responding When You Press the ESCAPE Key in the Microsoft Management Console =

Article ID: 311163

Article Last Modified on 7/11/2005

-

APPLIES TO


 * Microsoft Platform Software Development Kit-January 2000 Edition
 * Microsoft Management Console 3.0
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Learning Edition

-



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 &quot;More Information&quot; 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 &quot;user32&quot; (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Public Declare Function UnhookWindowsHookEx Lib &quot;user32&quot; (ByVal hHook As Long) As Long Public Declare Function SetWindowsHookEx Lib &quot;user32&quot; Alias &quot;SetWindowsHookExA&quot; (ByVal idHook As Long, ByVal lpfn As Long, ByVal hMod As Long, ByVal dwThreadId As Long) As Long Public Declare Function PostMessage Lib &quot;user32&quot; Alias &quot;PostMessageA&quot; (ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Public Declare Function GetActiveWindow Lib &quot;user32&quot; As Long Public Declare Function SetFocus Lib &quot;user32&quot; (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 </li> In Project Explorer, right-click PropertyPage1, and then click View Code.</li>  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 </li> On the File menu, click Make Project1.dll.</li> Start MMC, and then click Add/Remove Snap-in on the Console menu.</li> Click the Active Directory Users and Computers snap-in, and then click Remove to remove the existing snap-in.</li> Click Add, and then click the Active Directory Users and Computers snap-in that you created in step 9.</li> Click Add, and then click OK to add the Active Directory Users and Computers snap-in to MMC.</li> Expand Active Directory Users and Computers.</li> Click Users, right-click Guest, and then click Properties.</li> Click the MultiLine property page, and then click in the text box.</li> Press ESC.

Notice that the property page is dismissed and MMC does not stop responding.</li></ol>

<div class="status_section">

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

<div class="moreinformation_section">

Steps to Reproduce the Behavior
<ol> Start Visual Basic 6.0. Create a SnapIn for Active Directory Users and Computers.</li> On the Project menu, click Add Property Page.</li> Click Property Page, and then click Open. By default, PropertyPage1 is added to the project.</li>  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(&quot;PropertyPage1&quot;, &quot;Multiline&quot;) End Sub </li> In the Toolbox, double-click TextBox. By default, Text1 is added to PropertyPage1.</li> <li>Click Text1, and then set the MultiLine property to True.</li> <li>On the Project menu, click Make Project1.dll.</li> <li>In the Make Project dialog box that appears, click OK to compile the snap-in. By default, Project1.dll is created.</li> <li>Start MMC, and then click Add/Remove Snap-in on the Console menu.</li> <li>Click Add, and then click the Active Directory Users and Computers snap-in that you created in step 7.</li> <li>Click Add, and then click OK to add the Active Directory Users and Computers snap-in to MMC.</li> <li>Expand Active Directory Users and Computers.</li> <li>Click Users, right-click Guest, and then click Properties.</li> <li>Click the MultiLine property page, and then click in the text box.</li> <li>Press ESC.

Notice that the MultiLine property page starts to flicker and MMC stops responding.</li></ol>

<div class="references_section">