  $ filename "t.exe"
 'uses RTL64
  uses corewin


  dim cmdline as asciiz ptr
  dim hinst as sys
  
  'in lib "shell32.dll"
  ' DragQueryFile Alias "DragQueryFileA" ( _
  '   sys wHandle, NumFiles, NameBuffer,BufferLen ) As sys
  ' DragFinish Alias "DragFinish" (sys wHandle)
  ' DragAcceptFiles Alias "DragAcceptFiles" (sys hWnd, fAccept )

  % WM_DROPFILES  0x0233

  % EDGE_RAISED   5
  % EDGE_SUNKEN   10
  % BF_RECT       15
  % WM_DRAWITEM   43
  % ETO_OPAQUE    2
  % ETO_CLIPPED   4
  % ODS_SELECTED  1
  % GWL_HINSTANCE 0xfffffffa '-6

  % IDB_BUTTON  200
  sys hWndStdButton

  % IDC_OWNERDRAWN  300
  sys hWndClrButton

  type SIZE
    long cx
    long cy
  end type

  type DRAWITEMSTRUCT 
     uint CtlType
     uint CtlID
     uint itemID
     UINT itemAction
     UINT itemState
    sys  hwndItem
    sys  hDC
    RECT rcItem
    sys  itemData        'ulong_ptr
  end type


  function GetDropFiles(sys hDropParam) As String
  ===============================================
  ' returns string list of dropped files
  '
  int i             ' iterator
  int e             ' number of files dropped
  int le            ' length of each file
  string sfile      ' temp name buffer for each file
  string sDropFiles ' list of files to return
  '
  e=DragQueryFile(hDropParam, -1, 0, 0)
  for i = 0 To e-1
    '
    ' get filename length
    ' create buffer for filename
    ' get filename
    ' append filename to list              
    ' but ignore shortcuts
    '
    le=DragQueryFile(hDropParam, i, 0, 1)
    sfile=space le
    DragQueryFile(hDropParam, i, sFile, le+1)
    If Ucase(mid(sFile, -4)) = ".LNK"
    else
      sDropFiles+= sFile + chr(13,10)
    end if
  next i   
  return sDropFiles
  end function



  function WndProc ( sys hWnd, wMsg, wParam, lparam ) as sys callback
  ===================================================================

 
    select wMsg
                       
    case WM_CREATE
    ==============
            
    DragAcceptFiles(hwnd, TRUE)
  
    static sys hwdr
    int style=
      WS_CHILD | WS_BORDER | WS_VISIBLE | ES_READONLY |
      ES_MULTILINE   | ES_WANTRETURN
    string stys="edit"
    hwdr=CreateWindowEx(0,stys, null, style, 0,0,0,0, hwnd, 100, hinst, null)
    string s = "Drop Files here:"
    int le=len s
    SendMessage hwdr,WM_SETTEXT,le,s
    '
    hWndStdButton = CreateWindowEx(
      0,
      "BUTTON",
      "Clear",
      WS_VISIBLE or WS_CHILD,
      0,0,0,0,
      hWnd,
      IDB_BUTTON,
      hInst,
      NULL)

    hWndClrButton = CreateWindowEx(
      0,
      "BUTTON",
      "Exec",
      WS_CHILD or BS_OWNERDRAW,
      0,0,0,0,
      hWnd,
      IDC_OWNERDRAWN,
      hinst,
      NULL)

      ShowWindow(hWndClrButton, SW_SHOW)


    case WM_DROPFILES
    =================
    '
    sys pDrop = wparam
    string sFiles = GetDropFiles(pDrop)
    int le=len sFiles
    SendMessage hwdr,WM_SETTEXT,le,sFiles
    'print sFiles
    DragFinish(wparam)

    case WM_DRAWITEM
    ================
    '
      select case wParam

      case IDC_OWNERDRAWN

        'get the pointer to the item-drawing info
        DRAWITEMSTRUCT *ptDrawItem
        @ptDrawItem=lParam
                   
        ' alternative
        'DRAWITEMSTRUCT ptDrawItem at lParam                   

         SIZE siz
         string text
         text = "Exec"
         GetTextExtentPoint32(ptDrawItem.hDC, text, len(text), siz)
         SetTextColor(ptDrawItem.hDC, WHITE)
         SetBkColor(ptDrawItem.hDC, RED)

         ExtTextOut(ptDrawItem.hDC,
           ((ptDrawItem.rcItem.right - ptDrawItem.rcItem.left) - siz.cx) \ 2,
           ((ptDrawItem.rcItem.bottom - ptDrawItem.rcItem.top) - siz.cy) \ 2,
           ETO_OPAQUE or ETO_CLIPPED, &ptDrawItem.rcItem, text, len(text), NULL)

         uint edge
         if ptDrawItem.itemState and ODS_SELECTED
           edge = EDGE_SUNKEN
         else
           edge = EDGE_RAISED
         end if   
         DrawEdge(ptDrawItem.hDC, ptDrawItem.rcItem,
           edge, BF_RECT)
               
      end select

    case WM_COMMAND
    ===============

      select loword(wParam)

        case IDB_BUTTON

          select hiword(wParam)

            case BN_CLICKED
            s="Drag and Drop Files here:"
            le=len s
            SendMessage hwdr, WM_SETTEXT,le,s
          end select

        case IDC_OWNERDRAWN

          select case hiword(wParam)

            case BN_CLICKED
              MessageBox(NULL, "Selected Color Button", "Color Button", MB_OK or MB_ICONINFORMATION)
          end select
      end select

    case WM_CLOSE
    =============

    DestroyWindow(hWnd)

    case WM_DESTROY
    ===============
          
    PostQuitMessage 0
              

    case WM_KEYDOWN
    ===============

      select wParam
      =============

      case 27 : SendMessage hwnd, WM_CLOSE, 0, 0      'ESCAPE

      end select

    case WM_SIZE
    ============

    RECT r
    GetClientRect hwnd,r
    int rx=r.right-100
    MoveWindow hwdr , r.left+10 , r.top+10 , rx , r.bottom-20 , TRUE
    MoveWindow hwndStdButton , rx+15 , r.top+10 , 80 , 30 , TRUE
    MoveWindow hwndClrButton , rx+15 , r.top+40 , 80 , 30 , TRUE
      

    case else
    =========
          
      function=DefWindowProc hWnd,wMsg,wParam,lParam
        
    end select

  end function ' WndProc



  Function WinMain(sys inst, prevInst, asciiz*cmdline, sys show) as sys
  =====================================================================

  WndClass wc
  MSG      wm

  sys hwnd, wwd, wht, wtx, wty, tax

  with wc
    .style = CS_HREDRAW or CS_VREDRAW
    .lpfnWndProc = @WndProc 
    .cbClsExtra =0
    .cbWndExtra =0    
    .hInstance =inst
    .hIcon=LoadIcon 0, IDI_APPLICATION
    .hCursor=LoadCursor 0,IDC_ARROW
    .hbrBackground = GetStockObject WHITE_BRUSH 
    .lpszMenuName =null
    .lpszClassName = strptr "Demo"
  end with
  '
  RegisterClass wc
 
  wwd = 640
  wht = 240
  tax = GetSystemMetrics SM_CXSCREEN
  wtx = (tax - wwd) >>1
  tax = GetSystemMetrics SM_CYSCREEN
  wty = (tax - wht) >>1
 
  hwnd = CreateWindowEx 0,wc.lpszClassName,"Tool using Drag & Drop",WS_OVERLAPPEDWINDOW,Wtx,Wty,Wwd,Wht,0,0,inst,0
  ShowWindow hwnd,SW_SHOW
  UpdateWindow hwnd
  
  DragAcceptFiles(hwnd, TRUE)
  '
  sys bRet
  '
  do while bRet := GetMessage(wm, 0, 0, 0)
    if bRet = -1 then
      'show an error message
    else
      TranslateMessage wm
      DispatchMessage wm
    end if
  wend
  End Function 


  'ENTRY CODE
  '==========
  
  @cmdline=GetCommandLine
  hinst=GetModuleHandle 0
  '
  'WINDOWS START
  '=============
  '
  WinMain(hinst,0,cmdline,SW_NORMAL)
  end
