FIX: Closing an MDI Form Results in a General Protection Fault
ID: Q149488
|
The information in this article applies to:
-
Microsoft Visual Basic Standard, Professional, and Enterprise Editions, 32-bit only, for Windows, version 4.0
SYMPTOMS
A Visual Basic program contains an MDI child form with a ComboBox set to
the 1-Simple ComboBox style. The ComboBox contains at least one item. When
you select an item in the ComboBox and then attempt to close the MDI Child
form with the Close button, the program shuts down with the following error
message:
VB32 caused a general protection fault in module USER.EXE
RESOLUTION
To work around this bug, you can do one of the following:
STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed
at the beginning of this article. This bug has been corrected in Visual
Basic, version 5.0.
MORE INFORMATION
This section shows how to create a sample project that demonstrates the bug
and shows how to disable the Close button on the toolbar using Windows API
functions.
Steps to Reproduce Problem
- Start Visual Basic 4.0 or, if it is already running, click New Project
on the File menu.
- Set the MDIChild property of Form1 to True.
- Add a ComboBox and two Command buttons to Form1. Set the ComboBox Style
property to 1-Simple ComboBox.
- Copy the following code to the Code window of Form1:
Option Explicit
Private Declare Function GetSystemMenu Lib "user32" _
(ByVal hWnd As Long, _
ByVal bRevert As Long) As Long
Private Declare Function ModifyMenu Lib "user32" _
Alias "ModifyMenuA" _
(ByVal hMenu As Long, _
ByVal nPosition As Long, _
ByVal wFlags As Long, _
ByVal wIDNewItem As Long, _
ByVal lpString As Any) As Long
Private Declare Function GetMenuItemID Lib "user32" _
(ByVal hMenu As Long, _
ByVal nPos As Long) As Long
Const MF_BYPOSITION = &H400&
Const MF_GRAYED = &H1&
Const MF_BYCOMMAND = &H0&
Sub Command1_click()
' Disables the Close button by calling a user-defined function.
Dim hwndParent As Long
hwndParent = Me.hWnd
DisableItem hwndParent, "&Close", 6
End Sub
Sub DisableItem(hWnd As Long, _
sMenuCaption As String, _
iMenuPos As Integer)
'User-defined function to disable the Close button on the
'MDI Child Form toolbar.
Dim hMenu As Long
Dim hItem As Long
hMenu = GetSystemMenu(hWnd, 0)
hItem = GetMenuItemID(hMenu, iMenuPos)
ModifyMenu hMenu, _
hItem, _
MF_BYCOMMAND Or MF_GRAYED, _
-9, _
sMenuCaption
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Form_Load()
Me.Show
Combo1.AddItem "first item"
Command1.Caption = "Disable Close Button"
Command2.Caption = "Unload MDI Child Form"
End Sub
- From the Insert menu, click MDIForm to add an MDI form to the project.
MDIForm1 is created by default.
- On the Run menu, click start or press the F5 key to start the program.
Select the first item in the ComboBox. Click the Close button in the
Form1 form toolbar. An application error occurs with an error message.
- Run the program again, click Disable Close Button. Check the Close menu
item in the control menu to confirm that it is grayed out. Select the
first item in the ComboBox, and then close the form using the Unload MDI
Child Form button, the MDI Child form closes normally.
Additional query words:
kbide kbVBp kbdsd kbDSupport kbVBp400bug kbVBp500fix kbControl
Keywords : kbCtrl kbVBp400bug kbVBp500fix kbGrpVB
Version :
Platform : WINDOWS
Issue type : kbbug
|