AW: Declare Fuktion
14.02.2022 09:04:11
Nepumuk
Hallo Hape,
teste mal:
Option Explicit
Private Declare PtrSafe Function FindWindowA Lib "user32.dll" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As LongPtr
Private Declare PtrSafe Function DrawMenuBar Lib "user32.dll" ( _
ByVal hwnd As LongPtr) As Long
#If Win64 Then
Private Declare PtrSafe Function GetWindowLongPtr Lib "user32.dll" Alias "GetWindowLongPtrA" ( _
ByVal hwnd As LongPtr, _
ByVal nIndex As Long) As LongPtr
Private Declare PtrSafe Function SetWindowLongPtr Lib "user32.dll" Alias "SetWindowLongPtrA" ( _
ByVal hwnd As LongPtr, _
ByVal nIndex As Long, _
ByVal dwNewLong As LongPtr) As LongPtr
#Else
Private Declare PtrSafe Function GetWindowLongPtr Lib "user32.dll" Alias "GetWindowLongA" ( _
ByVal hwnd As LongPtr, _
ByVal nIndex As Long) As LongPtr
Private Declare PtrSafe Function SetWindowLongPtr Lib "user32.dll" Alias "SetWindowLongA" ( _
ByVal hwnd As LongPtr, _
ByVal nIndex As Long, _
ByVal dwNewLong As LongPtr) As LongPtr
#End If
Private Sub CommandButton1_Click()
Call fncHasUserformCaption(True)
End Sub
Private Sub CommandButton2_Click()
Call fncHasUserformCaption(False)
End Sub
Private Sub CommandButton3_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
Call fncHasUserformCaption(False)
End Sub
Private Sub fncHasUserformCaption(bState As Boolean)
Dim Userform_hWnd As LongPtr
Dim Userform_Style As LongPtr
Const GWL_STYLE = (-16)
Const WS_CAPTION = &HC00000
Userform_hWnd = FindWindowA(lpClassName:="ThunderDFrame", lpWindowName:=Caption)
Userform_Style = GetWindowLongPtr(hwnd:=Userform_hWnd, nIndex:=GWL_STYLE)
If bState Then
Userform_Style = Userform_Style Or WS_CAPTION
Else
Userform_Style = Userform_Style And Not WS_CAPTION
End If
Call SetWindowLongPtr(hwnd:=Userform_hWnd, nIndex:=GWL_STYLE, dwNewLong:=Userform_Style)
Call DrawMenuBar(hwnd:=Userform_hWnd)
End Sub
Gruß
Nepumuk