Copy several files to the clipboard

Copy several files to the clipboard

Postby Natter » Mon May 08, 2023 2:31 pm

Hi,

I need to copy several files to the clipboard at the same time. How can I do this ?
Natter
 
Posts: 1215
Joined: Mon May 14, 2007 9:49 am

Re: Copy several files to the clipboard

Postby Natter » Mon May 08, 2023 6:32 pm

It looks like you need to use the function Clipboard.SetFileDropList() But how to do it under FWH I do not know :(
Natter
 
Posts: 1215
Joined: Mon May 14, 2007 9:49 am

Re: Copy several files to the clipboard

Postby nageswaragunupudi » Tue May 09, 2023 12:19 pm

Clipboard.SetFileDropList()

This is dot NET.
FWH has not yet provided this.
This will be provided soon.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10625
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Copy several files to the clipboard

Postby Natter » Tue May 09, 2023 1:42 pm

Thanks, I get it !
Is it possible in FWH to write multiple files to the clipboard at the moment ?
Natter
 
Posts: 1215
Joined: Mon May 14, 2007 9:49 am

Re: Copy several files to the clipboard

Postby Antonio Linares » Tue May 09, 2023 6:35 pm

Dear Yuri,

Here you have a working example:
Code: Select all  Expand view
#include "FiveWin.ch"

#define CF_HDROP 15

function Main()

   local oWnd, hDrop

   DEFINE WINDOW oWnd

   MsgInfo( OpenClipboard( oWnd:hWnd ) )

   MsgInfo( SetClipboardData( CF_HDROP, { "tutor1.prg", "tutor02.prg", "tutor03.prg" } ) )

   hDrop = GetClpData( CF_HDROP )

   XBROWSER DragQueryFiles( hDrop )

   CloseClipboard()

   oWnd:End()

return nil  


You have to modify FWH\source\winapi\clpbrd.c this way:
Code: Select all  Expand view
HB_FUNC( SETCLIPBOARDDATA )
{
   WORD wType = hb_parni( 1 );
   ULONG ulLen;
   HGLOBAL hMem;
   void far * pMem;
   HBITMAP hDuplBmp;

   if( hb_pcount() > 1 )
   {
      switch( wType )
      {
         case CF_TEXT:
         case CF_UNICODETEXT:
              ulLen = hb_parclen( 2 );
              hMem = GlobalAlloc( GHND, ulLen + 1 );
              if( ! hMem )
              {
                 hb_retl( 0 );
                 return;
              }

              pMem = GlobalLock( hMem );
              memcpy( ( char * ) pMem, ( char * ) hb_parc( 2 ), ulLen );
              GlobalUnlock( hMem );
//              hb_retl( ( BOOL ) SetClipboardData( CF_TEXT, hMem ) );
              hb_retl( SetClipboardData( wType, hMem ) != NULL );
              break;

         case CF_BITMAP:
/*
              // commented out : 2021-03-07
              hb_retl( SetClipboardData( CF_BITMAP,
                     DuplicateBitmap( ( HBITMAP ) fw_parH( 2 ) ) ) != NULL );
*/

              // substituted code : 2021-03-07
              hDuplBmp = DuplicateBitmap( ( HBITMAP ) fw_parH( 2 ) );
              hb_retl( SetClipboardData( CF_BITMAP,hDuplBmp ) != NULL );
              DelResource( hDuplBmp ); // This is required because DuplicateBitmap() Registers the resource (internal to FWH)

              // See: https://docs.microsoft.com/en-us/window ... pboarddata
              // Should we delete the object hDuplBmp ?
              DeleteObject( hDuplBmp );

              break;

         case CF_HDROP:
         {
            PHB_ITEM pArray = hb_param( 2, HB_IT_ARRAY );
            ULONG ulFiles = hb_arrayLen( pArray );
            ULONG ulBufSize = sizeof(DROPFILES);
            ULONG i;
            DROPFILES * pDropFiles;
            TCHAR * pData;

            for( i = 1; i <= ulFiles; i++ )
               ulBufSize += ( hb_arrayGetCLen( pArray, i ) + 1 ) * sizeof(TCHAR);
            ulBufSize += sizeof(TCHAR); // For the final NULL character

            hMem = GlobalAlloc( GHND, ulBufSize );
            if( ! hMem )
            {
               hb_retl( 0 );
               return;
            }

            pMem = GlobalLock( hMem );
            pDropFiles = ( DROPFILES * ) pMem;
            pDropFiles->pFiles = sizeof(DROPFILES);
            pDropFiles->pt.x = pDropFiles->pt.y = 0;
            pDropFiles->fNC = FALSE;
            pDropFiles->fWide = sizeof(TCHAR) == sizeof(WCHAR) ? TRUE : FALSE;

            pData = ( TCHAR * ) ( ( BYTE * ) pMem + sizeof(DROPFILES) );
            for( i = 1; i <= ulFiles; i++ )
            {
               hb_strncpy( pData, hb_arrayGetCPtr( pArray, i ), hb_arrayGetCLen( pArray, i ) );
               pData += hb_arrayGetCLen( pArray, i ) + 1;
            }
            *pData = '\0';

            GlobalUnlock( hMem );
            hb_retl( SetClipboardData( CF_HDROP, hMem ) != NULL );
         }
         break;              

         #ifdef __FLAT__
            #ifndef UNICODE
               case CF_ENHMETAFILE:
                    break;
            #endif
         #endif
      }
   }
}
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Copy several files to the clipboard

Postby Natter » Tue May 09, 2023 6:59 pm

Thank you, Antonio, this is what I need!!!
Natter
 
Posts: 1215
Joined: Mon May 14, 2007 9:49 am

Re: Copy several files to the clipboard

Postby MMK » Thu May 11, 2023 9:27 am

And how to activate the changes in clpbrd.c? Do I need to rebuild the library (which one) or is there another way?
MMK
 
Posts: 13
Joined: Thu Jan 22, 2009 6:24 am

Re: Copy several files to the clipboard

Postby Antonio Linares » Thu May 11, 2023 9:28 am

Simply modify clpbrd.c, compile it and link the resulting OBJ to your EXE
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Copy several files to the clipboard

Postby nageswaragunupudi » Fri May 12, 2023 4:34 am

From the next version FWH2305 onwards, you can simply call:
Code: Select all  Expand view
FW_CopyToClipboard( aFiles ) --> lSuccess
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10625
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Copy several files to the clipboard

Postby Natter » Fri May 12, 2023 8:44 am

Thank you, this is good news !
Natter
 
Posts: 1215
Joined: Mon May 14, 2007 9:49 am


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 68 guests