Kopieren Sie die folgenden Zeilen einfach in ein Modul, die Erklärung des Aufrufs erfolgt im nächsten Abschnitt.
Private Declare Function SetWindowLong Lib "user32" Alias
"SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare
Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As Rect) As Long
Private Declare
Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function SetParent Lib "user32" (ByVal hWndChild
As Long, ByVal
hWndNewParent As Long) As
Long
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 Declare
Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal
idHook&, ByVal lpfn&, ByVal hmod&, ByVal
dwThreadId&) As Long
Private Declare Function
UnhookWindowsHookEx Lib "user32" (ByVal hHook&) As Long
Private Type Rect
Left As Long
Top As
Long
Right As
Long
Bottom As Long
End
Type
Private Type CWPSTRUCT
lParam
As Long
wParam As
Long
Message As
Long
hwnd As Long
End
Type
Private Const WM_COMMAND = &H111
Private Const WM_NCPAINT = &H85
Private Const WM_MOVE = &H3
Private Const SWP_FRAMECHANGED = &H20
Private Const GWL_EXSTYLE = -20
Private WHook As
Long
Private varForm As
Form, varButton As CommandButton
Private Function HookProc&(ByVal nCode&, ByVal
wParam&, Inf As CWPSTRUCT)
Dim WinRect As Rect,
ButtonLeft As
Byte
If
Inf.hwnd = GetParent(varButton.hwnd) Then
'Bei Klick auf den Button
On Error Resume Next
If Inf.Message = WM_COMMAND Then
Call varForm.TitleBarButton_Click
On Error
GoTo 0
ElseIf Inf.hwnd =
varForm.hwnd Then
If
varForm.BorderStyle < 4
Then
If Int(varForm.MaxButton) + Int(varForm.MinButton) < 0
Then
ButtonLeft = 3 * 16
Else
ButtonLeft = 1 * 16
End If
End If
If Inf.Message =
WM_NCPAINT Or Inf.Message = WM_MOVE Then
Call
GetWindowRect(varForm.hwnd,
WinRect)
Call SetWindowPos(varButton.hwnd, 0,
_
WinRect.Right - ButtonLeft - 10 - (varButton.Width /
Screen.TwipsPerPixelX),
_
WinRect.Top + 6, varButton.Width / Screen.TwipsPerPixelX, 14,
_
SWP_FRAMECHANGED)
End
If
End If
End
Function
Public Sub SetTitleBarButton(Frm As Form, Button As
CommandButton)
Set varForm =
Frm
Set varButton =
Button
WHook = SetWindowsHookEx(4, AddressOf HookProc, 0, App.ThreadID)
Call SetWindowLong(Button.hwnd, GWL_EXSTYLE,
&H80)
Call SetParent(Button.hwnd,
GetParent(Frm.hwnd))
End Sub
Public Sub Terminate()
Call UnhookWindowsHookEx(WHook)
Call SetParent(varButton.hwnd, varForm.hwnd)
End Sub