  includepath "$/inc/"
  $ filename "t.exe"
 'uses RTL64
  uses minwin


  '#lookahead ' for procedures

  % WM_DROPFILES  0x0233
  
  extern lib "shell32.dll"  
  Declare DragQueryFile Alias "DragQueryFileA" ( _
          sys wHandle, NumFiles, NameBuffer,BufferLen ) As sys
  Declare DragFinish Alias "DragFinish" (sys wHandle)
  Declare DragAcceptFiles Alias "DragAcceptFiles" (sys hWnd, fAccept )
  end extern

  Function GetDropFiles(sys hDropParam) As String
  ===============================================
  string sDropFiles, sFiles
  sys i,e
  e=DragQueryFile(hDropParam, -1, null, 0)-1
  for i = 0 To e
    int le=DragQueryFile(hDropParam, i, null, 1)
    string sfile=space le              
    DragQueryFile(hDropParam, i, StrPtr sFile, le+1)
    If Ucase(mid(sFile, -4)) = ".LNK"
    else
      sDropFiles+= sFile + chr(13,10)
    end if
  next i   
  return sDropFiles
  End Function



  dim as rect crect 'for WndProc and TimerProc


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

    static as sys hdc
    static as String txt
    static as PaintStruct Paintst
 
    ===========
    select wMsg
    ===========
      
    'case WM_COMMAND
                 
    case WM_CREATE
    ==============
            
    Case WM_DROPFILES
    =================
    '
    sys pDrop = wparam
    string sFiles = GetDropFiles(pDrop)
    print sFiles
    DragFinish(wparam)
    '
    case WM_DESTROY
    ================
          
    PostQuitMessage 0
    DragAcceptFiles(hwnd, TRUE)  
      
    case WM_PAINT
    =============

    'TEXT
    'http://msdn.microsoft.com/en-us/library/dd144821(v=VS.85).aspx

    'DRAWING AND PAINTING
    'http://msdn.microsoft.com/en-us/library/dd162760(v=VS.85).aspx

    GetClientRect  hWnd,&cRect
    hDC=BeginPaint hWnd,&Paintst
    'style
    '0x20 DT_SINGLELINE
    '0x04 DT_VCENTER
    '0x01 DT_CENTER
    '0x25

     SetBkColor   hdc,yellow
     SetTextColor hdc,red
     DrawText hDC,"Drop Files Here",-1,&cRect,0x25
     EndPaint hWnd,&Paintst
                          

    case WM_KEYDOWN
    '==============

      Select wParam
      '============

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

      End Select
      

    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

  wc.style = CS_HREDRAW or CS_VREDRAW
  wc.lpfnWndProc = @WndProc 
  wc.cbClsExtra =0
  wc.cbWndExtra =0    
  wc.hInstance =inst
  wc.hIcon=LoadIcon 0, IDI_APPLICATION
  wc.hCursor=LoadCursor 0,IDC_ARROW
  wc.hbrBackground = GetStockObject WHITE_BRUSH 
  wc.lpszMenuName =null
  wc.lpszClassName = strptr "Demo"

  RegisterClass (@wc)
 
  Wwd = 420 : Wht = 300
  Tax = GetSystemMetrics SM_CXSCREEN
  Wtx = (Tax - Wwd) /2
  Tax = GetSystemMetrics SM_CYSCREEN
  Wty = (Tax - Wht) /2
 
  hwnd = CreateWindowEx 0,wc.lpszClassName,"drag and Drop Test_go!",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 


  '=========
  'MAIN CODE
  '=========
  
  dim cmdline as asciiz ptr, inst as sys
  &cmdline=GetCommandLine
  inst=GetModuleHandle 0
  '
  'WINDOWS START
  '=============
  '
  WinMain inst,0,cmdline,SW_NORMAL
  end
