Page tree

Welcome to FreeSoftwareServers Confluence Wiki

Skip to end of metadata
Go to start of metadata

Note: "Application.ActiveWindow"

   
    #If VBA7 Then
        #If Win64 Then
            Public Declare PtrSafe Function GetWindowLongPtr Lib "user32" Alias _
            "GetWindowLongPtrA" (ByVal hWnd As LongPtr, ByVal nIndex As Long) As LongPtr
            
            Public Declare PtrSafe Function SetWindowLongPtr Lib "user32" Alias _
            "SetWindowLongPtrA" (ByVal hWnd As LongPtr, ByVal nIndex As Long, _
            ByVal dwNewLong As LongPtr) As LongPtr
        #Else
            Public Declare PtrSafe Function GetWindowLongPtr Lib "user32" Alias _
            "GetWindowLongA" (ByVal hWnd As LongPtr, ByVal nIndex As Long) As LongPtr
            
            Private Declare Function SetWindowLongPtr Lib "user32" Alias _
            "SetWindowLongA" (ByVal hWnd As LongPtr, ByVal nIndex As Long, _
            ByVal dwNewLong As LongPtr) As LongPtr
        #End If
        
        Public Declare PtrSafe Function DrawMenuBar Lib "user32" _
        (ByVal hWnd As LongPtr) As LongPtr
        
        Private Declare PtrSafe Function FindWindow Lib "user32" Alias _
        "FindWindowA" (ByVal lpClassName As String, _
        ByVal lpWindowName As String) As LongPtr
        
        Private Declare PtrSafe Function SetTimer Lib "user32" _
        (ByVal hWnd As LongPtr, ByVal nIDEvent As LongPtr, _
        ByVal uElapse As LongPtr, ByVal lpTimerFunc As LongPtr) As LongPtr
    
        Public Declare PtrSafe Function KillTimer Lib "user32" _
        (ByVal hWnd As LongPtr, ByVal nIDEvent As LongPtr) As LongPtr
        
        Public TimerID As LongPtr
        
        Dim lngWindow As LongPtr, lFrmHdl As LongPtr
    #Else
    
        Public Declare Function GetWindowLong _
        Lib "user32" Alias "GetWindowLongA" ( _
        ByVal hWnd As Long, ByVal nIndex As Long) As Long
        
        Public Declare Function SetWindowLong _
        Lib "user32" Alias "SetWindowLongA" ( _
        ByVal hWnd As Long, ByVal nIndex As Long, _
        ByVal dwNewLong As Long) As Long
        
        Public Declare Function DrawMenuBar _
        Lib "user32" (ByVal hWnd As Long) As Long
        
        Public Declare Function FindWindowA _
        Lib "user32" (ByVal lpClassName As String, _
        ByVal lpWindowName As String) As Long
    
        Public Declare Function SetTimer Lib "user32" ( _
        ByVal hWnd As Long, ByVal nIDEvent As Long, _
        ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
        
        Public Declare Function KillTimer Lib "user32" ( _
        ByVal hWnd As Long, ByVal nIDEvent As Long) As Long
        
        Public TimerID As Long
        Dim lngWindow As Long, lFrmHdl As Long
    #End If
   Public Const GWL_STYLE = -16
   Public Const WS_CAPTION = &HC00000
''''''''''''''''''''''''''''''
Public Sub HideTitleBar(frm As Object)
        #If VBA7 Then
            Dim lngWindow As LongPtr, lFrmHdl As LongPtr
            lFrmHdl = FindWindow(vbNullString, frm.Caption)
            lngWindow = GetWindowLongPtr(lFrmHdl, GWL_STYLE)
            lngWindow = lngWindow And (Not WS_CAPTION)
            Call SetWindowLongPtr(lFrmHdl, GWL_STYLE, lngWindow)
            Call DrawMenuBar(lFrmHdl)
        #Else
            Dim lngWindow As Long, lFrmHdl As Long
            lFrmHdl = FindWindow(vbNullString, frm.Caption)
            lngWindow = GetWindowLong(lFrmHdl, GWL_STYLE)
            lngWindow = lngWindow And (Not WS_CAPTION)
            Call SetWindowLong(lFrmHdl, GWL_STYLE, lngWindow)
            Call DrawMenuBar(lFrmHdl)
        #End If
    frm.Top = (Application.ActiveWindow.Top + Application.ActiveWindow.Height / 2) - (frm.Height / 2)
    frm.Left = (Application.ActiveWindow.Left + Application.ActiveWindow.Width / 2) - (frm.Width / 2)
End Sub
  • No labels