ListView_Ex.Pbi version 1.0

Partagez votre expérience de PureBasic avec les autres utilisateurs.
Avatar de l’utilisateur
celtic88
Messages : 309
Inscription : sam. 12/sept./2015 14:31
Localisation : Alger

ListView_Ex.Pbi version 1.0

Message par celtic88 »

Salut tout le monde j espère que vous allez bien :D
voici un inclue de Pb pour le contrôle "Listview System" qui permet de travailler avec en En toute simplicité .
avec vous pouvez ajouter ou modifier les items le "drag and drop' le "sort" des items l ajoute d un "progress bar" et plein d autre chose ...
amusez vous bien :P

image

Image

ListView_Ex.Pbi

Code : Tout sélectionner

; EnableExplicit

;Author Celtic88

#HDS_CHECKBOXES = $00000400
#HDF_CHECKBOX=$00000040
#HDN_ITEMSTATEICONCLICK = -316
#HDF_CHECKED=$00000080
#HDF_FIXEDWIDTH = $00000100
#PBM_SETBKCOLOR = $2000 + 1
#PBM_SETBARCOLOR = #WM_USER + 9
#LVIM_AFTER=$00000001

Structure LVINSERTMARK
  Size.l
  Flags.l
  Item.l
  Reserved.l
EndStructure

Structure ListView_SortInfo
  LvHwnd.i
  Colindex.i
  Lv_SortDu.b
EndStructure

Structure ListView_ProgressBar
  LvHwnd.i
  PgsHwnd.i
  sItemIndex.i
  sSubItemIndex.b
EndStructure

Global Dim ListView_ProgressBar_iAr.ListView_ProgressBar(0)

Procedure _Add_Window_Style(Hwnd,Isteyle)
  Protected Getstyle = GetWindowLong_(Hwnd, #GWL_STYLE)
  If (Getstyle& Isteyle) <> Isteyle
    SetWindowLong_(Hwnd, #GWL_STYLE, Getstyle | Isteyle)
  EndIf
EndProcedure

Procedure ListView_SetGroup(hWnd, text.s, groupid, INSERTGROUP.b=1)
  Protected lvg.LVGROUP
  lvg\cbSize = SizeOf(LVGROUP)
  lvg\mask = #LVGF_ALIGN | #LVGF_HEADER | #LVGF_STATE
  lvg\uAlign = #LVGA_HEADER_LEFT
;   lvg\state=#LVGS_COLLAPSIBLE
  lvg\pszHeader = @text
  lvg\cchHeader=Len(text)
  If INSERTGROUP
    lvg\mask | #LVGF_GROUPID
    lvg\iGroupId = groupid
    ProcedureReturn SendMessage_ (hWnd, #LVM_INSERTGROUP, -1, @lvg)
  Else
    SendMessage_ (hWnd, #LVM_SETGROUPINFO, groupid, @lvg)
    lvg\mask = #LVGF_GROUPID
    lvg\iGroupId = groupid
    SendMessage_ (hWnd, #LVM_SETGROUPINFO, 0, @lvg)
  EndIf
EndProcedure

Procedure.s ListView_GetItemText(hWnd, iIndex, iSubItem = 0)
  Protected tItem.LVITEM
  tItem\iSubItem=iSubItem
  Protected Gettxt.s=Space(1024)
  tItem\pszText=@Gettxt
  tItem\cchTextMax=1024
  If SendMessage_(hWnd, #LVM_GETITEMTEXT, iIndex, @tItem)
    ProcedureReturn Gettxt
  EndIf
EndProcedure

Procedure ListView_EnableGroupView(hWnd, state.b)
  SendMessage_ (hWnd, #LVM_ENABLEGROUPVIEW, state, 0)
EndProcedure

Procedure ListView_FINDItemPar(hWnd, i_Param, Istart = -1)
  Protected tFindInfo.LV_FINDINFO
  tFindInfo\flags = #LVFI_PARAM
  tFindInfo\lParam = i_Param
  ProcedureReturn SendMessage_(hWnd, #LVM_FINDITEM, Istart, tFindInfo)
EndProcedure

Procedure ListView_ItemIsSelected(hWnd, iIndex)
  ProcedureReturn SendMessage_(hWnd, #LVM_GETITEMSTATE, iIndex, #LVIS_SELECTED) 
EndProcedure

Procedure ListView_GetItemCount(hWnd)
  ProcedureReturn SendMessage_(hWnd, #LVM_GETITEMCOUNT, 0, 0) -1
EndProcedure

Procedure ListView_ItemISITEMVISIBLE(hWnd, iIndex)
  ProcedureReturn SendMessage_(hWnd, #LVM_ISITEMVISIBLE, iIndex,0)
EndProcedure

Procedure ListView_GETSELECTEDCOUNT(hWnd)
  ProcedureReturn SendMessage_(hWnd, #LVM_GETSELECTEDCOUNT, 0, 0)
EndProcedure

Procedure ListView_GetSelectedItem(hWnd)
  ProcedureReturn SendMessage_(hWnd, #LVM_GETNEXTITEM, -1, #LVNI_SELECTED)
EndProcedure

Procedure ListView_SetView(hWnd,iView)
  ProcedureReturn SendMessage_(hWnd, #LVM_SETVIEW, iView, 0)
EndProcedure

Procedure ListView_EnsureVisible(hWnd,iIndex,fPartialOK = #False)
  ProcedureReturn SendMessage_(hWnd, #LVM_ENSUREVISIBLE, iIndex, fPartialOK)
EndProcedure

Procedure ListView_SetItemSelected(hWnd, iIndex)
  Protected tItem.LVITEM
  tItem\mask=#LVIF_STATE
  tItem\iItem=iIndex
  tItem\state=#LVIS_SELECTED | #LVIS_FOCUSED
  tItem\stateMask=#LVIS_SELECTED | #LVIS_FOCUSED
  ProcedureReturn SendMessage_(hWnd, #LVM_SETITEMSTATE, iIndex, @tItem)
EndProcedure

Procedure ListView_GetItemImage(hWnd, iIndex,iSubitem=0)
  Protected tItem.LVITEM
  tItem\mask=#LVIF_IMAGE
  tItem\iItem=iIndex
  tItem\iSubItem=iSubitem
  SendMessage_(hWnd, #LVM_GETITEM, 0, @tItem)
  ProcedureReturn tItem\iImage
EndProcedure

Procedure ListView_GetItemChecked(hWnd, iIndex)
  Protected tItem.LVITEM
  tItem\mask=#LVIF_STATE
  tItem\iItem=iIndex
  tItem\stateMask=$ffff
  SendMessage_(hWnd, #LVM_GETITEM, 0, @tItem)
  ProcedureReturn Bool((tItem\state & $2000) <> 0)
EndProcedure

Procedure ListView_SETIMAGELIST(hWnd,hImagelist,Imstyle)
  SendMessage_(hWnd, #LVM_SETIMAGELIST, Imstyle, hImagelist)
EndProcedure

Procedure ListView_DELETEALLITEMS(hWnd)
  SendMessage_(hWnd, #LVM_DELETEALLITEMS, 0, 0)
EndProcedure

Procedure ListView_DELETEITEM(hWnd, iIndex)
  SendMessage_(hWnd, #LVM_DELETEITEM, iIndex, 0)
EndProcedure

Procedure Header_GetItemFormat(hWnd, iIndex)
  Protected tItem.HDITEM
  tItem\mask=#HDI_FORMAT
  SendMessage_(hWnd, #HDM_GETITEM, iIndex, @tItem)
  ProcedureReturn tItem\fmt
EndProcedure

Procedure Header_SetItemFormat(hWnd, iIndex,iFORMAT)
  Protected tItem.HDITEM
  tItem\mask=#HDI_FORMAT
  tItem\fmt=iFORMAT
  ProcedureReturn SendMessage_(hWnd, #HDM_SETITEM, iIndex, @tItem)
EndProcedure

Procedure Header_SetItemOrder(hWnd, iIndex,iOrder)
  Protected tItem.HDITEM
  tItem\mask=$00000080
  tItem\iOrder=iOrder
  ProcedureReturn SendMessage_(hWnd, #HDM_SETITEM, iIndex, @tItem)
EndProcedure

Procedure Header_GETITEMCOUNT(hwnd)
  ProcedureReturn SendMessage_(hwnd, #HDM_GETITEMCOUNT,0,0)
EndProcedure

Procedure ListView_SetItemChecked(hWnd, iIndex, fCheck.b = 1)
  Protected tItem.LVITEM
  tItem\mask=#LVIF_STATE
  If fCheck
    tItem\state = $2000
  Else
    tItem\state = $1000
  EndIf
  tItem\stateMask=$f000
  If iIndex = -1
    Protected mo
    For mo= 0 To ListView_GetItemCount(hWnd)
      tItem\iItem=mo
      SendMessage_(hWnd, #LVM_SETITEM, 0, @tItem)
    Next
  Else
    tItem\iItem=iIndex
    ProcedureReturn  SendMessage_(hWnd, #LVM_SETITEM, 0, @tItem)
  EndIf
EndProcedure

Procedure ListView_GetItemParam(hWnd, iItem)
  Protected itm.LVITEM
  itm\mask = #LVIF_PARAM
  itm\iItem=iItem
  SendMessage_(hWnd, #LVM_GETITEM, 0, @itm)
  ProcedureReturn itm\lParam
EndProcedure

Procedure ListView_GetItemiDGroup(hWnd, iItem)
  Protected itm.LVITEM
  itm\mask = #LVIF_GROUPID
  itm\iItem=iItem
  SendMessage_(hWnd, #LVM_GETITEM, 0, @itm)
  ProcedureReturn itm\iGroupId
EndProcedure

Procedure ListView_GetGroupeCountItem(hWnd,GROUPID)
  Protected i,Cgi
  For i=0 To ListView_GetItemCount(hWnd)
    If ListView_GetItemiDGroup(hWnd, i) = GROUPID
      Cgi +1
    EndIf
  Next
  ProcedureReturn Cgi
EndProcedure

Procedure ListView_SetItemImage(hWnd,iItem,iSubItem,Imagein)
  Protected itm.LVITEM
  itm\mask = #LVIF_IMAGE
  itm\iImage=Imagein
  itm\iItem=iItem
  itm\iSubItem=iSubItem
  ProcedureReturn SendMessage_ (hWnd, #LVM_SETITEM, 0, @itm)
EndProcedure

Procedure ListView_SetItemText(hWnd, iItem,iSubItem,text.s)
  Protected itm.LVITEM
  itm\mask = #LVIF_TEXT
  itm\pszText = @text
  itm\cchTextMax=Len(text)
  itm\iItem=iItem
  itm\iSubItem=iSubItem  
  ProcedureReturn SendMessage_ (hWnd, #LVM_SETITEM, 0, @itm)
EndProcedure

Procedure ListView_AddSubItem(hWnd, iItem,iSubItem,text.s,Imagein=-1)
  Protected itm.LVITEM
  itm\mask = #LVIF_TEXT
  itm\pszText = @text
  itm\cchTextMax=Len(text)
  If Imagein <> -1
    itm\mask | #LVIF_IMAGE
    itm\iImage=Imagein
  EndIf
  itm\iItem=iItem
  itm\iSubItem=iSubItem
  ProcedureReturn SendMessage_ (hWnd, #LVM_SETITEM, 0, @itm)
EndProcedure

Procedure ListView_AddItem(hWnd,text.s,groupid=-1,Li_Param=-1,Imagein=-1,INSERIndex=-1)
  Protected itm.LVITEM
  itm\mask = #LVIF_TEXT
  itm\pszText = @text
  itm\state=#LVIS_DROPHILITED
  itm\cchTextMax=Len(text)
  If Imagein <> -1
    itm\mask | #LVIF_IMAGE
    itm\iImage=Imagein
  EndIf
  If groupid <> -1  
    itm\mask | #LVIF_GROUPID 
    itm\iGroupId = groupid
  EndIf
  If Li_Param <> -1
    itm\mask | #LVIF_PARAM
    itm\lParam=Li_Param
  EndIf
  If  INSERIndex <> -1
    itm\iItem=INSERIndex
  Else
    itm\iItem=ListView_GetItemCount(hWnd)+1
  EndIf
  ProcedureReturn SendMessage_ (hWnd, #LVM_INSERTITEM, 0, @itm)
EndProcedure

Procedure ListView_InsertColumn(hwnd,index,text.s,ClWIDTH=200)
  Protected COLUMN.LVCOLUMN 
  COLUMN\mask = #LVCF_TEXT |#LVCF_WIDTH
  COLUMN\pszText = @text
  COLUMN\cx=ClWIDTH
  COLUMN\cchTextMax=Len(text)
  ProcedureReturn SendMessage_(hwnd, #LVM_INSERTCOLUMN, index, @COLUMN)
EndProcedure

Procedure ListView_SETColumn_Image(hwnd,index,inimage,BITMAP_ON_RIGHT.b=0)
  Protected COLUMN.LVCOLUMN 
  COLUMN\mask = #LVCF_IMAGE|#LVCF_FMT
  COLUMN\fmt=#LVCFMT_IMAGE|#LVCFMT_COL_HAS_IMAGES
  If BITMAP_ON_RIGHT
    COLUMN\fmt | #LVCFMT_BITMAP_ON_RIGHT
  EndIf
  COLUMN\iImage=inimage
  ProcedureReturn SendMessage_(hwnd, #LVM_SETCOLUMN, index, @COLUMN)
EndProcedure

Procedure ListView_SetColumnWidth(hwnd,iCol, iWidth)
  ProcedureReturn SendMessage_(hwnd ,#LVM_SETCOLUMNWIDTH,iCol, iWidth)
EndProcedure

Procedure ListView_GETHEADER(hwnd)
  ProcedureReturn SendMessage_(hwnd ,#LVM_GETHEADER,0,0)
EndProcedure

Procedure ListView_Getcountperpage(hwnd)
  ProcedureReturn SendMessage_(hwnd,#LVM_GETCOUNTPERPAGE,0,0)
EndProcedure

Procedure ListView_BeginUpdate(hwnd)
  ProcedureReturn SendMessage_(hwnd,$000B,0,0)
EndProcedure

Procedure ListView_EndUpdate(hwnd)
  ProcedureReturn  SendMessage_(hwnd, $000B,1,0)
EndProcedure

Procedure ListView_Create(hWnd,iX, iY , iWidth , iHeight , Style,Ex_style)
  Protected Lv_hwnd = CreateWindowEx_(#WS_EX_CLIENTEDGE ,"SysListView32","",#WS_VISIBLE | #WS_CHILD | Style,iX, iY , iWidth , iHeight,hWnd,0,GetModuleHandle_(0),0)
  SetWindowTheme_(Lv_hwnd,"EXPLORER",0)
  SendMessage_(Lv_hwnd, #LVM_SETEXTENDEDLISTVIEWSTYLE,0,Ex_style)
  InvalidateRect_(Lv_hwnd,0,1)
  ProcedureReturn Lv_hwnd
EndProcedure


Procedure ImageList_Add_FromFile(Himage, ImageFile.s,ImageType,X,Y)
  Protected ImageList_Add
  Protected LoadImag.q=LoadImage_(0,ImageFile,ImageType,X,Y,#LR_LOADFROMFILE)
  If LoadImag
    If ImageType =#IMAGE_ICON
      ImageList_Add=ImageList_ReplaceIcon_(Himage,-1,LoadImag)
      DestroyIcon_(LoadImag)
    Else
      ImageList_Add=ImageList_Add_(Himage,LoadImag,0)
      DeleteObject_(LoadImag)
    EndIf
  EndIf
  ProcedureReturn ImageList_Add
EndProcedure

Procedure Ctrl_SETFONT(Chwnd,Hfont)
  ProcedureReturn SendMessage_(Chwnd,#WM_SETFONT,Hfont,1)
EndProcedure

Procedure ListView_SetInsertMarkColor(Hwnd, iColor)
  ProcedureReturn SendMessage_(Hwnd, #LVM_SETINSERTMARKCOLOR, 0, iColor)
EndProcedure

Procedure ListView_SetInsertMark(Hwnd, iIndex,bAfter=0)
  Protected tMark.LVINSERTMARK
  tMark\Size = SizeOf(LVINSERTMARK)
  If bAfter
    tMark\Flags=#LVIM_AFTER
  EndIf
  tMark\Item=iIndex
  tMark\Reserved=0
  ProcedureReturn SendMessage_(Hwnd, #LVM_SETINSERTMARK, 0, @tMark)
EndProcedure

Procedure ListView_CreateDragImage(Hwnd, itemindex,*point.POINT)
  ProcedureReturn SendMessage_(Hwnd, #LVM_CREATEDRAGIMAGE, itemindex, *point)
EndProcedure

Procedure ListView_HitTest(Hwnd, *lhitest.LVHITTESTINFO)
  ProcedureReturn SendMessage_(Hwnd, #LVM_HITTEST, 0, *lhitest)
EndProcedure

Procedure ListView_GetItemRect(Hwnd, iIndex, *tRect.RECT)
  ProcedureReturn SendMessage_(Hwnd, #LVM_GETITEMRECT, iIndex, *tRect)
EndProcedure

Procedure ListView_GetSubItemRect(Hwnd, iIndex, *tRect.RECT)
  ProcedureReturn SendMessage_(Hwnd, #LVM_GETSUBITEMRECT, iIndex, *tRect)
EndProcedure

Procedure Progress_Create(hWnd, iX, iY, iWidth = -1, iHeight = -1, iStyle = 0, iExStyle = 0)
  iStyle|#WS_CHILD|#WS_VISIBLE
  ProcedureReturn CreateWindowEx_(iExStyle, "msctls_progress32", "", iStyle, iX, iY, iWidth, iHeight, hWnd,0,GetModuleHandle_(0),0)
EndProcedure

Procedure ListView_ProgressBarInsert(Hwnd,iItem,iSubItem=0)
  _Add_Window_Style(Hwnd,#WS_CLIPCHILDREN)
  Protected tRect.RECT
  If iSubItem=0
    tRect\left = 2
    ListView_GetItemRect(Hwnd, iItem, @tRect)
  Else
    tRect\Top = iSubItem
    tRect\left = #LVIR_LABEL
    ListView_GetSubItemRect(Hwnd, iItem, @tRect)
  EndIf
  Protected Progress_Create = Progress_Create(Hwnd, tRect\left+4, tRect\top, tRect\right-tRect\left, tRect\bottom-tRect\top-8)
  If Progress_Create
    Protected Getsizepar=ArraySize(ListView_ProgressBar_iAr())
    ReDim ListView_ProgressBar_iAr(Getsizepar+1)
    ListView_ProgressBar_iAr(Getsizepar)\LvHwnd=Hwnd
    ListView_ProgressBar_iAr(Getsizepar)\PgsHwnd=Progress_Create
    ListView_ProgressBar_iAr(Getsizepar)\sItemIndex=ListView_GetItemParam(Hwnd,iItem)
    ListView_ProgressBar_iAr(Getsizepar)\sSubItemIndex=iSubItem
  EndIf
  ProcedureReturn Progress_Create
EndProcedure

Procedure ListView_ProgressBarMove(Hwnd)
  Protected i,Trv.b,tRect.RECT,iSubItem,iItem
  Protected Getsizepar=ArraySize(ListView_ProgressBar_iAr())
  For i=0 To Getsizepar -1
    If ListView_ProgressBar_iAr(i)\LvHwnd=Hwnd
      iSubItem=ListView_ProgressBar_iAr(i)\sSubItemIndex
      iItem=ListView_FINDItemPar(Hwnd, ListView_ProgressBar_iAr(i)\sItemIndex)
      If iSubItem=0
        tRect\left = 2
        ListView_GetItemRect(Hwnd, iItem, @tRect)
      Else
        tRect\Top = iSubItem
        tRect\left = #LVIR_LABEL
        ListView_GetSubItemRect(Hwnd, iItem, @tRect)
      EndIf
      If tRect\top < 20
        ShowWindow_(ListView_ProgressBar_iAr(i)\PgsHwnd, #SW_HIDE)
      ElseIf  tRect\top >= 20
        ShowWindow_(ListView_ProgressBar_iAr(i)\PgsHwnd, #SW_SHOW)
      EndIf
      MoveWindow_(ListView_ProgressBar_iAr(i)\PgsHwnd, tRect\left, tRect\top+4, tRect\right-tRect\left, tRect\bottom-tRect\top-8, #True)
    EndIf
  Next
  InvalidateRect_(Hwnd,0,1)
EndProcedure

Procedure ListView_ProgressBarGetbyitem(Hwnd, itemPar)
  Protected i
  Protected Getsizepar=ArraySize(ListView_ProgressBar_iAr())
  For i=0 To Getsizepar -1
    If ListView_ProgressBar_iAr(i)\LvHwnd=Hwnd And  ListView_ProgressBar_iAr(i)\sItemIndex=itemPar
      ProcedureReturn ListView_ProgressBar_iAr(i)\PgsHwnd
    EndIf
  Next
EndProcedure

Procedure.b ListView_ProgressBarDeleteby(PgsHwnd)
  Protected i,Trv.b
  Protected Getsizepar=ArraySize(ListView_ProgressBar_iAr())
  For i=0 To Getsizepar -1
    If ListView_ProgressBar_iAr(i)\PgsHwnd=PgsHwnd
      Trv = 1
      Continue
    EndIf
    If Not Trv
      Continue
    EndIf
    ListView_ProgressBar_iAr(i-1)\LvHwnd=ListView_ProgressBar_iAr(i)\LvHwnd
    ListView_ProgressBar_iAr(i-1)\PgsHwnd=ListView_ProgressBar_iAr(i)\PgsHwnd
    ListView_ProgressBar_iAr(i-1)\sItemIndex=ListView_ProgressBar_iAr(i)\sItemIndex
    ListView_ProgressBar_iAr(i-1)\sSubItemIndex=ListView_ProgressBar_iAr(i)\sSubItemIndex   
  Next
  If Trv
    ReDim ListView_ProgressBar_iAr(Getsizepar-1)
    ProcedureReturn Bool(DestroyWindow_(PgsHwnd) <> 0)
  EndIf
EndProcedure

Procedure ListView_ProgressBarDeletebyItemPar(Hwnd,iItemPar)
  Protected gethwnpg=ListView_ProgressBarGetbyitem(Hwnd, iItemPar)
  While gethwnpg
    ListView_ProgressBarDeleteby(gethwnpg)
    gethwnpg=ListView_ProgressBarGetbyitem(Hwnd, iItemPar)
  Wend
EndProcedure

Procedure ProgressBar_StepIt(hWnd)
  ProcedureReturn SendMessage_(hWnd, #PBM_STEPIT, 0, 0)
EndProcedure

Procedure ProgressBar_SetStep(hWnd,iStep=10)
  ProcedureReturn SendMessage_(hWnd, #PBM_SETSTEP, iStep, 0)
EndProcedure

Procedure ProgressBar_SetBkColor(hWnd, iColor)
  ProcedureReturn SendMessage_(hWnd, #PBM_SETBKCOLOR, 0, iColor)
EndProcedure

Procedure ProgressBar_SetPos(hWnd, iPos)
  ProcedureReturn SendMessage_(hWnd, #PBM_SETPOS, iPos, 0)
EndProcedure

Procedure ProgressBar_SetBarColor(hWnd, iColor)
  ProcedureReturn SendMessage_(hWnd, #PBM_SETBARCOLOR, 0, iColor)
EndProcedure

Procedure.b ListView_Sort(ItemPar,SItemPar,*Lv_Col.ListView_SortInfo)
  Protected Index=ListView_FINDItemPar(*Lv_Col\LvHwnd, ItemPar)
  Protected IndexS=ListView_FINDItemPar(*Lv_Col\LvHwnd, SItemPar)
  Protected IndexStr.s,IndexSStr.s
  If *Lv_Col\Colindex = 0
    Protected GetItemChecked.b=ListView_GetItemChecked(*Lv_Col\LvHwnd, Index)
    Protected GetItemCheckeds.b=ListView_GetItemChecked(*Lv_Col\LvHwnd, IndexS)
    IndexStr=Str(GetItemChecked)
    IndexSStr=Str(GetItemCheckeds)
  Else
    IndexStr=ListView_GetItemText(*Lv_Col\LvHwnd, Index, *Lv_Col\Colindex)
    IndexSStr=ListView_GetItemText(*Lv_Col\LvHwnd, IndexS, *Lv_Col\Colindex)
  EndIf
  Protected nResult.b = 0
  If IndexStr < IndexSStr
    nResult = -1 
  ElseIf IndexStr > IndexSStr
    nResult = 1 
  EndIf
  nResult * *Lv_Col\Lv_SortDu
  ProcedureReturn nResult
EndProcedure

Procedure ListView_Start_Sort(hWnd,Colindex,Lv_SortDu)
  Protected LvSortInfo.ListView_SortInfo
  LvSortInfo\LvHwnd=hWnd
  LvSortInfo\Colindex=Colindex
  LvSortInfo\Lv_SortDu=Lv_SortDu
  SendMessage_(hWnd, #LVM_SETSELECTEDCOLUMN, Colindex, 0)
  InvalidateRect_(hWnd,0,1)
  SendMessage_(hWnd, #LVM_SORTITEMS, LvSortInfo, @ListView_Sort())
EndProcedure
le test ListView_Ex.Pb

Code : Tout sélectionner

XIncludeFile "ListView_Ex.Pbi"

Global Ex_Listview,Header_Ex_Listview,Imageslist_Ex_Listview,Lv_DragStarted.b,Lv_hDragImage

Procedure LoWord(value)
  ProcedureReturn value & $FFFF
EndProcedure
Procedure HiWord(value)
  ProcedureReturn value >> 16 & $FFFF
EndProcedure

Structure EnddragSubiinfo
  SubiTxt.s
  Subiimgei.i
EndStructure

Procedure _WindowCallback(hWnd, uMsg, wParam, lParam) 
  
  Select uMsg
    Case #WM_LBUTTONUP
      If Lv_DragStarted
        Lv_DragStarted = 0
        ImageList_DragLeave_(Ex_Listview)
        ImageList_EndDrag_()
        ImageList_Destroy_(Lv_hDragImage)
        ReleaseCapture_()
        ClipCursor_(0)
        ListView_SetInsertMark(Ex_Listview, -1, 1)
        Protected lhitest.LVHITTESTINFO
        lhitest\pt\x=LoWord(lParam)
        lhitest\pt\y=HiWord(lParam)
        ClientToScreen_(hWnd, @lhitest\pt);
        ScreenToClient_(Ex_Listview, @lhitest\pt);
        ListView_HitTest(Ex_Listview, @lhitest)
        If lhitest\iItem <> -1
          Protected iSelected = ListView_GetSelectedItem(Ex_Listview)
          If iSelected <> -1 And iSelected <> lhitest\iItem
            Protected isCheked = ListView_GetItemChecked(Ex_Listview, iSelected)
            Protected GetiPar = ListView_GetItemParam(Ex_Listview,iSelected)
            Protected NewList Subiinfo.EnddragSubiinfo()
            For i=1 To Header_GETITEMCOUNT(Header_Ex_Listview)
              AddElement(Subiinfo())
              Subiinfo()\SubiTxt=ListView_GetItemText(Ex_Listview,iSelected,i)
              Subiinfo()\Subiimgei=ListView_GetItemImage(Ex_Listview,iSelected,i)  
            Next
            FirstElement(Subiinfo()) 
            ListView_DELETEITEM(Ex_Listview, iSelected)
            Protected iTem=ListView_AddItem(Ex_Listview,"",0,GetiPar,999,lhitest\iItem)
            For i=1 To Header_GETITEMCOUNT(Header_Ex_Listview)
              ListView_AddSubItem(Ex_Listview, iTem,i,Subiinfo()\SubiTxt,Subiinfo()\Subiimgei)      
              NextElement(Subiinfo()) 
            Next
            FreeList(Subiinfo())
            ListView_ProgressBarMove(Ex_Listview)
            If isCheked
              ListView_SetItemChecked(Ex_Listview,iTem,1)
            EndIf
            ListView_SetItemSelected(Ex_Listview,iTem)
          EndIf
        EndIf
      EndIf

    Case #WM_MOUSEMOVE
      If Lv_DragStarted
        Protected lhitesti.LVHITTESTINFO
        lhitesti\pt\x=LoWord(lParam)
        lhitesti\pt\y=HiWord(lParam)
        ClientToScreen_(hWnd, @lhitesti\pt);
        ScreenToClient_(Ex_Listview, @lhitesti\pt);
        Protected cindex=ListView_HitTest(Ex_Listview, @lhitesti)
        ListView_SetInsertMark(Ex_Listview, cindex, 0)
        ClientToScreen_(Ex_Listview, @lhitesti\pt)
        ImageList_DragMove_(lhitesti\pt\x, lhitesti\pt\y)
      EndIf

    Case #WM_NOTIFY
      
      Protected *tNMHDR.NMHDR=lParam
      
      Select *tNMHDR\hwndFrom          
        Case Header_Ex_Listview
          Protected *NMHEADER.NMHEADER=lParam
          Protected *tItem.HDITEM=*NMHEADER\pitem
          Select *tNMHDR\code
            Case #HDN_ITEMCHANGED,#HDN_ENDDRAG
              ListView_ProgressBarMove(Ex_Listview)
              
            Case #HDN_ITEMSTATEICONCLICK
              If *tItem\mask & #HDI_FORMAT
                If *tItem\fmt & #HDF_CHECKBOX
                  Protected Cheked.b= Bool((*tItem\fmt & #HDF_CHECKED) = 0)
                  ListView_SetItemChecked(Ex_Listview, -1, Cheked)
                EndIf
              EndIf
          EndSelect
          
        Case Ex_Listview
          Protected *tInfoLv.NMLISTVIEW=lParam,ic
          
          Select *tNMHDR\code
                            
            Case #LVN_ENDSCROLL
              ListView_ProgressBarMove(Ex_Listview)
              
            Case #LVN_BEGINDRAG
              Protected point.POINT,rect.RECT
              Lv_hDragImage=ListView_CreateDragImage(Ex_Listview, *tInfoLv\iItem,@point)
              ImageList_BeginDrag_(Lv_hDragImage,0,0,0)
              ClientToScreen_(Ex_Listview,@*tInfoLv\ptAction)
              ImageList_DragEnter_(0,*tInfoLv\ptAction\x,*tInfoLv\ptAction\y)
              GetWindowRect_(Ex_Listview,@rect);
              ClipCursor_(@rect)
              SetCapture_(hWnd);
              Lv_DragStarted=1

            Case #LVN_COLUMNCLICK
              Protected iFormat ,ListView_SortDu,sCol = *tInfoLv\iSubItem
              For ic=0 To Header_GETITEMCOUNT(Header_Ex_Listview)
                iFormat =Header_GetItemFormat(Header_Ex_Listview,ic)
                If iFormat & #HDF_SORTDOWN
                  If sCol = ic
                    ListView_SortDu = -1
                  EndIf
                  Header_SetItemFormat(Header_Ex_Listview,ic,iFormat!#HDF_SORTDOWN)
                ElseIf iFormat & #HDF_SORTUP
                  If sCol = ic
                    ListView_SortDu = 1
                  EndIf
                  Header_SetItemFormat(Header_Ex_Listview,ic,iFormat!#HDF_SORTUP)
                EndIf
              Next
              
              iFormat =Header_GetItemFormat(Header_Ex_Listview,sCol)
              If ListView_SortDu = 1
                ListView_SortDu=-1
                Header_SetItemFormat(Header_Ex_Listview,sCol,iFormat|#HDF_SORTDOWN)
              Else
                ListView_SortDu=1
                Header_SetItemFormat(Header_Ex_Listview,sCol,iFormat|#HDF_SORTUP)
              EndIf
              
              ListView_Start_Sort(Ex_Listview,sCol,ListView_SortDu)
              ListView_ProgressBarMove(Ex_Listview)
              
          EndSelect
          
      EndSelect
  EndSelect
  
  ProcedureReturn #PB_ProcessPureBasicEvents 
EndProcedure

Procedure.s RandomString(len=10)
  Protected Ranstr.s,oklm
  For oklm=1 To len
    Ranstr + Chr(Random(90,64))
  Next
  ProcedureReturn Ranstr
EndProcedure

OpenWindow(0,#PB_Ignore, #PB_Ignore, 690,  330,"test ListView_Inclu_Ex")

Style=#LVS_REPORT | #LVS_SHOWSELALWAYS |#LVS_SINGLESEL
Ex_style= #LVS_EX_CHECKBOXES|#LVS_EX_SUBITEMIMAGES|#LVS_EX_BORDERSELECT|#LVS_EX_CHECKBOXES|#LVS_EX_DOUBLEBUFFER|#LVS_EX_FULLROWSELECT|#LVS_EX_HEADERDRAGDROP
Ex_Listview = ListView_Create(WindowID(0),10, 5, 670, 300,Style,Ex_style)
; ListView_EnableGroupView(Ex_Listview,1)

ListView_InsertColumn(Ex_Listview, 0, "", 40)
For i=1 To 4
  ListView_InsertColumn(Ex_Listview, i, "Col" + Str(i), 80)
Next
ListView_SetColumnWidth(Ex_Listview,4, 120)
ListView_SetColumnWidth(Ex_Listview,1, 120)

Header_Ex_Listview  = ListView_GETHEADER(Ex_Listview)
Ctrl_SETFONT(Header_Ex_Listview,LoadFont(0,"",9,#PB_FontRequester_Effects|#PB_Font_Italic ))
_Add_Window_Style(Header_Ex_Listview,#HDS_CHECKBOXES)
Header_SetItemFormat(Header_Ex_Listview,0,Header_GetItemFormat(Header_Ex_Listview,0)|#HDF_CHECKBOX|#HDF_FIXEDWIDTH)

Imageslist_Ex_Listview = ImageList_Create_(50,50,#ILC_COLOR32|#ILC_MASK,1,1)

ListView_SETIMAGELIST(Ex_Listview,Imageslist_Ex_Listview,#LVSIL_SMALL)
ListView_SetView(Ex_Listview,#LV_VIEW_DETAILS)

Grouppid=0
ListView_SetGroup(Ex_Listview, "", Grouppid)
For i=1 To 40
  iTem=ListView_AddItem(Ex_Listview,"",Grouppid,i,999)
  For ii=1 To 3
    ListView_AddSubItem(Ex_Listview, iTem,ii,RandomString(15)+Str(i+ii))       
  Next
  ProgressBar_SetPos(ListView_ProgressBarInsert(Ex_Listview,iTem,4),Random(100,0))
Next
ProgressBar_Ex_Listview0=ListView_ProgressBarInsert(Ex_Listview,0,3)
ListView_SetGroup(Ex_Listview,Str(ListView_GetGroupeCountItem(Ex_Listview,Grouppid))+ " item", Grouppid,0)

SetWindowCallback(@_WindowCallback() ,0)


SetWindowTheme_(ListView_ProgressBarGetbyitem(Ex_Listview, 1),"","")
ProgressBar_SetBkColor(ListView_ProgressBarGetbyitem(Ex_Listview, 1),RGB(Random(255), Random(255), Random(255)))
ProgressBar_SetBarColor(ListView_ProgressBarGetbyitem(Ex_Listview, 1),RGB(Random(255), Random(255), Random(255)))

Getipar=ListView_GetItemParam(Ex_Listview, 2)
ListView_DELETEITEM(Ex_Listview, 2)
ListView_ProgressBarDeletebyItemPar(Ex_Listview,Getipar)
ListView_ProgressBarMove(Ex_Listview)

ListView_SetInsertMarkColor(Ex_Listview, $000000FF)

For op=0 To ListView_GetItemCount(Ex_Listview)
  CreateImage(0, 50,50, 32)
  StartDrawing(ImageOutput(0))
  Box(0,0, 50,50,RGB(Random(255), Random(255), Random(255)))
  Ellipse(25,25, 25,25, RGB(Random(255), Random(255), Random(255)))
  StopDrawing()
  imgin=ImageList_Add_(Imageslist_Ex_Listview,ImageID(0),0)
  ListView_SetItemImage(Ex_Listview,op,1,imgin)
  ListView_SetItemImage(Ex_Listview,op,2,imgin)
  FreeImage(0)
Next

AddWindowTimer(0, 600, 900)

Repeat
  Event = WaitWindowEvent()
  
  Select Event
    Case #PB_Event_Timer 
      For op=0 To ListView_GetItemCount(Ex_Listview)
        ProgressBar_SetPos(ListView_ProgressBarGetbyitem(Ex_Listview, op),Random(100,0))
        ProgressBar_SetPos(ProgressBar_Ex_Listview0,Random(100,0))
      Next
      
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 1 
          CloseWindow(0)
          End  
      EndSelect
      
  EndSelect
Until Event = #PB_Event_CloseWindow
.....i Love Pb :)
Avatar de l’utilisateur
Micoute
Messages : 2584
Inscription : dim. 02/oct./2011 16:17
Localisation : 35520 La Mézière

Re: ListView_Ex.Pbi version 1.0

Message par Micoute »

Bonjour celtic88 et merci pour ce partage.
Microsoft Windows 10 Famille 64 bits : Carte mère : ASRock 970 Extreme3 R2.0 : Carte Graphique NVIDIA GeForce RTX 3080 : Processeur AMD FX 6300 6 cœurs 12 threads 3,50 GHz PB 6.20 LTS (x64)
Un homme doit être poli, mais il doit aussi être libre !
Avatar de l’utilisateur
Kwai chang caine
Messages : 6989
Inscription : sam. 23/sept./2006 18:32
Localisation : Isere

Re: ListView_Ex.Pbi version 1.0

Message par Kwai chang caine »

Waooouuh !!! c'est un avion que tu nous a codé 8O :D
Mon XP, doit mettre presque une minute pour compiler, et encore...sans le debugger car avec le debugger ça plante.
Tu doit avoir une bête de scène comme PC

En tout cas merci beaucoup de ce partage et de ton gros travail 8)
ImageLe bonheur est une route...
Pas une destination

PureBasic Forum Officiel - Site PureBasic
Avatar de l’utilisateur
celtic88
Messages : 309
Inscription : sam. 12/sept./2015 14:31
Localisation : Alger

Re: ListView_Ex.Pbi version 1.0

Message par celtic88 »

merci pour votre commentaire j'espère avoir pu vous aider :D
.....i Love Pb :)
Avatar de l’utilisateur
celtic88
Messages : 309
Inscription : sam. 12/sept./2015 14:31
Localisation : Alger

Re: ListView_Ex.Pbi version 1.0

Message par celtic88 »

Kwai chang caine a écrit :Waooouuh !!! c'est un avion que tu nous a codé 8O :D
Mon XP, doit mettre presque une minute pour compiler, et encore...sans le debugger car avec le debugger ça plante.
Tu doit avoir une bête de scène comme PC

En tout cas merci beaucoup de ce partage et de ton gros travail 8)
pas de quoi cher amie
remarque pour ce code marche correctement il faux avoir minimum windows vista et bien sur activer l option "Activer le support des thèmes"
.....i Love Pb :)
Shadow
Messages : 1413
Inscription : mer. 04/nov./2015 17:39

Re: ListView_Ex.Pbi version 1.0

Message par Shadow »

Salut,

Je suis époustouflé par se code 8O
Alors toi t'es un bourrin dans le genre, un bon si tu préfère :wink:

Petite idée, pouvoir sélectionné plusieurs élément et pouvoir les déplacer (Drag & Drop)
Super boulet en tous les cas, respect :wink:
Processeur: Intel Core I7-4790 - 4 Cœurs - 8 Thread: 3.60 Ghz.
Ram: 32 GB.
Disque: C: SDD 250 GB, D: 3 TB.
Vidéo: NVIDIA GeForce GTX 960: 2 GB DDR5.
Écran: Asus VX248 24 Pouces: 1920 x 1080.
Système: Windows 7 64 Bits.

PureBasic: 5.60 x64 Bits.
Avatar de l’utilisateur
celtic88
Messages : 309
Inscription : sam. 12/sept./2015 14:31
Localisation : Alger

Re: ListView_Ex.Pbi version 1.0

Message par celtic88 »

Shadow a écrit :Salut,

Je suis époustouflé par se code 8O
Alors toi t'es un bourrin dans le genre, un bon si tu préfère :wink:

Petite idée, pouvoir sélectionné plusieurs élément et pouvoir les déplacer (Drag & Drop)
Super boulet en tous les cas, respect :wink:
je vous remercie pour votre commentaire ;).
et à propos de ton idée, Voila un exemple. il lui manque un peu d'amélioration mais bon je laisse sa a toi :)

Code : Tout sélectionner

XIncludeFile "ListView_Ex.Pbi"

Global Ex_Listview,Header_Ex_Listview,Lv_DragStarted.b,Lv_hDragImage

Procedure LoWord(value)
  ProcedureReturn value & $FFFF
EndProcedure
Procedure HiWord(value)
  ProcedureReturn value >> 16 & $FFFF
EndProcedure

Structure EnddragSubiteminfo
  SubiTxt.s
  Subiimgei.i
EndStructure
Structure EnddragIteminfo
  Selectind.i
  itemPar.i
  itemCheked.b
  List Subiteminfo.EnddragSubiteminfo()
EndStructure

Procedure ListView_GetNextSelectedItem(hWnd,iIndex)
  ProcedureReturn SendMessage_(hWnd, #LVM_GETNEXTITEM, iIndex, #LVNI_SELECTED)
EndProcedure

Procedure ListView_GetNextBelowItem(hWnd,iIndex)
  ProcedureReturn SendMessage_(hWnd, #LVM_GETNEXTITEM, iIndex, #LVNI_BELOW)
EndProcedure

Procedure ListView_GetSelectedItemCount(hWnd)
  ProcedureReturn SendMessage_(hWnd, #LVM_GETSELECTEDCOUNT, 0, 0)
EndProcedure

Procedure ListView_SetItemSelectedEx(hWnd, iIndex,Selected.b=1,Focused.b=0,All.b=0)
  Protected tItem.LVITEM
  tItem\mask=#LVIF_STATE
  If All
    iIndex = -1
  EndIf
  tItem\iItem=iIndex
  Protected iSelected = 0, iFocused = 0
  If Selected
    iSelected=#LVIS_SELECTED
  EndIf
  If Focused
    iFocused=#LVIS_FOCUSED
  EndIf
  tItem\state=iSelected |iFocused
  tItem\stateMask=#LVIS_SELECTED | iFocused
  ProcedureReturn SendMessage_(hWnd, #LVM_SETITEMSTATE, iIndex, @tItem)
EndProcedure

Procedure ListView_DropSelectedItem(hWnd,Dropinindex)
  If Dropinindex =-1
    ProcedureReturn
  EndIf
  Protected fristselecteditem=-1
  Protected NewList ItemInfo.EnddragIteminfo()
  For op=1 To ListView_GetSelectedItemCount(hWnd)
    fristselecteditem= ListView_GetNextSelectedItem(hWnd,fristselecteditem)
    If fristselecteditem = -1
      Break
    EndIf
    AddElement(ItemInfo())
    ItemInfo()\Selectind = fristselecteditem
    ItemInfo()\itemPar=ListView_GetItemParam(hWnd,fristselecteditem)
    ItemInfo()\itemCheked=ListView_GetItemChecked(hWnd, fristselecteditem)
    For i=0 To Header_GETITEMCOUNT(Header_Ex_Listview)-1
      AddElement(ItemInfo()\Subiteminfo())
      ItemInfo()\Subiteminfo()\SubiTxt=ListView_GetItemText(hWnd,fristselecteditem,i)
      ItemInfo()\Subiteminfo()\Subiimgei=ListView_GetItemImage(hWnd,fristselecteditem,i)  
    Next
  Next
  
  If ListSize(ItemInfo()) > 0
    
    ForEach ItemInfo()
      ListView_DELETEITEM(hWnd, ItemInfo()\Selectind)
    Next
    ListView_SetItemSelectedEx(hWnd, 0,0,0,1) ;Deselected All
    Protected iTem,GroupId=-1
    ForEach ItemInfo()
      Dropinindex = ListView_GetNextBelowItem(hWnd,Dropinindex)
      Debug Dropinindex
      iTem=ListView_AddItem(hWnd,"",GroupId,ItemInfo()\itemPar,-1,Dropinindex)
      ListView_SetItemChecked(hWnd,iTem,ItemInfo()\itemCheked)
      ListView_SetItemSelected(hWnd,iTem)
      ForEach ItemInfo()\Subiteminfo()
        ListView_AddSubItem(hWnd, iTem,ListIndex(ItemInfo()\Subiteminfo()) ,ItemInfo()\Subiteminfo()\SubiTxt,ItemInfo()\Subiteminfo()\Subiimgei)  
      Next
    Next
    
  EndIf
  
  FreeList(ItemInfo()\Subiteminfo())
  FreeList(ItemInfo())
EndProcedure


Procedure _WindowCallback(hWnd, uMsg, wParam, lParam) 
  
  Select uMsg
    Case #WM_LBUTTONUP
      If Lv_DragStarted
        Lv_DragStarted = 0
        ImageList_DragLeave_(Ex_Listview)
        ImageList_EndDrag_()
        ImageList_Destroy_(Lv_hDragImage)
        ReleaseCapture_()
        ClipCursor_(0)
        ListView_SetInsertMark(Ex_Listview, -1, 1)
        Protected lhitest.LVHITTESTINFO
        lhitest\pt\x=LoWord(lParam)
        lhitest\pt\y=HiWord(lParam)
        ClientToScreen_(hWnd, @lhitest\pt);
        ScreenToClient_(Ex_Listview, @lhitest\pt);
        ListView_HitTest(Ex_Listview, @lhitest)
        ListView_DropSelectedItem(Ex_Listview,lhitest\iItem)
EndIf

    Case #WM_MOUSEMOVE
      If Lv_DragStarted
        Protected lhitesti.LVHITTESTINFO
        lhitesti\pt\x=LoWord(lParam)
        lhitesti\pt\y=HiWord(lParam)
        ClientToScreen_(hWnd, @lhitesti\pt);
        ScreenToClient_(Ex_Listview, @lhitesti\pt);
        ListView_HitTest(Ex_Listview, @lhitesti)
        ListView_SetInsertMark(Ex_Listview, lhitesti\iItem, 0)
        ClientToScreen_(Ex_Listview, @lhitesti\pt)
        ImageList_DragMove_(lhitesti\pt\x, lhitesti\pt\y)
      EndIf

    Case #WM_NOTIFY
      
      Protected *tNMHDR.NMHDR=lParam
      
      Select *tNMHDR\hwndFrom          
        Case Ex_Listview
          Protected *tInfoLv.NMLISTVIEW=lParam,ic
          
          Select *tNMHDR\code
              
            Case #LVN_BEGINDRAG
              Protected point.POINT,rect.RECT
              Lv_hDragImage=ListView_CreateDragImage(Ex_Listview, *tInfoLv\iItem,@point)
              ImageList_BeginDrag_(Lv_hDragImage,0,0,0)
              ClientToScreen_(Ex_Listview,@*tInfoLv\ptAction)
              ImageList_DragEnter_(0,*tInfoLv\ptAction\x,*tInfoLv\ptAction\y)
              GetWindowRect_(Ex_Listview,@rect);
              ClipCursor_(@rect)
              SetCapture_(hWnd);
              Lv_DragStarted=1
              
          EndSelect
          
      EndSelect
  EndSelect
  
  ProcedureReturn #PB_ProcessPureBasicEvents 
EndProcedure

Procedure.s RandomString(len=10)
  Protected Ranstr.s,oklm
  For oklm=1 To len
    Ranstr + Chr(Random(90,64))
  Next
  ProcedureReturn Ranstr
EndProcedure

OpenWindow(0,#PB_Ignore, #PB_Ignore, 690,  530,"test ListView_Inclu_Ex")

Style=#LVS_REPORT | #LVS_SHOWSELALWAYS
Ex_style= #LVS_EX_BORDERSELECT|#LVS_EX_DOUBLEBUFFER|#LVS_EX_FULLROWSELECT|#LVS_EX_GRIDLINES     
Ex_Listview = ListView_Create(WindowID(0),10, 5, 670, 500,Style,Ex_style)

Header_Ex_Listview = ListView_Getheader(Ex_Listview)

For i=0 To 4
  ListView_InsertColumn(Ex_Listview, i, "Col" + Str(i), 80)
Next

For i=1 To 40
  iTem=ListView_AddItem(Ex_Listview,RandomString(15),-1,i)
  For ii=1 To 4
    ListView_AddSubItem(Ex_Listview, iTem,ii,RandomString(15)+Str(i+ii))       
  Next
Next

SetWindowCallback(@_WindowCallback() ,0)

ListView_SetInsertMarkColor(Ex_Listview, RGB(Random(255), Random(255), Random(255)))

Repeat
  Event = WaitWindowEvent()
  
  Select Event
      
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 1 
          CloseWindow(0)
          End  
      EndSelect
      
  EndSelect
Until Event = #PB_Event_CloseWindow
.....i Love Pb :)
Répondre