vb@rchiv
VB Classic
VB.NET
ADO.NET
VBA
C#
Top-Preis! AP-Access-Tools-CD Volume 1  
 vb@rchiv Quick-Search: Suche startenErweiterte Suche starten   Impressum  | Datenschutz  | vb@rchiv CD Vol.6  | Shop Copyright ©2000-2025
 
zurück

 Sie sind aktuell nicht angemeldet.Funktionen: Einloggen  |  Neu registrieren  |  Suchen

Visual-Basic Einsteiger
Re: msgbox 
Autor: ModeratorDieter (Moderator)
Datum: 26.11.03 19:18

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

alle Nachrichten anzeigenGesamtübersicht  |  Zum Thema  |  Suchen

 ThemaViews  AutorDatum
msgbox1.301Chris380SE26.11.03 18:17
Re: msgbox1.051smither26.11.03 18:59
Re: msgbox984Chris380SE26.11.03 19:15
Re: msgbox1.230ModeratorDieter26.11.03 19:18
Re: msgbox1.008Brian26.11.03 19:19
Re: msgbox1.095Chris380SE26.11.03 19:29
Re: msgbox1.321ari26.11.03 19:48
Re: msgbox946Chris380SE26.11.03 20:00
Re: msgbox1.073GuidoE26.11.03 20:15
Re: msgbox976Chris380SE26.11.03 20:52
Re: msgbox987GuidoE26.11.03 21:26
Re: msgbox1.039ari26.11.03 21:28
Re: msgbox947Chris380SE26.11.03 21:47
Re: msgbox961GuidoE26.11.03 21:49
Re: msgbox983ari26.11.03 22:34
Re: msgbox1.009GuidoE27.11.03 21:00
Re: msgbox981ari28.11.03 00:40

Sie sind nicht angemeldet!
Um auf diesen Beitrag zu antworten oder neue Beiträge schreiben zu können, müssen Sie sich zunächst anmelden.

Einloggen  |  Neu registrieren

Funktionen:  Zum Thema  |  GesamtübersichtSuchen 

nach obenzurück
 
   

Copyright ©2000-2025 vb@rchiv Dieter Otter
Alle Rechte vorbehalten.
Microsoft, Windows und Visual Basic sind entweder eingetragene Marken oder Marken der Microsoft Corporation in den USA und/oder anderen Ländern. Weitere auf dieser Homepage aufgeführten Produkt- und Firmennamen können geschützte Marken ihrer jeweiligen Inhaber sein.

Diese Seiten wurden optimiert für eine Bildschirmauflösung von mind. 1280x1024 Pixel