File: w_main.srw
Size: 5764
Date: Wed, 18 Jan 2023 22:21:52 +0100
$PBExportHeader$w_main.srw
forward
global type w_main from window
end type
type st_fullname from statictext within w_main
end type
type lv_files from u_listview within w_main
end type
type cb_cancel from commandbutton within w_main
end type
end forward

global type w_main from window
integer width = 3232
integer height = 1844
boolean titlebar = true
string title = "Drag Files"
boolean controlmenu = true
long backcolor = 67108864
string icon = "AppIcon!"
boolean center = true
st_fullname st_fullname
lv_files lv_files
cb_cancel cb_cancel
end type
global w_main w_main

type prototypes
Subroutine DragAcceptFiles ( &
   Longptr hWnd, &
   Boolean fAccept &
   ) Library "shell32.dll"

Function ULong DragQueryFile ( &
   Longptr hDrop, &
   ULong iFile, &
   Ref String lpszFile, &
   ULong cch &
   ) Library "shell32.dll" Alias For "DragQueryFileW"

end prototypes

type variables
Long il_unknown
Long il_folder

end variables

on w_main.create
this.st_fullname=create st_fullname
this.lv_files=create lv_files
this.cb_cancel=create cb_cancel
this.Control[]={this.st_fullname,&
this.lv_files,&
this.cb_cancel}
end on

on w_main.destroy
destroy(this.st_fullname)
destroy(this.lv_files)
destroy(this.cb_cancel)
end on

event open;// Enable Drag Accept Files
DragAcceptFiles(Handle(lv_files), True)

end event

event close;// Disable Drag Accept Files
DragAcceptFiles(Handle(lv_files), False)

end event

type st_fullname from statictext within w_main
integer x = 73
integer y = 1616
integer width = 2674
integer height = 68
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
long textcolor = 33554432
long backcolor = 67108864
boolean focusrectangle = false
end type

type lv_files from u_listview within w_main
event dropfiles pbm_dropfiles
integer x = 73
integer y = 64
integer width = 3077
integer height = 1476
integer taborder = 10
integer textsize = -8
string facename = "Tahoma"
listviewview view = listviewreport!
end type

event dropfiles;Constant ULong FILECOUNT = 4294967295
Constant ULong MAX_PATH = 260
n_filesys lnv_fsys
ListViewItem llvi_item
DateTime ldt_modified
Decimal ldec_kb
Integer li_item
Long  ll_index, ll_pos, ll_large, ll_small, ll_filesize
ULong lul_index, lul_chars, lul_idx, lul_max
String ls_FullName, ls_FileName, ls_extn, ls_prevextn, ls_filetype

// get list of files
lul_max = DragQueryFile(handle, FILECOUNT, ls_FullName, MAX_PATH)
For lul_idx = 1 To lul_max
   // get individual file name
   lul_index = lul_idx - 1
   ls_FullName = Space(MAX_PATH)
   lul_chars = DragQueryFile(handle, lul_index, ls_FullName, MAX_PATH)
   ll_pos = LastPos(ls_FullName, "\")
   ls_FileName = Mid(ls_FullName, ll_pos + 1)

   If DirectoryExists(ls_FullName) Then
      // add directory item
      llvi_item.Data = ls_FullName
      llvi_item.Label = ls_FileName
      llvi_item.PictureIndex = il_folder
      li_item = this.AddItem(llvi_item)
      // fill in additional columns
      this.SetItem(li_item, 2, "")
      this.SetItem(li_item, 3, "File Folder")
      this.SetItem(li_item, 4, "")
   Else
      // load associated icon
      ls_extn = Mid(ls_FileName, Pos(ls_FileName, "."))
      If Lower(ls_extn) = ".ico" Then
         // add associated icon
         If lv_files.of_ImportAssociatedIcon(ls_FullName, &
                           ll_large, ll_small) Then
            ll_index = ll_small
         Else
            ll_index = il_unknown
         End If
      Else
         If ls_extn <> ls_prevextn Then
            ls_prevextn = ls_extn
            // add associated icon
            If lv_files.of_ImportAssociatedIcon(ls_FullName, &
                              ll_large, ll_small) Then
               ll_index = ll_small
            Else
               ll_index = il_unknown
            End If
         End If
      End If
      // add file item
      llvi_item.Data = ls_FullName
      llvi_item.Label = ls_FileName
      llvi_item.PictureIndex = ll_index
      li_item = this.AddItem(llvi_item)
      // get file properties
      ll_filesize = FileLength(ls_FullName)
      If ll_filesize > 0 Then
         ldec_kb = (ll_filesize / 1024) + .5
         ll_filesize = Round(ldec_kb, 0)
         If ll_filesize = 0 Then
            ll_filesize = 1
         End If
      End If
      ls_filetype = lv_files.of_GetFileDescription(ls_FullName)
      ldt_modified = lnv_fsys.of_GetLastWriteTime(ls_FullName)
      // fill in additional columns
      this.SetItem(li_item, 2, String(ll_filesize, "#,##0") + " KB")
      this.SetItem(li_item, 3, ls_filetype)
      this.SetItem(li_item, 4, String(ldt_modified, "m/dd/yyyy h:mm AM/PM"))
   End If
Next

end event

event constructor;call super::constructor;// destroy and create new image list
this.of_DestroyImageLists()
this.of_CreateSmallImageList()

// add shell icons
il_unknown = this.of_ImportSmallIcon("shell32.dll", 1)      // Unknown
il_folder  = this.of_ImportSmallIcon("shell32.dll", 4)      // Folder

// add columns to report view
this.AddColumn("Name", Left!, 1250)
this.AddColumn("Size", Right!, 350)
this.AddColumn("Type", Left!, 800)
this.AddColumn("Date Modified", Left!, 550)

end event

event destructor;call super::destructor;// destroy image lists
this.of_DestroyImageLists()

end event

event clicked;call super::clicked;ListViewItem llvi_item

If index > 0 Then
   this.GetItem(index, llvi_item)
   st_fullname.text = llvi_item.Data
End If

end event

type cb_cancel from commandbutton within w_main
integer x = 2816
integer y = 1600
integer width = 334
integer height = 100
integer taborder = 10
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
string text = "Cancel"
boolean cancel = true
end type

event clicked;Close(Parent)

end event