HOWTO: Simulate a Modal Form in Visual Basic CE 6.0
ID: Q218750
|
The information in this article applies to:
-
Microsoft Windows CE Toolkit for Visual Basic 6.0, version 1.0
SUMMARY
This article demonstrates how to simulate a modal form using the Windows CE Toolkit for Visual Basic 6.0 (VBCE6). Please note that the sample code below does not compile under the Windows CE Toolkit for Visual Basic 5.0 (VBCE5) since the declare statement (and, thus, API calls) is not supported under Windows CE Toolkit for Visual Basic 5.0.
MORE INFORMATION
The following sample code illustrates how to implement a login form that simulates a modal form using the SetWindowPos API.
Steps to Reproduce Behavior
- Start a new Windows CE HPC Project in Visual Basic. Form1 is created by default.
- Add a command button to Form1.
- Paste the following code into the code module for Form1:
Private Sub Command1_Click()
Form2.Show
' Warning: Code still executes despite the
' fact that Form2 will be shown modally.
Form1.Enabled = False
MsgBox "Form1 events still fire"
End Sub
Sub ValidatePassword(UID As String, PWD As String)
If UID <> "" And PWD <> "" Then
MsgBox "Login succeeded"
Form1.Enabled = True
Else
MsgBox "Login failed: Please try again"
Form2.Show
End If
End Sub
- From the Project menu, click Add Form to add a new form.
- Set the ControlBox property of Form2 to "False."
- Add a command button, two labels, and two text boxes to Form2.
- Paste the following code into the code module for Form2:
Private Sub Form_Load()
ConfigureUI
Dim lret
lret = SetWindowPos(Form2.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE)
End Sub
Private Sub Command1_Click()
Form2.Hide
Form1.ValidatePassword Text1.Text, Text2.Text
End Sub
Sub ConfigureUI()
Form2.Height = 2235
Form2.Width = 3400
Form2.Caption = "Please Log In"
Label1.Top = 120
Label1.Left = 120
Label1.Height = 375
Label1.Width = 975
Label1.Caption = "UserID"
Label2.Top = 600
Label2.Left = 120
Label2.Height = 375
Label2.Width = 975
Label2.Caption = "Password"
Text1.Top = 120
Text1.Left = 1100
Text1.Height = 375
Text1.Width = 1975
Text1.Text = "TestID"
Text2.Top = 600
Text2.Left = 1100
Text2.Height = 375
Text2.Width = 1975
Text2.Text = "TestPassword"
Command1.Left = 240
Command1.Top = 1200
Command1.Height = 495
Command1.Width = 2775
Command1.Caption = "Log In"
End Sub
- From the Project menu, click Add Module to add a new module.
- Paste the following code into Module1:
Public Declare Function SetWindowPos Lib "Coredll" ( _
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 SWP_NOMOVE = 2
Const SWP_NOSIZE = 1
Const HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2
- Run the project.
REFERENCES
Windows CE Toolkit for Visual Basic 6.0 Online Help
The Windows API Viewer (winceapi.txt file)
Additional query words:
vbce vbce6
Keywords : kbToolkit kbVBp600 kbWinCE kbGrpVB
Version : WINDOWS:1.0
Platform : WINDOWS
Issue type : kbhowto
|