VERSION 5.00
Begin VB.UserControl ctMenuA 
   Alignable       =   -1  'True
   BackColor       =   &H80000005&
   BorderStyle     =   1  'Fixed Single
   ClientHeight    =   1170
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   1200
   ClipBehavior    =   0  'None
   ClipControls    =   0   'False
   EditAtDesignTime=   -1  'True
   FillStyle       =   0  'Solid
   HasDC           =   0   'False
   HitBehavior     =   0  'None
   KeyPreview      =   -1  'True
   PaletteMode     =   4  'None
   ScaleHeight     =   78
   ScaleMode       =   3  'Pixel
   ScaleWidth      =   80
   Begin VB.Image ePic 
      Height          =   480
      Index           =   0
      Left            =   360
      Top             =   120
      Visible         =   0   'False
      Width           =   480
   End
   Begin VB.Label eLabel 
      Alignment       =   2  'Center
      AutoSize        =   -1  'True
      BackColor       =   &H80000005&
      Height          =   195
      Index           =   0
      Left            =   90
      TabIndex        =   0
      Top             =   600
      UseMnemonic     =   0   'False
      Visible         =   0   'False
      Width           =   1005
      WordWrap        =   -1  'True
   End
End
Attribute VB_Name = "ctMenuA"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
' custom usercontrol for Visual Basic 6
' Copyright (C) 2003-2006 Jan Vorel
' This program is free software; you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation; either version 2 of the License, or
' (at your option) any later version.

' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU General Public License for more details.

' You should have received a copy of the GNU General Public License
' along with this program; if not, write to the Free Software
' Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

' This is a shared modul, class modul, usercontrol or form. It is also
' published under the GNU General Public License.

' If you have any questions, suggestions or bug reports about this product,
' contact me: info@ctuser.net; Do not contact me about general B.A.S.I.C.
' language or A.P.I. issues

'#ctMenuA_FlagA
'      1 = Keys
'      2 = Paging
'      4 = ExtendedEvents
'     10 = UpdateItemCount
'     20 = AddItem
'     40 = RemoveItem
'    X00 -> Alignment
'    100 = AutoAlignStretch
'    200 = AutoAlignStretchCenter
'#ctMenuA_FlagB
'      1 = SetTextHeight
'      2 = SetIconHeight (reserved)
'      4 = SetBold
'      8 = FlatButtons
'     10 = GetItemCount
'     20 = SetCurItem
'     40 = GetCurItem
'    100 = SetEnabled
'   1000 = <Reserved QTaskRemoving>

' Version history:
' 0000_0001: Correct width when non-standard width used on initialisation (not yet runtime-resized)
'            vertical alignemnt working on initialisation (not yet runtime-resized)
'            Some other fixes
' 0000_0002: Fixed 'Argument not optional' problem due obsolete 'RaiseEvent ItemClick(Index)' statement

Option Explicit
Option Base 0

Dim xSpaceGen As Long
Dim xSpaceIHeight As Long
Dim xSpaceTHeight As Long
Dim xCount As Long
Dim xCurrent As Long
Dim xHasFocus As Boolean

Private Const xSpaceTLeft As Long = 6&
Private Const xSpaceTWidth As Long = 12&

#If (ctMenuA_FlagA And &H1&) = &H1& Then
  #If (ctMenuA_FlagA And &H4&) = &H4& Then
    Public Event ItemClick(ByVal Index As Long, ByVal Key As String, ByVal ButtonMode As Long, ByRef Cancel As Boolean)
    #Else
    Public Event ItemClick(ByVal Index As Long, ByVal Key As String)
    #End If
  #Else
  #If (ctMenuA_FlagA And &H4&) = &H4& Then
    Public Event ItemClick(ByVal Index As Long, ByVal ButtonMode As Long, ByRef Cancel As Boolean)
    #Else
    Public Event ItemClick(ByVal Index As Long)
    #End If
  #End If

#If (ctMenuA_FlagA And 1) = 1 Then
  Private Const xMaxCount As Long = 256&
  Private Const xMaxCountX As Long = 255&
  Private xKey(xMaxCountX) As String
  #End If

#If (ctMenuA_FlagA And &H2&) = &H2& Then
  Private xPage As Long
  Private xPages As Long
  Private Const xSpaceBTop As Long = 3 'Integer = 0
  Private Const xSpaceBRight As Long = 3 ' Integer = 3
  Private Const xSpaceBBottom As Long = 3 'Integer = 3
  
  Private eButton0Top As Long
  Private eButtonLeft As Long
  Private eButton1Top As Long
  Private Const eButtonHeight As Long = 16&
  Private Const eButtonWidth As Long = 16&
  
  Private hWndButton1 As Long
  Private hWndButton2 As Long
  Private hWndButton1HookOld As Long
  Private hWndButton2HookOld As Long
  
  'Private xHookProc As Long
  Private Declare Function SetTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
  Private Declare Function KillTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long) As Long
  
  Private Declare Function CreateWindowExA Lib "user32" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, lpParam As Any) As Long
  Private Declare Function DestroyWindow Lib "user32" (ByVal hWnd 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 SetWindowLongA Lib "user32" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
  Private Declare Function GetWindowLongA Lib "user32" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
  Private Declare Function SendMessageA Lib "user32" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

  #If (ctMenuA_FlagB And &H8&) = &H8& Then
    Private xFlButtons As Boolean
    #End If
  #End If

#If (ctMenuA_FlagA And &HF00&) > 0 Then
  Private xAutoAligned As Boolean
  #End If

Public Property Let ItemCount(ByVal Count As Long)
  Dim xLong1 As Long
  Dim xLong2 As Long
  
  #If (ctMenuA_FlagA And &H10&) = &H10& Then
    Dim xLong3 As Long
    
    If Not Count = xCount Then
      #If (ctMenuA_FlagA And 1) = 1 Then
        If Count > xMaxCount Then Count = xMaxCount
        #End If
      xLong2 = Count
      If Count < xCount Then
        If Count = 0& Then
          ePic(0).Visible = False
          eLabel(0).Visible = False
          Count = 1&
          End If
        For xLong1 = xCount - 1& To Count Step -1&
          Unload ePic(xLong1)
          Unload eLabel(xLong1)
          Next
        Else
        If xCount = 0 Then
          xLong3 = (xSpaceTHeight + xSpaceGen + xSpaceIHeight) * (-xPage) + xSpaceGen
          With ePic(0)
            .Top = xLong3
            .Visible = True
            End With
          With eLabel(0)
            .Top = xLong3 + xSpaceIHeight
            .Visible = True
            End With
          xCurrent = 0&
          xCount = 1&
          Highlight 0&, True
          End If
        For xLong1 = xCount To Count - 1
          xLong3 = (xSpaceTHeight + xSpaceGen + xSpaceIHeight) * (-xPage + xLong1) + xSpaceGen
          Load ePic(xLong1)
          With ePic(xLong1)
            .Top = xLong3
            .Visible = True
            End With
          Load eLabel(xLong1)
          With eLabel(xLong1)
            .Top = xLong3 + xSpaceIHeight
            .ForeColor = &H80000008
            .BackColor = &H80000005
            .Visible = True
            End With
          Next
        End If
      xCount = xLong2
      If xCount = 0& Then
        Highlight 0&, False
        xCurrent = 0&
        Else
        If Not xCurrent < xCount Then
          xCurrent = xCount - 1&
          CurrentItem = xCurrent
          End If
        End If
      #If (ctMenuA_FlagA And &H2&) = &H2& Then
        CheckPaging
        #ElseIf (ctMenuA_FlagA And &HF00&) > 0 Then
        AlignItems
        #End If
      End If
    #Else


    #If (ctMenuA_FlagA And 1) = 1 Then
      If Count > xMaxCount Then Count = xMaxCount
      #End If
    
    
    #If (ctMenuA_FlagA And &H2&) = &H2& Then
      ePic(xLong1).Top = (xSpaceTHeight + xSpaceGen + xSpaceIHeight) * (-xPage) + xSpaceGen   '78
      eLabel(xLong1).Top = (xSpaceTHeight + xSpaceGen + xSpaceIHeight) * (-xPage) + xSpaceGen + xSpaceIHeight   '+ 40 '78 / + 8+32
      #Else
      ePic(0).Top = xSpaceGen
      eLabel(0).Top = xSpaceGen + xSpaceIHeight
      #End If
    ePic(0).Visible = (Not Count = 0&)
    eLabel(0).Visible = (Not Count = 0&)
    xCurrent = 0&
    xCount = 1&
    Highlight 0&, True
    
    For xLong1 = 1& To Count - 1&
      #If (ctMenuA_FlagA And &H2&) = &H2& Then
        xLong2 = (xSpaceTHeight + xSpaceGen + xSpaceIHeight) * (xLong1 - xPage) + xSpaceGen
        #Else
        xLong2 = (xSpaceTHeight + xSpaceGen + xSpaceIHeight) * xLong1 + xSpaceGen
        #End If
      Load ePic(xLong1)
      With ePic(xLong1)
        .Top = xLong2
        .Visible = True
        End With
      Load eLabel(xLong1)
      With eLabel(xLong1)
        .Top = xLong2 + xSpaceIHeight
        .ForeColor = &H80000008
        .BackColor = &H80000005
        .Visible = True
        End With
      Next
    xCount = Count
    
    If Not xCurrent < xCount Then
      xCurrent = xCount - 1&
      End If
    #If (ctMenuA_FlagA And &H2&) = &H2& Then
      CheckPaging
      #ElseIf (ctMenuA_FlagA And &HF00&) > 0 Then
      AlignItems
      #End If
    #End If
  End Property

#If (ctMenuA_FlagB And &H10&) = &H10& Then
  Public Property Get ItemCount() As Long
    ItemCount = xCount
    End Property
  #End If









#If (ctMenuA_FlagA And &H20&) = &H20& Then
  Public Sub AddItem(ByVal Index As Long)
    Dim xLong1 As Long
    Dim xLong2 As Long
    Dim xChar1 As String
    
    #If (ctMenuA_FlagA And 1) = 1 Then
      If Not xCount = xMaxCount Then
        #End If
          If Index < xCount + 1& Then
            If Not xCount = 0& Then
              Load ePic(xCount)
              Load eLabel(xCount)
              End If
            xLong1 = (xSpaceTHeight + xSpaceGen + xSpaceIHeight) * (xCount - xPage) + xSpaceGen
            ePic(xCount).Top = xLong1
            eLabel(xCount).Top = xLong1 + xSpaceIHeight
            For xLong1 = xCount To Index + 1& Step -1&
              xLong2 = xLong1 - 1&
              xChar1 = ePic(xLong2).ToolTipText
              ePic(xLong1).Picture = ePic(xLong2).Picture
              ePic(xLong1).ToolTipText = xChar1
              eLabel(xLong1).Caption = eLabel(xLong2).Caption
              eLabel(xLong1).ToolTipText = xChar1
              #If (ctMenuA_FlagA And 1) = 1 Then
                xKey(xLong1) = xKey(xLong2)
                #End If
              Next
            xCount = xCount + 1&
            Highlight xCount - 1&, False
            If Not xCurrent < Index Then
              Highlight xCurrent, False
              xCurrent = xCurrent + 1&
              Highlight xCurrent, True
              End If
            ePic(xCount - 1&).Visible = True
            eLabel(xCount - 1&).Visible = True
            #If (ctMenuA_FlagA And &H2&) = &H2& Then
              CheckPaging
              #ElseIf (ctMenuA_FlagA And &HF00&) > 0 Then
              AlignItems
              #End If
            End If
          #If (ctMenuA_FlagA And 1) = 1 Then
        End If
      #End If
    End Sub
  #End If

#If (ctMenuA_FlagA And &H40&) = &H40& Then
  Public Sub RemoveItem(ByVal Index As Long)
    Dim xLong1 As Long
    Dim xLong2 As Long
    Dim xChar1 As String
    
    If Index < xCount Then
      For xLong1 = Index To xCount - 2&
        xLong2 = xLong1 + 1&
        xChar1 = ePic(xLong1 - 1&).ToolTipText
        ePic(xLong1).Picture = ePic(xLong2).Picture
        ePic(xLong1).ToolTipText = xChar1
        eLabel(xLong1).Caption = eLabel(xLong2).Caption
        eLabel(xLong1).ToolTipText = xChar1
        #If (ctMenuA_FlagA And 1) = 1 Then
          xKey(xLong1) = xKey(xLong2)
          #End If
        Next
      If xCount = 1& Then
        ePic(0).Visible = False
        eLabel(0).Visible = False
        Else
        Unload ePic(xCount - 1&)
        Unload eLabel(xCount - 1&)
        If xCurrent > Index Then
          If Not xCurrent = xCount - 1& Then
            Highlight xCurrent, False
            End If
          xCurrent = xCurrent - 1&
          Highlight xCurrent, True
          ElseIf xCurrent = Index Then
          'Highlight xCurrent, True
          If xCurrent = xCount - 1& Then
            If Not xCount = 1& Then
              xCurrent = xCurrent - 1&
              Highlight xCurrent, True
              End If
            Else
            Highlight xCurrent, True
            End If
          End If
        End If
      xCount = xCount - 1&
      #If (ctMenuA_FlagA And &H2&) = &H2& Then
        CheckPaging
        #ElseIf (ctMenuA_FlagA And &HF00&) > 0 Then
        AlignItems
        #End If
      End If
    End Sub
  #End If

#If (ctMenuA_FlagA And 1) = 1 Then
  Public Sub SetItem(ByVal Index As Long, ByVal Caption As String, Optional ByVal PictureResID As Long = -1&, Optional ByVal ToolTipText As String = vbNullChar, Optional ByVal Key As String = "")
  #Else
  Public Sub SetItem(ByVal Index As Long, ByVal Caption As String, Optional ByVal PictureResID As Long = -1&, Optional ByVal ToolTipText As String = vbNullChar)
  #End If
If Index < xCount Then
  eLabel(Index).Caption = Caption
  If Not PictureResID = -1& Then
    #If (LoadResEx_FlagA And &H10&) = &H10& Then
    '#If IsQPlayer100 Then
      Call LoadResEx_Picture(PictureResID, ePic(Index), False)
      #Else
      On Error Resume Next
      ePic(Index).Picture = LoadResPicture(PictureResID, 1)
      On Error GoTo 0
      #End If
    'On Error GoTo 0
    End If
  If Not ToolTipText = vbNullChar Then
    ePic(Index).ToolTipText = ""
    eLabel(Index).ToolTipText = ""
    Else
    ePic(Index).ToolTipText = ToolTipText
    eLabel(Index).ToolTipText = ToolTipText
    End If
  #If (ctMenuA_FlagA And 1) = 1 Then
    xKey(Index) = Key
    #End If
  End If


End Sub

Private Sub eLabel_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
#If (ctMenuA_FlagA And &H4&) = &H4& Then
  If Button = 1 Or Button = 2 Then ClickEvent Index, CLng(Button)
  #Else
  ClickEvent Index
  #End If
End Sub

Private Sub ePic_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
#If (ctMenuA_FlagA And &H4&) = &H4& Then
  If Button = 1 Or Button = 2 Then ClickEvent Index, CLng(Button)
  #Else
  ClickEvent Index
  #End If
End Sub

#If (ctMenuA_FlagA And &H4&) = &H4& Then
  Private Sub eLabel_DblClick(Index As Integer)
    ClickEvent Index, 3
    End Sub
  
  Private Sub ePic_DblClick(Index As Integer)
    ClickEvent Index, 3
    End Sub
  #End If

'#If (ctMenuA_FlagA And &H2&) = &H2& Then
  'Public Sub RaiseButtonEvent(ByVal Index As Long)
  '  If Index = 0& And Not xPage = 0& Then SetPage xPage - 1&, False
  '  If Index = 1& And Not xPage = xCount - xPages Then SetPage xPage + 1&, False
  '  End Sub
  '#End If



#If (ctMenuA_FlagA And &H4&) = &H4& Then
  Private Sub ClickEvent(ByVal Index As Long, ByVal MouseEvent As Long)
    Dim xBool1 As Boolean
    
    xBool1 = False
    If Not Index = xCurrent Then
      Highlight xCurrent, False
      Highlight Index, True
      If MouseEvent = 2 Then xBool1 = True
      DoEvents
      #If (ctMenuA_FlagA And 1) = 1 Then
        RaiseEvent ItemClick(Index, xKey(Index), MouseEvent, xBool1)
        #Else
        RaiseEvent ItemClick(Index, MouseEvent, xBool1)
        #End If
      If xBool1 Then
        Highlight Index, False
        Highlight xCurrent, True
        Else
        xCurrent = Index
        End If
      Else
      
      DoEvents
      #If (ctMenuA_FlagA And 1) = 1 Then
        RaiseEvent ItemClick(Index, xKey(Index), MouseEvent, xBool1)
        #Else
        RaiseEvent ItemClick(Index, MouseEvent, xBool1)
        #End If
      End If
    End Sub
  #Else
  Private Sub ClickEvent(ByVal Index As Long)
    If Not Index = xCurrent Then
      Highlight xCurrent, False
      Highlight Index, True
      xCurrent = Index
      End If
    DoEvents
    #If (ctMenuA_FlagA And 1) = 1 Then
      RaiseEvent ItemClick(Index, xKey(Index))
      #Else
      RaiseEvent ItemClick(Index)
      #End If
    End Sub
  #End If

#If (ctMenuA_FlagB And &H20&) = &H20& Then
  Public Property Let CurrentItem(ByVal Index As Long)
    If Not Index = xCurrent And Index < xCount Then
      Highlight xCurrent, False
      xCurrent = Index
      Highlight xCurrent, True
      
      #If (ctMenuA_FlagA And &H4&) = &H4& Then
        #If (ctMenuA_FlagA And &H1&) = &H1& Then
          RaiseEvent ItemClick(Index, xKey(Index), MouseEvent, xBool1)
          #Else
          RaiseEvent ItemClick(Index, 1&, False)
          #End If
        #Else
        #If (ctMenuA_FlagA And 1) = 1 Then
          RaiseEvent ItemClick(Index, xKey(Index))
          #Else
          RaiseEvent ItemClick(Index)
          #End If
        #End If
''''      RaiseEvent ItemClick(Index)
      End If
    End Property
  #End If

#If (ctMenuA_FlagB And &H40&) = &H40& Then
  Public Property Get CurrentItem() As Long
    CurrentItem = xCurrent
    End Property
  #End If
  


Private Sub Highlight(ByVal Index As Long, ByVal Highlight As Boolean)
  If Highlight Then
    If xHasFocus Then
      eLabel(Index).ForeColor = &H8000000E
      eLabel(Index).BackColor = &H8000000D
      Else
      eLabel(Index).ForeColor = &H80000012
      eLabel(Index).BackColor = &H8000000F
      End If
    #If (ctMenuA_FlagA And &H2&) = &H2& Then
      If xPages < 3 Or Index = 0 Or Index = xCount - 1 Then
        If Index < xPage Then SetPage Index, False
        If Index > xPage + xPages - 1 And Not xPages = 0 Then SetPage Index + 1 - xPages, False
        Else
        If Index < xPage + 1 Then SetPage Index - 1, False
        If Index > xPage + xPages - 2 And Not xPages = 0 Then SetPage (Index + 2 - xPages), False
        End If
      #End If
    Else
    eLabel(Index).ForeColor = &H80000008
    eLabel(Index).BackColor = &H80000005
    End If
  End Sub

Private Sub UserControl_EnterFocus()
  xHasFocus = True
  Highlight xCurrent, True
  End Sub

Private Sub UserControl_ExitFocus()
  xHasFocus = False
  Highlight xCurrent, True
  End Sub

Private Sub UserControl_Initialize()
  xSpaceTHeight = 24&
  xSpaceGen = 6&
  xSpaceIHeight = 32&
  #If (ctMenuA_FlagA And &H2&) = &H2& Then
    'Load eButton(1)
    If ctMenuA_TimerHWnd = 0& Then
      ctMenuA_TimerHWnd = SetTimer(0&, 0&, ctMenuA_ButtonDownTimerInterval, AddressOf ctMenuA_TimerProc)
      'Debug.Print "Create"
      End If
    ctMenuA_TimerCount = ctMenuA_TimerCount + 1&
    #End If
  End Sub

#If (ctMenuA_FlagA And &H2&) = &H2& Then
  Private Sub UserControl_Terminate()
    ctMenuA_TimerCount = ctMenuA_TimerCount - 1&
    If ctMenuA_TimerCount = 0& And Not ctMenuA_TimerHWnd = 0& Then
      'Debug.Print "Killed"
      Call KillTimer(0&, ctMenuA_TimerHWnd)
      ctMenuA_TimerHWnd = 0&
      End If
    If Not hWndButton1 = 0& Then
      If hWndButton1 = ctMenuA_PressedButtonHWnd Then ctMenuA_PressedButtonHWnd = 0&
      Call SetWindowLongA(hWndButton1, -4&, hWndButton1HookOld)
      Call DestroyWindow(hWndButton1)
      hWndButton1 = 0&
      End If
    If Not hWndButton2 = 0& Then
      If hWndButton2 = ctMenuA_PressedButtonHWnd Then ctMenuA_PressedButtonHWnd = 0&
      Call SetWindowLongA(hWndButton2, -4&, hWndButton2HookOld)
      Call DestroyWindow(hWndButton2)
      hWndButton2 = 0&
      End If
    End Sub
  #End If


Private Sub UserControl_KeyDown(KeyCode As Integer, Shift As Integer)
  If Not xCount = 0& Then
    If KeyCode = 38 And Not xCurrent = 0& Then
      #If (ctMenuA_FlagA And &H4&) = &H4& Then
        ClickEvent xCurrent - 1&, 0&
        #Else
        ClickEvent xCurrent - 1&
        #End If
      End If
    If KeyCode = 40 And Not xCurrent = xCount - 1& Then
      #If (ctMenuA_FlagA And &H4&) = &H4& Then
        ClickEvent xCurrent + 1&, 0&
        #Else
        ClickEvent xCurrent + 1&
        #End If
      End If
  '  If Index = 0& And Not xPage = 0& Then SetPage xPage - 1&, False
  '  If Index = 1& And Not xPage = xCount - xPages Then SetPage xPage + 1&, False
    #If (ctMenuA_FlagA And &H2&) = &H2& Then
      If KeyCode = 33& And Not xPage = 0& Then SetPage xPage - 1&, False
      If KeyCode = 34& And Not xPage = xCount - xPages Then SetPage xPage + 1&, False
      #End If
    End If
  End Sub

#If (ctMenuA_FlagA And &H4&) = &H4& Then
  Private Sub UserControl_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then ClickEvent xCurrent, 4&
    End Sub
  #End If

#If (ctMenuA_FlagA And &H4&) = &H4& Then
  Private Sub UserControl_KeyUp(KeyCode As Integer, Shift As Integer)
    If KeyCode = 93 Then
      ClickEvent xCurrent, 2&
      End If
    End Sub
  #End If

Private Sub UserControl_Resize()
Dim xLong1 As Long
Dim xLong2 As Long

  #If (ctMenuA_FlagA And &H2&) = &H2& Then
    CheckPaging
    #End If
  xLong2 = UserControl.ScaleWidth
  
  ePic(0).Left = (xLong2 - xSpaceIHeight) / 2&
  eLabel(0).Left = xSpaceTLeft
  eLabel(0).Width = xLong2 - xSpaceTWidth
  For xLong1 = 1& To xCount - 1&
    ePic(xLong1).Left = (xLong2 - xSpaceIHeight) / 2&
    eLabel(xLong1).Left = xSpaceTLeft
    eLabel(xLong1).Width = xLong2 - xSpaceTWidth
    Next

  #If (ctMenuA_FlagA And &H2&) = &H2& Then
    eButton0Top = xSpaceBTop
    xLong2 = xLong2 - eButtonWidth - xSpaceBRight
    eButtonLeft = xLong2
    eButton1Top = UserControl.ScaleHeight - eButtonHeight - xSpaceBBottom
    If Not hWndButton1 = 0& Then
      'setwindowpos
      Call SetWindowPos(hWndButton1, 0&, eButtonLeft, eButton0Top, 0&, 0&, &H215&)
      End If
    If Not hWndButton2 = 0& Then
      Call SetWindowPos(hWndButton2, 0&, eButtonLeft, eButton1Top, 0&, 0&, &H215&)
      End If
    
    #ElseIf (ctMenuA_FlagA And &HF00&) > 0 Then
    AlignItems
    #End If
  End Sub

#If (ctMenuA_FlagA And &H2&) = &H2& Then
  Private Sub CheckPaging()
    Dim xLong1 As Long
    
    xLong1 = (UserControl.ScaleHeight - xSpaceTHeight) \ (xSpaceTHeight + xSpaceGen + xSpaceIHeight)
    If xLong1 > xCount Then
      xPages = xCount
      Else
      If xLong1 < 2& Then
        xPages = 1&
        Else
        xPages = xLong1
        End If
      End If
    
    If xPages < xCount Then
      If xPage + xPages > xCount Then
        SetPage xCount - xPages, False
        End If
      Else
      SetPage 0&, False
      End If
    
    CheckButtons
    #If (ctMenuA_FlagA And &HF00&) > 0 Then
      If xPage = 0& And xPage = (xCount - xPages) Then
        xAutoAligned = True
        AlignItems
        ElseIf xAutoAligned Then
        xAutoAligned = False
        UserControl_Resize
        End If
      #End If
    End Sub
  
  Private Sub SetPage(ByVal Page As Long, ByVal Force As Boolean)
    Dim xLong1 As Long
    Dim xLong2 As Long
    
    If Not Page = xPage Or Force Then
      xPage = Page
      For xLong1 = 0& To xCount - 1&
        xLong2 = (xSpaceTHeight + xSpaceGen + xSpaceIHeight) * (xLong1 - xPage) + xSpaceGen '78
        ePic(xLong1).Top = xLong2
        eLabel(xLong1).Top = xLong2 + xSpaceIHeight
        Next
      End If
    CheckButtons
    End Sub
  
  Private Sub CheckButtons()
    If xPage = 0& Then
      If Not hWndButton1 = 0& Then
        If hWndButton1 = ctMenuA_PressedButtonHWnd Then ctMenuA_PressedButtonHWnd = 0&
        Call SetWindowLongA(hWndButton1, -4&, hWndButton1HookOld)
        Call DestroyWindow(hWndButton1)
        hWndButton1 = 0&
        End If
      ElseIf hWndButton1 = 0& Then
'Const BS_TOP As Long = &H400&
'Const BS_BOTTOM As Long = &H800&
#If (ctMenuA_FlagB And &H8&) = &H8& Then
      If xFlButtons Then
        hWndButton1 = CreateWindowExA(4&, "BUTTON", "...", &H5000840B, eButtonLeft, eButton0Top, eButtonWidth, eButtonHeight, UserControl.hWnd, 0&, CLng(App.hInstance), 0&)
        Else
#End If
        hWndButton1 = CreateWindowExA(4&, "BUTTON", "...", &H5000040B, eButtonLeft, eButton0Top, eButtonWidth, eButtonHeight, UserControl.hWnd, 0&, CLng(App.hInstance), 0&)
#If (ctMenuA_FlagB And &H8&) = &H8& Then
        End If
#End If
      If Not hWndButton1 = 0& Then
        hWndButton1HookOld = SetWindowLongA(hWndButton1, -4&, AddressOf ctMenuA_ButtonHookProc)
        Call SetWindowLongA(hWndButton1, -21&, hWndButton1HookOld)
        End If
      End If
    
    If xCount = 0& Then
      If Not hWndButton1 = 0& Then
        If hWndButton2 = ctMenuA_PressedButtonHWnd Then ctMenuA_PressedButtonHWnd = 0&
        Call SetWindowLongA(hWndButton2, -4&, hWndButton2HookOld)
        Call DestroyWindow(hWndButton2)
        hWndButton1 = 0&
        End If
      Else
      If (xPage = (xCount - xPages)) Then
        If Not hWndButton2 = 0& Then
          If hWndButton2 = ctMenuA_PressedButtonHWnd Then ctMenuA_PressedButtonHWnd = 0&
          Call SetWindowLongA(hWndButton2, -4&, hWndButton2HookOld)
          Call DestroyWindow(hWndButton2)
          hWndButton2 = 0&
          End If
        ElseIf hWndButton2 = 0& Then
#If (ctMenuA_FlagB And &H8&) = &H8& Then
        If xFlButtons Then
          'hWndButton2 = CreateWindowExA(0&, "BUTTON", "...", &H50008000, 0&, 0&, 50&, 16&, hwnd, 0&, CLng(App.hInstance), 0&)
          hWndButton2 = CreateWindowExA(0&, "BUTTON", "...", &H5000880B, eButtonLeft, eButton1Top, eButtonWidth, eButtonHeight, UserControl.hWnd, 0&, CLng(App.hInstance), 0&)
          Else
#End If
          'hWndButton2 = CreateWindowExA(0&, "BUTTON", "...", &H50000000, 0&, 0&, 50&, 16&, hwnd, 0&, CLng(App.hInstance), 0&)
          hWndButton2 = CreateWindowExA(0&, "BUTTON", "...", &H5000080B, eButtonLeft, eButton1Top, eButtonWidth, eButtonHeight, UserControl.hWnd, 0&, CLng(App.hInstance), 0&)
#If (ctMenuA_FlagB And &H8&) = &H8& Then
          End If
#End If
        If Not hWndButton2 = 0& Then
          hWndButton2HookOld = SetWindowLongA(hWndButton2, -4&, AddressOf ctMenuA_ButtonHookProc)
          Call SetWindowLongA(hWndButton2, -21&, hWndButton2HookOld)
          End If
        End If
      End If
    End Sub
  #End If


#If (ctMenuA_FlagA And &HF00&) > 0 Then
  Private Sub AlignItems()
    Dim xLong1 As Long
    Dim xLong2 As Long
    Dim xLong3 As Long
    Dim xLong4 As Long

    #If (ctMenuA_FlagA And &H100&) = &H100& Then
      xLong4 = xSpaceGen
      If xCount > 1& Then
        xLong3 = (UserControl.ScaleHeight - 2& * xSpaceGen - xSpaceIHeight - xSpaceTHeight) \ (xCount - 1&)
        End If
      #Else
      #If (ctMenuA_FlagA And &H200&) = &H200& Then
        If Not xCount = 0& Then
          xLong3 = (UserControl.ScaleHeight - xCount * (xSpaceIHeight + xSpaceTHeight)) \ (xCount)
          End If
        xLong4 = xLong3 \ 2&
        xLong3 = xLong3 + (xSpaceIHeight + xSpaceTHeight)
        #End If
      #End If
    
    
    If xLong3 < (xSpaceIHeight + xSpaceTHeight) Then
      xLong3 = (xSpaceIHeight + xSpaceTHeight)
      End If
    If xLong4 < 0& Then xLong4 = 0&
    
    For xLong1 = 0& To xCount - 1&
      xLong2 = xLong3 * xLong1 + xLong4 '+ xSpaceGen
      ePic(xLong1).Top = xLong2
      eLabel(xLong1).Top = xLong2 + xSpaceIHeight
      Next

'Select Case xAlignMode
'  Case 0
'    xLong4 = xSpaceGen
'    xLong3 = (xSpaceTHeight + xSpaceGen + xSpaceIHeight)
'  Case 1
'    xLong3 = (xSpaceTHeight + xSpaceGen + xSpaceIHeight)
'    xLong4 = (UserControl.ScaleHeight - xCount * xLong3) \ 2
'  Case 2
'    xLong4 = xSpaceGen
'    xLong3 = (UserControl.ScaleHeight - (xCount + 2) * xSpaceGen) \ (xCount - 1)
'  End Select
'For xLong1 = 0 To xCount - 1
'  xLong2 = xLong3 * xLong1 + xLong4 '+ xSpaceGen
'  ePic(xLong1).Top = xLong2
'  eLabel(xLong1).Top = xLong2 + xSpaceIHeight
'  Next
    End Sub
  #End If






#If (ctMenuA_FlagB And &H1&) = &H1& Then
  Public Property Let TextHeight(ByVal Height As Long)
    If Not xSpaceTHeight = Height Then
      xSpaceTHeight = Height
      UserControl_Resize
      '#If (ctMenuA_FlagA And &H2&) = &H2& Then
      '  CheckPaging
      '  #ElseIf (ctMenuA_FlagA And &HF00&) > 0 Then
      '  AlignItems
      '  #End If
      End If
    End Property
  #End If

#If (ctMenuA_FlagB And &H4&) = &H4& Then
  Public Sub SetFontFlag(ByVal Index As Long, ByVal FontFlags As Long, Optional ByVal NewColor As Long = -1&)
    If Index < xCount Then
      eLabel(Index).FontBold = (Not (FontFlags And &H1&) = 0&)
      eLabel(Index).FontItalic = (Not (FontFlags And &H2&) = 0&)
      eLabel(Index).FontUnderline = (Not (FontFlags And &H2&) = 0&)
      'if (Not (FontFlags And &H2&) = 0&)
      If Not NewColor = -1& Then
        eLabel(Index).ForeColor = NewColor
        End If
      End If
    End Sub
  #End If


#If (ctMenuA_FlagB And &H8&) = &H8& And (ctMenuA_FlagA And &H2&) = &H2& Then
  Public Property Let FlatButtons(ByVal NewValue As Boolean)
'    Dim xType1 As RECT
    
    If Not xFlButtons = NewValue Then
      xFlButtons = NewValue
      If xFlButtons Then
        If Not hWndButton1 = 0& Then
          Call SetWindowLongA(hWndButton1, -16, GetWindowLongA(hWndButton1, -16) Or &H8000&)
          Call SendMessageA(hWndButton1, 15&, 0&, ByVal 0&)
          End If
        If Not hWndButton2 = 0& Then
          Call SetWindowLongA(hWndButton2, -16, GetWindowLongA(hWndButton2, -16) Or &H8000&)
          Call SendMessageA(hWndButton2, 15&, 0&, ByVal 0&)
          End If
        Else
        If Not hWndButton1 = 0& Then
          Call SetWindowLongA(hWndButton1, -16, GetWindowLongA(hWndButton1, -16) And Not &H8000&)
          Call SendMessageA(hWndButton1, 15&, 0&, ByVal 0&)
          End If
        If Not hWndButton2 = 0& Then
          Call SetWindowLongA(hWndButton2, -16, GetWindowLongA(hWndButton2, -16) And Not &H8000&)
          Call SendMessageA(hWndButton2, 15&, 0&, ByVal 0&)
          End If
        End If
      End If
    End Property
  #End If








' Especially designed for speed/size issues for QuickTask, this procedure adds / removes last item (1 item)
' No key support
' Always (Un)selects last item as used for QuickTask only
#If (ctMenuA_FlagB And &H1000&) = &H1000& Then
  Public Sub AddItemExQT()
    Dim xLong1 As Long
    Load ePic(xCount)
    Load eLabel(xCount)
    xLong1 = (xSpaceTHeight + xSpaceGen + xSpaceIHeight) * (xCount - xPage) + xSpaceGen
    ePic(xCount).Top = xLong1
    eLabel(xCount).Top = xLong1 + xSpaceIHeight
    Highlight xCurrent, False
    xCurrent = xCount
    xCount = xCount + 1&
    Highlight xCurrent, True
    ePic(xCount - 1&).Visible = True
    eLabel(xCount - 1&).Visible = True
    CheckPaging
    End Sub
  
  Public Sub RemoveItemExQT()
    Unload ePic(xCount - 1&)
    Unload eLabel(xCount - 1&)
    xCount = xCount - 1&
    xCurrent = xCount - 1&
    Highlight xCurrent, True
    CheckPaging
    End Sub
  #End If


#If (ctMenuA_FlagB And &H100&) = &H100& Then
  Public Property Let Enabled(NewState As Long)
    UserControl.Enabled = ((NewState And &H1&) = 0&)
    'usercontrol
    End Property
  #End If


'Private Function SetWindowLongA(hwnd as Long, param as Long , value as Long ) as lon
'
'End Function
