The information in this article applies to:
- Microsoft Visual Basic Learning, Professional, and Enterprise Editions
for Windows, version 5.0
on the following platform: Win95
SYMPTOMS
A Visual Basic form can be displayed as the top z-ordered (or top-most)
window by using the SetWindowPos API function. Under Windows 95, if the top-
most window then displays a message box, the message box may display behind
the top-most window. The user cannot continue or exit the program because
the user cannot close the message box.
RESOLUTION
Do not display a message box from a form set as the top-most window. If you
must use a message box from the form, unload the form first before
displaying the message box.
STATUS
This behavior is by design.
MORE INFORMATION
Steps to Reproduce Behavior
- Start a new Standard EXE project in Visual Basic. Form1 is created by
default.
- Add the two CommandButtons to Form1 form. Set the following Form1 form
properties:
Form1 Form Property Setting
---------------------------------------
BorderStyle 0-None
StartUpPosition 2-CenterScreen
- Copy the following code to the Code window of Form1 form:
Option Explicit
Private Declare Function SetWindowPos Lib "user32" _
(ByVal hwnd As Long, _
ByVal hWndInsertAfter As Long, _
ByVal x As Long, _
ByVal y As Long, _
ByVal cx As Long, _
ByVal cy As Long, _
ByVal wFlags As Long) As Long
Const HWND_TOPMOST = -1
Const SWP_NOMOVE = &H2
Const SWP_NOSIZE = &H1
Private Sub Form_Load()
Dim lngWindowPosition As Long
Command1.Caption = "Show Message Box"
Command2.Caption = "End Program"
LngWindowPosition = SetWindowPos(Form1.hwnd, _
HWND_TOPMOST, _
0, _
0, _
0, _
0, _
SWP_NOMOVE Or SWP_NOSIZE)
End Sub
Private Sub Command1_Click()
MsgBox "From Message Box", vbSystemModal
End Sub
Private Sub Command2_Click()
End
End Sub
- Save the Project and compile the project into an executable file. This
problem only occurs from an EXE file.
- Run the executable file.
- Click Show Message Box to display the message box.
- Click on the desktop or another application to de-activate Project1.
- Click on the form of Project1 to activate Project1.
- Click OK to dismiss the message box.
NOTE: You may need to repeat steps 6-9 several times to reproduce the
problem where the Message Box is displayed behind the top-most window and
cannot be dismissed.
|