AW: MSG Box Positionieren?
12.02.2017 16:32:08
Hajo_Zi
Hallo Andi,
Option Explicit
' 1.Teil - alles in ein Standart-Modul:
' MsgBOx an bestimmte Position
Private Declare Function FindWindow Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName As String, ByVal _
lpWindowName As String) As Long
Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, _
_
ByVal nIndex As Long) As Long
Public Declare Function GetCurrentThreadId Lib "kernel32" () As Long
Public Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" _
(ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As _
Long
Public 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
Public Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Public Const GWL_HINSTANCE = (-6)
Public Const SWP_NOSIZE = &H1
Public Const SWP_NOZORDER = &H4
Public Const SWP_NOACTIVATE = &H10
Public Const HCBT_ACTIVATE = 5
Public Const WH_CBT = 5
Public hHook As Long
Public MsgBoxPosX As Integer
Public MsgBoxPosY As Integer
Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Function WinProc(ByVal lMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If lMsg = HCBT_ACTIVATE Then
SetWindowPos wParam, 0, MsgBoxPosX, MsgBoxPosY, 0, 0, SWP_NOSIZE Or SWP_NOZORDER Or _
SWP_NOACTIVATE
UnhookWindowsHookEx hHook
End If
WinProc = False
End Function
Function msg(msgText As String, msgButton As Long, msgTitel As String, xPos As Long, yPos As _
Long)
Dim hInst As Long
Dim XLInst As Long
Dim Thread As Long
MsgBoxPosX = xPos
MsgBoxPosY = yPos
XLInst = FindWindow("xlmain", vbNullString)
hInst = GetWindowLong(XLInst, GWL_HINSTANCE)
Thread = GetCurrentThreadId()
hHook = SetWindowsHookEx(WH_CBT, AddressOf WinProc, hInst, Thread)
MsgBox msgText, msgButton, msgTitel, 0, 0
End Function
' 2.Teil - Aufruf von überall:
Sub Aufruf_MsgBox()
Dim Dummy As Byte
'ButtonTypen:
'0 = OK
'1 = OK , Cancel
'2 = Abort , Ignore, Retry
'3 = Yes , No, Cancel
'4 = Yes , No
'5 = Retry , Cancel
'IconTypen:
'16 = Critical
'32 = Question
'48 = Exclamation
'64 = Information
'Syntax: msg(Text,Button(siehe oben),Titel,Position X-Achse,Position Y-Achse)
'Variablen: msg(as string, as Long, as String, as Long, as Long)
Dummy = msg("Ich bin Positioniert :-)", 4, "Achtung!", 5, 50)
End Sub
' Von Der Zugvogel (Mischa Reichelt mIsCHa)
Benutze eine UserForm ist einfacher.