--
=======================
Gruß
Stephan Häussler
=======================
an.
In das Codefenster der Userform diesen Code
'--------'UserForm1 -------
Private Sub UserForm_Initialize()
CheckBox1.Value = True
End Sub
Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then
TextBox1.Enabled = False
TextBox2.Enabled = False
TextBox1.BackColor =
&H80000004
TextBox2.BackColor =
&H80000004
Else
TextBox1.Enabled = True
TextBox2.Enabled = True
TextBox1.BackColor =
&H80000005
TextBox2.BackColor =
&H80000005
TextBox1.SetFocus
End If
End Sub
Private Sub CommandButton1_Click()
Dim hInst As Long, Thread As Long
Dim msg As String
If CheckBox1.Value = True Then
msg$ = "Die MessageBox ist jetzt zentriert."
Else
hInst = Application.Hinstance
Thread = GetCurrentThreadId()
hHook = SetWindowsHookEx(WH_CBT, AddressOf WinProc, hInst, Thread)
posX = CLng(TextBox1)
posY = CLng(TextBox2)
msg$ = "Die Position der MessageBox ist an:" & _
vbCrLf & vbCrLf & "X-Position: " & posX & vbCrLf & "Y-Position: " &
posY
End If
MsgBox msg$, vbOKOnly + vbInformation
End Sub
Private Sub CommandButton2_Click()
Unload Me
End
End Sub
Nun noch ein Modul anlegen für die API Funktion:
'Autor/Einsender: Detlev Schubert
'Datum: 01.05.2001 Beispielprojekt erstellt mit VB5
'geändert von Ulrich Weigel für Excel VBA
Option Explicit
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 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 UnhookWindowsHookEx Lib "user32" (ByVal hHook As
Long) As Long
Public Declare Function GetCurrentThreadId Lib "kernel32" () As Long
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 posX As Long
Public posY As Long
Public Function WinProc(ByVal lMsg As Long, ByVal wParam As Long, _
ByVal lParam As Long) As Long
If lMsg = HCBT_ACTIVATE Then
SetWindowPos wParam, 0, posX, posY, 0, 0, SWP_NOSIZE Or SWP_NOZORDER Or
SWP_NOACTIVATE
UnhookWindowsHookEx hHook
End If
WinProc = False
End Function
Sub Formular_Load()
UserForm1.Show
End Sub
Gutes Positionieren wünscht
Ulrich
Mail to MDLLe...@aol.com
WinXP
OfficeXP
u.v.a.
Rechtschreibfehler sind gewollt und dienen der Belustigung des Lesers