Tipp for "Firefly Visual Designer" Users and Listview-Header Problem

Started by Theo Gottwald, February 17, 2024, 09:48:00 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Theo Gottwald

Before:
LV0.png
After:
LV1.png


🔥🔍📝👨�💻
Nach vielen Jahren ist Firefly nicht mehr offiziell unterstützt, aber es gibt immer noch Nutzer, die wie ich den Firefly Visual Designer verwenden. In meinem letzten Projekt habe ich ein Problem mit Firefly und ListView entdeckt. Ich weiß nicht, warum das passiert. Das Problem kannst du auf den beiden beigefügten Bildern sehen. Unten findest du den Code, um dieses Problem zu lösen. 💡👀📷

👨�💻🔥🔍📝
Even after many years are gone and Firefly is not more officially supported, there may be other users out there who also still use Firefly Visual Designer as I do. Now in my last project I have found a problem with Firefly and ListView. I don't know why this happens. You can see the problem in the two attached pictures. And you find the code to solve this problem below.

'-----------------------------------------------------------------------------------

Sub SetupListView(ByVal hListView As Dword)
    Local lvc As LV_COLUMN
    Local lExStyle As Dword
    Local S01 As String
   
    FF_ListView_DeleteAllItems( hListView )
    FF_ListView_DeleteAllColumns( hListView )
   
    S01="No."
    FF_ListView_InsertColumn( hListView, 0, S01, %LVCFMT_CENTER, 60 )
    S01="Beschreibung"
    FF_ListView_InsertColumn( hListView, 1, S01, %LVCFMT_CENTER, 200 )
    S01="Wert"
    FF_ListView_InsertColumn( hListView, 2, S01, %LVCFMT_CENTER, 340 )
     MoveListViewHeader(hListView)   
End Sub

'--------------------------------------------------------------------------------------------------------

Sub MoveListViewHeader(ByVal hListView As Dword)
    Local hHeader As Dword
    Local rcHeader As Rect
    Local PA As PointApi ' POINTAPI should be a structure that matches the POINT structure
    Local hWndParent As Dword

    ' Send LVM_GETHEADER message to get the header control handle
    hHeader = SendMessage(hListView, %LVM_GETHEADER, 0, 0)

    MoveWindowRelative(hHeader,1,-1)
End Sub
'-----------------------------------------------------------------------------------
' This subroutine moves a specified child window by deltaX and deltaY
Sub MoveWindowRelative(ByVal U01 As Dword, ByVal deltaX As Long, ByVal deltaY As Long)
    Local rc As Rect
    Local flags As Dword
   
    ' Get current position of the window
    GetWindowRect U01, rc
   
    ' Convert screen coordinates to client coordinates for the parent window
    MapWindowPoints %HWND_DESKTOP, GetParent(U01), ByVal VarPtr(rc), 2
   
    ' Prepare flags - we're not changing the size of the window, just the position
    flags = %SWP_NOZORDER Or %SWP_NOSIZE
   
    ' Move the window using the new coordinates
    SetWindowPos U01, 0, rc.nLeft + deltaX, rc.nTop + deltaY, 0, 0, flags
End Sub
'-----------------------------------------------------------------------------------

Theo Gottwald

There are additional Subprogram needed, if you want to use the Scrollbar for the Listview.

%SB_HORZ = 0
%SB_VERT = 1


'-----------------------------------------------------------------------------------
' This subroutine moves a specified child window by deltaX and deltaY
Sub Init_Pos_HLV1(ByVal U01 As Dword, ByVal deltaX As Long, ByVal deltaY As Long)
    Local rc As Rect
    Local flags As Dword
    Local x,y As Long
    Local hHeader As Long
        ' Send LVM_GETHEADER message to get the header control handle
    hHeader = SendMessage(U01, %LVM_GETHEADER, 0, 0)
    g_Headera=hHeader
   
    ' Get current position of the window
    GetWindowRect hHeader, rc
   
    ' Convert screen coordinates to client coordinates for the parent window
    MapWindowPoints %HWND_DESKTOP, GetParent(hHeader), ByVal VarPtr(rc), 2
   
    ' Prepare flags - we're not changing the size of the window, just the position
    flags = %SWP_NOZORDER Or %SWP_NOSIZE
   
    x=rc.nLeft + deltaX
    y=rc.nTop + deltaY
    g_hlvax=x:g_hlvay=y
End Sub
'-----------------------------------------------------------------------------------
Function FF_ListView_GetHScrollPos (ByVal hWndControl As Dword) As Long
   G_REG
   R01 = GetScrollPos(hWndControl, %SB_HORZ)
   Function=R01
End Function
'-----------------------------------------------------------------------------------
Function FF_ListView_GetVScrollPos (ByVal hWndControl As Dword) As Long
   G_REG
   R01 = GetScrollPos(hWndControl, %SB_VERT)
   Function=R01
End Function
'-----------------------------------------------------------------------------------
' This subroutine moves a specified child window by deltaX and deltaY
Sub MoveHeader_L1()
    Local flags As Dword
    Local x As Long   
   
    x =FF_ListView_GetHScrollPos(HWND_TAB1_TALIST1)
   
    ' Prepare flags - we're not changing the size of the window, just the position
    flags = %SWP_NOZORDER Or %SWP_NOSIZE
   
   
    ' Move the window using the new coordinates
    SetWindowPos g_Headera, 0,g_hlvax-x,g_hlvay, 0, 0, flags
End Sub

'--------------------------------------------------------------------------------
' The following Firefly Procedures need to call the LV-Repair FUnction.
'--------------------------------------------------------------------------------
Function TAB1_TALIST1_LVN_ITEMCHANGED ( _
                                      ControlIndex  As Long,            _  ' index in Control Array
                                      hWndForm      As Dword,           _  ' handle of Form
                                      hWndControl   As Dword,           _  ' handle of Control
                                      ByVal lpNMV   As NM_LISTVIEW Ptr  _  ' pointer to NM_LISTVIEW
                                      ) As Long
                           MoveHeader_L1()
End Function


'--------------------------------------------------------------------------------
Function TAB1_TALIST1_WM_SIZE ( _
                              ControlIndex  As Long,  _  ' index in Control Array
                              hWndForm      As Dword, _  ' handle of Form
                              hWndControl   As Dword, _  ' handle of Control
                              fwSizeType    As Long,  _  ' type of resizing request
                              nWidth        As Long,  _  ' new width of client area
                              nHeight       As Long   _  ' new height of client area
                              ) As Long
                         MoveHeader_L1()     
End Function


'--------------------------------------------------------------------------------
Function TAB1_TALIST1_WM_PAINT ( _
                               ControlIndex  As Long,  _  ' index in Control Array
                               hWndForm      As Dword, _  ' handle of Form
                               hWndControl   As Dword  _  ' handle of Control
                               ) As Long
                               Sleep(10)
                          MoveHeader_L1()                             
End Function



Theo Gottwald

To get the Item-Data/Item that is just being selected in a Listview in Firefly into global var: "g_LVB_Sel".

Function TAB2_TBLV_LVN_ITEMCHANGED ( _
                                        ControlIndex  As Long,            _  ' index in Control Array
                                        hWndForm      As Dword,           _  ' handle of Form
                                        hWndControl   As Dword,           _  ' handle of Control
                                        ByVal lpNMV   As NM_LISTVIEW Ptr  _  ' pointer to NM_LISTVIEW
                                        ) As Long
    G_REG   
    ' Extract NM_LISTVIEW structure from pointer
    Dim lvInfo As NM_LISTVIEW
    lvInfo = @lpNMV   
    ' Check if the change is related to the item's selection state
    If (lvInfo.uChanged And %LVIF_STATE) Then
        ' Determine if the item is now selected
        If (lvInfo.uNewState And %LVIS_SELECTED) And Not (lvInfo.uOldState And %LVIS_SELECTED) Then
            ' The item has just been selected
            R01 = lvInfo.iItem ' Index of the newly selected item
            g_LVB_Sel = FF_ListView_GetItemlParam(hWndControl, R01, 0) ' Retrieve lParam value for the selected item                     
        End If
    End If
 ' Repair_L2()       
End Function