Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

msgbox positionieren

95 views
Skip to first unread message

Stephan Häussler

unread,
Sep 5, 2002, 8:02:32 AM9/5/02
to
Gibt es eine Möglichkeit, eine Msgbox auf dem Bildschirm zu positionieren
oder geht das nur mit Inputbox und Userforms ?

--
=======================
Gruß
Stephan Häussler
=======================


Dr. Eckehard Pfeifer

unread,
Sep 5, 2002, 8:09:25 AM9/5/02
to
Hallo, das geht wohl nur ueber WinAPI-Aufrufe.
Mfg EP


Ulrich Weigel

unread,
Sep 5, 2002, 7:32:41 PM9/5/02
to
"Dr. Eckehard Pfeifer" <i...@dr-e-pfeifer.de> schrieb im Newsbeitrag
news:OocVUTNVCHA.2056@tkmsftngp09...

> Hallo, das geht wohl nur ueber WinAPI-Aufrufe.
> Mfg EP
>
>
Hallo Stephan,
ja gibt es.
Gefunden bei http://www.vb-fun.de/cgi-bin/loadframe.pl?ID=vb/api.shtml
von mir für Excel VBA geändert:
Lege eine neue Mappe mit einer UserForm1 mit
- eine CheckBox1
- CommandButton1
- CommandButton2
- TextBox1
- TextBox2

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

0 new messages