Consulting

Results 1 to 7 of 7

Thread: create my own taskbar

  1. #1

    Question create my own taskbar

    hello all
    i'm trying to creat a small tasbar above the main windows taskbar i have searched too much to do that with vba and the resault is nothing
    how can i make my form like windows taskbar always on top and never hide is it possible ?
    thanks in advance

  2. #2
    VBAX Expert Logit's Avatar
    Joined
    Sep 2016
    Posts
    606
    Location
    .
    In a Routine Module :

    Option Explicit
    
    
    Sub shwfrm()
        UserForm1.Show
        SetWindowSize2
    End Sub
    
    
    Sub SetWindowSize2()
        Dim iMaxWidth As Integer
        Dim iMaxHeight As Integer
        Dim iStartX As Integer
        Dim iStartY As Integer
        Dim iDesiredWidth As Integer
        Dim iDesiredHeight As Integer
    
    
        iStartX = 5       ' Distance from left
        iStartY = 5    ' Distance from top
        iDesiredWidth = 0
        iDesiredHeight = 0
    
    
        With Application
            .WindowState = xlMaximized
            iMaxWidth = Application.Width
            iMaxHeight = Application.Height
    
    
            ' Adjust for starting point
            iMaxWidth = iMaxWidth - iStartX
            iMaxHeight = iMaxHeight - iStartY
            If iDesiredWidth > iMaxWidth Then
                iDesiredWidth = iMaxWidth
            End If
            If iDesiredHeight > iMaxHeight Then
                iDesiredHeight = iMaxHeight
            End If
    
    
            .WindowState = xlNormal
            .Top = iStartY
            .Left = iStartX
            .Width = iDesiredWidth
            .Height = iDesiredHeight
        End With
    End Sub
    In the UserForm code module :

    Option Explicit
    
    
    'Object variable to trigger application events
    Private WithEvents XLApp As Excel.Application
    
    
    #If VBA7 Then
        Dim mXLHwnd As LongPtr    'Excel's window handle
        Dim mhwndForm As LongPtr  'The userform's window handle
        private Declare PtrSafe Function FindWindowA Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
        #If Win64 Then
            private Declare PtrSafe Function SetWindowLongA Lib "user32" Alias "SetWindowLongPtrA" (ByVal hwnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr
        #Else
            private Declare PtrSafe Function SetWindowLongA Lib "user32" (ByVal hwnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr
        #End If
        private Declare PtrSafe Function SetForegroundWindow Lib "user32" (ByVal hwnd As LongPtr) As Long
    #Else
        Dim mXLHwnd As Long    'Excel's window handle
        Dim mhwndForm As Long  'The userform's window handle
        Private Declare Function FindWindowA Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
        Private Declare Function SetWindowLongA Lib "user32" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
        Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
    #End If
    
    
    Const GWL_HWNDPARENT As Long = -8
    
    
    Private Sub UserForm_Initialize()
        If Val(Application.Version) >= 15 Then        'Only makes sense on Excel 2013 and up
            Set XLApp = Application
            mhwndForm = FindWindowA("ThunderDFrame", caption)
        End If
    End Sub
    
    
    Private Sub XLApp_WindowActivate(ByVal Wb As Workbook, ByVal Wn As Window)
        If Val(Application.Version) >= 15 And mhwndForm <> 0 Then  'Basear o form na janela ativa do Excel.
            mXLHwnd = Application.hwnd    'Always get because in Excel 15 SDI each wb has its window with different handle.
            SetWindowLongA mhwndForm, GWL_HWNDPARENT, mXLHwnd
            SetForegroundWindow mhwndForm
        End If
    End Sub
    
    
    Private Sub XLApp_WindowResize(ByVal Wb As Workbook, ByVal Wn As Window)
        If Not Me.Visible Then Me.Show vbModeless
    End Sub
    
    
    Private Sub XLApp_WorkbookBeforeClose(ByVal Wb As Workbook, Cancel As Boolean)
        SetWindowLongA mhwndForm, GWL_HWNDPARENT, 0&
    End Sub
    Attached Files Attached Files

  3. #3
    thanks for your effort but unfortunately not what i need

  4. #4
    VBAX Expert Logit's Avatar
    Joined
    Sep 2016
    Posts
    606
    Location
    .
    The answer was based on this : "how can i make my form like windows taskbar always on top and never hide is it possible ?"

    Are you wanting to create another taskbar, matching the Windows Taskbar, and have it attached to the top of the Windows Taskbar ?

    Or, provide more description.

  5. #5
    Quote Originally Posted by Logit View Post
    .
    The answer was based on this : "how can i make my form like windows taskbar always on top and never hide is it possible ?"

    Are you wanting to create another taskbar, matching the Windows Taskbar, and have it attached to the top of the Windows Taskbar ?

    Or, provide more description.
    Exactly what you have said

  6. #6
    VBAX Expert Logit's Avatar
    Joined
    Sep 2016
    Posts
    606
    Location
    .
    Hmm ... I'm not so certain VBA is the language to do that. Probably use C or C++ .


    You can get close to your goal by using VBA to create a UserForm as the example shows.

    From there you can use additional code to :

    Remove the form borders
    Remove the form title bar
    Auto size the form to the height and length you want
    Auto position the form to the position you want it at when first loading
    Reduce the size of the workbook (as shown in the example)
    Position the location of the reduced size workbook where you want it ... even off screen (although not advisable) when it loads
    You can place buttons or icons on the userform and have those to run macros which will perform the task/s of the menu bar
    You can add a right-click function to the userform so it brings up a cascading selection of additional menus
    You can create a menu bar in the form's title bar, just like NotePad or WordPad.

    There are a number of things using VBA that you can do to a userform that will replicate the Windows taskbar.

  7. #7
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    You do not say which version of Access you are using.
    Most versions from 2000 onwards have customisable Task bars.

    Here is an example write up
    https://www.cimaware.com/expert-zone...nd-popup-menus

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •