         .586
         .model  flat, STDCALL

         include  TabTree.inc

.const
ClassName         db        'ListViewWindow',0
AppName           db        'A ListView Control',0
ListViewClass     db        'SysListView32',0
FontMS            db        'MS Sans Serif',0

szColName         db        'Filename',0

szAll             db        '*.*',0
szRootPath        db        'C:\',0
szSlashB          db        '\',0

.data?
hInst             dd        ?
hFontL            dd        ?
hImageListS       dd        ?
HoldT             dd        ?

.data
szRoot            db        256 dup(?)
szPath            db        256 dup(?)

Cnt               dd        0

lf           LOGFONT     <>
rect         RECT        <>

.code

start:

;=========================================================================
; InitListView PROCEDURE
;=========================================================================
InitListView  proc  hinst:DWORD, hwnd:DWORD
LOCAL    sfi:SHFILEINFO
LOCAL    lvc:LV_COLUMN

; or LVS_SORTASCENDING
      INVOKE     CreateWindowEx, WS_EX_CLIENTEDGE, addr ListViewClass, NULL,\
                 WS_CHILD or WS_VISIBLE or LVS_REPORT or LVS_SHAREIMAGELISTS or LVS_SORTASCENDING,\
                 0, 126, 123, 185, hwnd, ID_LISTVIEW, hinst, NULL
         mov     hWndList, eax

;         mov     eax, LVS_EX_FULLROWSELECT or LVS_EX_HEADERDRAGDROP or\
;                      LVS_EX_SUBITEMIMAGES or LVS_EX_GRIDLINES

         mov     eax, LVS_EX_FULLROWSELECT ;or LVS_EX_GRIDLINES

      INVOKE     SendMessage, hWndList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, eax

      INVOKE     SHGetFileInfo, addr szRootPath, 0, addr sfi, sizeof SHFILEINFO,\
                 SHGFI_SYSICONINDEX or SHGFI_SMALLICON
         mov     hImageListS, eax
;      INVOKE     SendMessage, hWndList, LVM_SETIMAGELIST, LVSIL_SMALL, hImageListS

      INVOKE     lstrcpy, addr lf.lfFaceName, addr FontMS
         mov     lf.lfHeight, -12
         mov     lf.lfWeight, 400 ;600
      INVOKE     CreateFontIndirect, addr lf
         mov     hFontL, eax    ; Listview font

      INVOKE     SendMessage, hWndList, WM_SETFONT, hFontL, 1
;      INVOKE     SendMessage, hWndList, LVM_SETTEXTCOLOR, 0, 00ffff00h
;      INVOKE     SendMessage, hWndList, LVM_SETBKCOLOR, 0, 00000000h
;      INVOKE     SendMessage, hWndList, LVM_SETTEXTBKCOLOR, 0, 00000000h

         mov     lvc.imask, LVCF_TEXT or LVCF_WIDTH
         mov     lvc.pszText, offset szColName
         mov     lvc.lx, 119
      INVOKE     SendMessage, hWndList, LVM_INSERTCOLUMN, 0, addr lvc
;      INVOKE     ReadTheFile
         ret
InitListView  endp

;=========================================================================
; Read the file PROCEDURE
;=========================================================================
ReadTheFile  proc  uses edi
LOCAL    FindData:WIN32_FIND_DATA
LOCAL    Lft:FILETIME
LOCAL    time:SYSTEMTIME
LOCAL    hFind:DWORD
LOCAL    szBuff[256]:BYTE, szBuff1[64]

      INVOKE     SendMessage, hWndList, LVM_DELETEALLITEMS, 0, 0
      INVOKE     lstrcpy, addr szBuff, addr WorkBuff
      INVOKE     lstrcat, addr szBuff, addr szSlashB
      INVOKE     lstrcpy, addr szPath, addr szBuff
      INVOKE     lstrcat, addr szBuff, addr szAll
         and     Cnt, 0

      INVOKE     FindFirstFile, addr szBuff, addr FindData
      .if eax != INVALID_HANDLE_VALUE
            mov     hFind, eax
         .while (eax)
               inc     Cnt
            INVOKE     FindNextFile, hFind, addr FindData
         .endw
      .endif

      INVOKE     FindFirstFile, addr szBuff, addr FindData
      .if eax != INVALID_HANDLE_VALUE
            mov     hFind, eax
            xor     edi, edi
         .while eax != 0
            .if byte ptr FindData.cFileName != '.'
               .if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
               .else
                  INVOKE     lstrcpy, addr szBuff1, addr FindData.cFileName
                  INVOKE     lstrlen, addr szBuff1
                  .while (eax)
                     .if byte ptr szBuff1[eax] == '.'
                        .break
                     .endif
                        dec     eax
                  .endw
                  .if eax
                        inc     eax
                     .if byte ptr szBuff1[eax] >= 'A' && byte ptr szBuff1[eax] <= 'Z'
                           add     byte ptr szBuff1[eax], 20h
                     .endif
                     .if byte ptr szBuff1[eax+1] >= 'A' && byte ptr szBuff1[eax+1] <= 'Z'
                           add     byte ptr szBuff1[eax+1], 20h
                     .endif
                     .if byte ptr szBuff1[eax] == 'a' && byte ptr szBuff1[eax+1] == 's' ||\
                         byte ptr szBuff1[eax] == 'r' && byte ptr szBuff1[eax+1] == 'c'
                     .elseif byte ptr szBuff1[eax] == 'i' && byte ptr szBuff1[eax+1] == 'n' ||\
                         byte ptr szBuff1[eax] == 'd' && byte ptr szBuff1[eax+1] == 'e' ||\
                         byte ptr szBuff1[eax] == 'b' && byte ptr szBuff1[eax+1] == 'a'
                     .else
                           jmp     Pass
                     .endif
                     INVOKE     LoadListView, edi, addr FindData
                        inc     edi
                  .endif
               .endif
            .endif
Pass:
            INVOKE     FindNextFile, hFind, addr FindData
         .endw
         INVOKE     FindClose, hFind
      .endif
         ret
ReadTheFile  endp

;=========================================================================
; Load the ListView with the file data PROCEDURE
;=========================================================================
LoadListView proc  uses ebx edx edi  row:DWORD, lpFind  ; uses edi
LOCAL    lvi:LV_ITEM
LOCAL    szBuff0[64]:BYTE

         mov     edi, lpFind

INVOKE     RtlZeroMemory, addr lvi, sizeof lvi

;---------- [Load the list items] ----------
         mov     lvi.imask, LVIF_TEXT or LVIF_IMAGE or LVIF_PARAM
        push     row
         pop     lvi.iItem
        push     row
         pop     lvi.lParam
         mov     lvi.iSubItem, 0
         lea     eax, [edi.WIN32_FIND_DATA].cFileName
         mov     lvi.pszText, eax
         mov     lvi.iImage, 0
      INVOKE     SendMessage, hWndList, LVM_INSERTITEM, 0, addr lvi
         ret
LoadListView endp

;=========================================================================
; Display the file name PROCEDURE
;=========================================================================
DisplayFileName proc
LOCAL    lvi:LV_ITEM
LOCAL    szBuff[256]:BYTE, szName[64]

      INVOKE     SendMessage, hWndList, LVM_GETNEXTITEM, -1, LVNI_FOCUSED
         mov     lvi.iItem, eax
         mov     lvi.iSubItem, 0
         mov     lvi.imask, LVIF_TEXT
         lea     eax, szName
         mov     lvi.pszText, eax
         mov     lvi.cchTextMax, 256
      INVOKE     SendMessage, hWndList, LVM_GETITEM, 0, addr lvi
      INVOKE     lstrcpy, addr szBuff, addr szPath
      INVOKE     lstrcat, addr szBuff, addr szName
      INVOKE     lstrcpy, addr PathName, addr szBuff
      INVOKE     lstrcpy, addr FileName, addr szName
;      INVOKE     MessageBox, NULL, addr PathName, addr AppName, MB_OK
         ret
DisplayFileName endp

END
;INVOKE     MessageBox, NULL, addr szPath, addr AppName, MB_OK
