Page 1 of 1
Copy several files to the clipboard
Posted: Mon May 08, 2023 2:31 pm
by Natter
Hi,
I need to copy several files to the clipboard at the same time. How can I do this ?
Re: Copy several files to the clipboard
Posted: Mon May 08, 2023 6:32 pm
by Natter
It looks like you need to use the function
Clipboard.SetFileDropList() But how to do it under FWH I do not know
Re: Copy several files to the clipboard
Posted: Tue May 09, 2023 12:19 pm
by nageswaragunupudi
Clipboard.SetFileDropList()
This is dot NET.
FWH has not yet provided this.
This will be provided soon.
Re: Copy several files to the clipboard
Posted: Tue May 09, 2023 1:42 pm
by Natter
Thanks, I get it !
Is it possible in FWH to write multiple files to the clipboard at the moment ?
Re: Copy several files to the clipboard
Posted: Tue May 09, 2023 6:35 pm
by Antonio Linares
Dear Yuri,
Here you have a working example:
Code: Select all | Expand
#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
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/windows/win32/api/winuser/nf-winuser-setclipboarddata
// 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
}
}
}
Re: Copy several files to the clipboard
Posted: Tue May 09, 2023 6:59 pm
by Natter
Thank you, Antonio, this is what I need!!!
Re: Copy several files to the clipboard
Posted: Thu May 11, 2023 9:27 am
by MMK
And how to activate the changes in clpbrd.c? Do I need to rebuild the library (which one) or is there another way?
Re: Copy several files to the clipboard
Posted: Thu May 11, 2023 9:28 am
by Antonio Linares
Simply modify clpbrd.c, compile it and link the resulting OBJ to your EXE
Re: Copy several files to the clipboard
Posted: Fri May 12, 2023 4:34 am
by nageswaragunupudi
From the next version FWH2305 onwards, you can simply call:
Re: Copy several files to the clipboard
Posted: Fri May 12, 2023 8:44 am
by Natter
Thank you, this is good news !