Ich hätte da noch eine Alternative
Im Falle, dass die MsgBox "AlwaysOnTop" angezeigt werden soll, könnte man die API-MessageBox verwenden
Füge einfach einmal folgenden Code in ein Modul:
Option Explicit
' Benötigte API's für die Timer-Steuerung
Private Declare Function SetTimer Lib "user32" ( _
ByVal hwnd As Long, _
ByVal nIDEvent As Long, _
ByVal uElapse As Long, _
ByVal lpTimer As Long) As Long
Private Declare Function KillTimer Lib "user32" ( _
ByVal hwnd As Long, _
ByVal nIDEvent As Long) As Long
Private Const MY_NID = 88
Private Const MY_ELAPSE = 25 ' Wartezeit: 25 MSek.
' Benötigte API's für das Manipulieren der MsgBox
Private Declare Function MessageBox Lib "user32" _
Alias "MessageBoxA" ( _
ByVal hwnd As Long, _
ByVal lpText As String, _
ByVal lpCaption As String, _
ByVal wType As Long) As Long
Private Declare Function GetActiveWindow _
Lib "user32" () As Long
' WindowHandle des aktiven Fensters
Private m_hWnd As Long
' Benötigte API's für das Anzeigen eines Fenster im Vordergrund
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
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Public Function MsgBox(ByVal sPrompt As String, _
Optional ByVal nButtons As VbMsgBoxStyle = vbOKOnly, _
Optional ByVal sTitle As String = "", _
Optional ByVal bOnTop As Boolean = False)
Dim nResult As Long
' Falls MsgBox "OnTop" angezeigt werden soll...
If bOnTop Then
' Fensterhandle
m_hWnd = GetActiveWindow()
' API-Timer starten
nResult = SetTimer(m_hWnd, MY_NID, MY_ELAPSE, AddressOf MsgBox_TimerEvent)
' MsgBox anzeigen
nResult = MessageBox(m_hWnd, sPrompt, sTitle, nButtons)
Else
' andernfalls Standard-MsgBox anzeigen
nResult = VBA.MsgBox(sPrompt, nButtons, sTitle)
End If
' Rückgabewert
MsgBox = nResult
End Function
' Timer-Event!
Sub MsgBox_TimerEvent()
Dim nWnd As Long
' API-Timer wieder deaktivieren
KillTimer m_hWnd, MY_NID
' Fensterhandle der MsgBox
nWnd = GetActiveWindow()
' MsgBox On Top setzen
SetWindowPos nWnd, HWND_TOPMOST, 0, 0, 0, 0, _
SWP_NOMOVE Or SWP_NOSIZE
End Sub Aufruf der MsgBox:
' AlwaysOnTop
MsgBox "Test", vbCritical + vbOKOnly, "Hinweis", True ' Normal
MsgBox "Test", vbCritical + vbOKOnly, "Hinweis" _________________________
Professionelle Entwicklerkomponenten
www.tools4vb.de |