.const
Listbox        db  'LISTBOX',0
FontMS         db  'MS Sans Serif',0
szSlashB       db  '\',0
szAll          db  '*.*',0

.data?
hList          dd  ?
hFontL         dd  ?
hFind          dd  ?

lf             LOGFONT   <?>

.code

;________________________________________________________________________________
WndProc proc  uses edx  hwnd:DWORD, wMsg, wParam, lParam
LOCAL    FindData:WIN32_FIND_DATA
LOCAL    szBuff[256]:BYTE

      .if wMsg == WM_CREATE

;---------- [Create the Listbox] ----------
         INVOKE     CreateWindowEx, 0, addr Listbox, 0, WS_CHILD or WS_VISIBLE or\
                    WS_VSCROLL or LBS_HASSTRINGS or LBS_SORT,
                    110, 5, 127, 50, hwnd, 85, hInst, 0
            mov     hList, eax

;---------- [Create the Font] ----------
         INVOKE     lstrcpy, addr lf.lfFaceName, addr FontMS
            mov     lf.lfHeight, -12
            mov     lf.lfWeight, 500
         INVOKE     CreateFontIndirect, addr lf
            mov     hFontL, eax    ; Listbox font

;---------- [Set the Font and the line height of the Listbox] ----------
         INVOKE     SendMessage, hList, WM_SETFONT, hFontL, 1
         INVOKE     SendMessage, hList, LB_SETITEMHEIGHT, 0, 13  ; List items

;---------- [Get the current dir and load the Listbox with its files] ----------
         INVOKE     GetCurrentDirectory, lengthof szBuff, addr szBuff
         INVOKE     lstrcat, addr szBuff, addr szSlashB
         INVOKE     lstrcat, addr szBuff, addr szAll
         INVOKE     FindFirstFile, addr szBuff, addr FindData
           test     eax, eax
             js     NoFile
            mov     hFind, eax
            jmp     Addem

Getem:
         INVOKE     FindNextFile, hFind, addr FindData
           test     eax, eax
             jz     AllDone

Addem:
         .if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||\
             (FindData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) ||\
             (FindData.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM)
               jmp     Getem
         .endif
;         INVOKE     lstrlen, addr FindData.cFileName
;            sub     eax, 3
;         INVOKE     lstrcpyn, addr szBuff, addr FindData.cFileName, eax
         INVOKE     SendMessage, hList, LB_ADDSTRING, 0, addr FindData.cFileName ;szBuff
            jmp     Getem

AllDone:
         INVOKE     FindClose, hFind

NoFile:

      .elseif wMsg == WM_COMMAND
         mov     eax, wParam
         mov     ebx, eax
         shr     ebx, 16

;---------- [Extract the selected item] ----------
         .if ebx == LBN_SELCHANGE
            INVOKE     SendMessage, hList, LB_GETCURSEL, 0, 0
            .if eax == LB_ERR
                  jmp     NoSel
            .endif
               mov     ebx, eax
            INVOKE     SendMessage, hList, LB_GETTEXT, ebx, addr szBuff
            INVOKE     MessageBox, NULL, addr szBuff, addr AppName, MB_OK
         .endif

NoSel:
