Announcement

Collapse
No announcement yet.

Fun with WM_DROPFILES

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Fun with WM_DROPFILES

    Having fun with WM_DROPFILES.

    The code fill a DROPFILES structure and then send a WM_DROPFILES to Notepad so it will open a specific file.

    This could be a convenient way to send one or more file to any open application that accept WM_DROPFILES message.

    Code:
    'Having fun with WM_DROPFILES
    'This could be a convenient way to send one or more file to any application that accept WM_DROPFILES message.
    
    #COMPILE EXE '#Win 9.07#
    #DIM ALL
    #INCLUDE "Win32Api.inc"
    
    TYPE DROPFILES '20 bytes
      pFiles AS DWORD    'Offset of a double null terminated file list
      pt     AS POINTAPI 'Drop point client coords
      fNC    AS LONG     'Is it on NonClient area and pt is in screen coords
      fWide  AS LONG     'Zero = ANSI else WIDE
    END TYPE
    '_____________________________________________________________________________
    
    FUNCTION PBMAIN() AS LONG
     LOCAL DropFile   AS DROPFILES
     LOCAL sFileArray AS STRING
     LOCAL hWin       AS DWORD
     LOCAL hMem       AS DWORD
     LOCAL pMem       AS DWORD
     LOCAL Pid        AS DWORD
     LOCAL MaxWait    AS DWORD
    
     'Double zero terminated array of zero terminated string, may be Ansi or UNICODE
     sFileArray = DIR$("*.txt")
     IF LEN(sFileArray) = 0 THEN sFileArray = DIR$("*.bas")
     IF LEN(sFileArray) = 0 THEN
       MessageBox(%HWND_DESKTOP, "No valid filename found!", "WM_DROPFILES", %MB_OK OR %MB_TOPMOST)
       EXIT FUNCTION
     END IF
     sFileArray &= NUL$(2)
     'sFileArray      = "" & NUL$(2) 'You may put a valid filename here
     DropFile.pFiles = SIZEOF(DROPFILES) '20 - Offset of a double null terminated file list
     DropFile.pt.x   = 0 'Drop point client coords
     DropFile.pt.y   = 0 'Drop point client coords
     DropFile.fNC    = 0 'Is it on NonClient area and pt is in screen coords
     DropFile.fWide  = 0 'Zero = ANSI else WIDE
    
     hMem = GlobalAlloc(%GMEM_FIXED, SIZEOF(DROPFILES) + LEN(sFileArray))
     pMem = GlobalLock(hMem)
     CopyMemory(pMem, VARPTR(DropFile), SIZEOF(DROPFILES))
     CopyMemory(pMem + SIZEOF(DROPFILES), STRPTR(sFileArray), LEN(sFileArray))
    
     Pid = SHELL("Notepad", %SW_SHOWNORMAL)
     WHILE hWin = 0 AND MaxWait < 30 '30 * 100ms = 3 seconds wait maximum
       hWin = FindWindow("Notepad", "")
       SLEEP 100
       INCR MaxWait
     WEND
     IF hWin THEN
       PostMessage(hWin, %WM_DROPFILES, hMem, 0)
     END IF
    
     IF GlobalFlags(hMem) <> %GMEM_INVALID_HANDLE THEN
       'Notepad will free memory via DragFinish(wParam) so this is not needed if all goes well
       GlobalUnlock(pMem)
       GlobalFree(hMem)
       WinBeep(1500, 100)
     END IF
    
    END FUNCTION
    '_____________________________________________________________________________
    '

  • #2
    Pierre

    You could use your 32-bit PB's code even with a 64-bit application, should work with my MediaBox to play any multimedia file.
    in case you want to see an illustration of using drag and drop with MediaBox download the video from the link below.
    http://www.objreader.com/download/video/MBox64.mp4
    Last edited by Patrice Terrier; 13 Aug 2017, 02:28 PM.
    Patrice Terrier
    www.zapsolution.com
    www.objreader.com
    Addons: GDImage.DLL 32/64-bit (Graphic library), WinLIFT.DLL 32/64-bit (Skin Engine).

    Comment


    • #3
      Good to know, it was still hot, fresh from the oven so I did not thought to try on 64 bit application.
      Works also fine on my little 64bit text viewer.
      Seems bad on ie32 and ie64 though. Well, ie is more than a simple exe... It will need some investigations someday... :-)

      Comment

      Working...
      X