Τα controls του Microsoft Visual Basic επιτρέπουν εμφάνιση μηνυμάτων σε dialog box (user form). Χρησιμοποιούνται message boxes για ερωτήσεις προς τον χρήστη ή εμφάνιση σφαλμάτων με λύσεις. Οι συντεταγμένες μιας φόρμας καθορίζουν τη θέση της στο παράθυρο. Τοποθετώντας ένα message box στο κέντρο της φόρμας, το κείμενο γίνεται πιο ορατό.
Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Public Declare Function SetWindowPos Lib "user32" ()
Public Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Function WinProc2(ByVal lMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim rectForm As RECT, rectMsg As RECT
Dim x As Long, y As Long
'On HCBT_ACTIVATE, show the MsgBox centered over Form1
If lMsg = HCBT_ACTIVATE Then
'Get the coordinates of the form and the message box
'to determine the center of the form location
GetWindowRect Form1.hwnd, rectForm
GetWindowRect wParam, rectMsg
x = (rectForm.Left + (rectForm.Right - rectForm.Left) / 2) - _
((rectMsg.Right - rectMsg.Left) / 2)
y = (rectForm.Top + (rectForm.Bottom - rectForm.Top) / 2) - _
((rectMsg.Bottom - rectMsg.Top) / 2)
'Position the msgbox
SetWindowPos wParam, 0, x, y, 0, 0, _
SWP_NOSIZE Or SWP_NOZORDER Or SWP_NOACTIVATE
End If
End Function
Private Sub Command2_Click()
Dim hInst As Long
Dim Thread As Long
'Display the message box
'MsgBox "This message box is positioned at (0,0)."
End Sub
Πνευματικά δικαιώματα © Γνώση Υπολογιστών Όλα τα δικαιώματα διατηρούνται.