Drop files from Explorer to HMG Control

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

User avatar
AidTIC
Posts: 117
Joined: Mon Apr 22, 2013 8:29 am
DBs Used: DBF
Contact:

Re: Drop files from Explorer to HMG Control

Post by AidTIC »

AUGE_OHR wrote: Wed Nov 29, 2023 10:05 pm hi.
AidTIC wrote: Wed Nov 29, 2023 4:08 pm It works fine for me when I drag a saved file, but when I drag it from an email (outlook) it doesn't let me.
How could it be implemented?
as i know DragAccept does not support OLE for DragDrop like Outlook Email

---

under Xbase++ there was a Trick to use a IE Window to drop anything you want. not sure if it still work with EDGE
Como podría hacerse??

How could it be done?
Skydone Solutions
www.skydone.com
User avatar
AUGE_OHR
Posts: 2064
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: Drop files from Explorer to HMG Control

Post by AUGE_OHR »

hi,
AidTIC wrote: Mon Dec 04, 2023 12:26 pm How could it be done?
as i say : DragAccept does not support OLE for DragDrop like Outlook Email
if you want to learn OLE Dragdrop have a look at https://www.catch22.net/tuts/ole/
---
under Xbase++ i can use (old) IE Engine to drop a Email from Outlook and save it
i have not try it using harbour yet

Code: Select all

#DEFINE olMSGUnicode    9

Function DoMyDrag(oDlg, oDrag, bArchivname)
   LOCAL oOutlook
   LOCAL aFile := {}
   LOCAL i, iCnt
   LOCAL cBase, cFile

   oDlg:setpointer(, XBPSTATIC_SYSICON_WAIT, XBPWINDOW_POINTERTYPE_SYSPOINTER)

   // email speichern in TEMP
   if oDrag:queryGetFormat( "FileGroupDescriptor")
      oOutlook := createobject("outlook.application")
      if IsObject(oOutlook)
         iCnt  := oOutlook:ActiveExplorer:selection:count
         aFile := array(iCnt)
         for i := 1 to iCnt
            // cBase ist der Betraff der Nachricht
            cBase    := ValidFileName(oOutlook:ActiveExplorer:selection:item(i):subject)

            // dieser Codeblock erzeugt den Name der zu speichernen Datei, incl Pfad, etc
*           aFile[i] := eval( bArchivname, cBase )
            aFile[i] := "C:\TEMP\TEXTXXX"   // use a fix Filename

            oOutlook:ActiveExplorer:selection:item(i):saveas(aFile[i], olMSGUnicode)
         next
         oOutlook:destroy()
      else
         Msgbox("Fehler beim Zugriff auf Outlook !")
      endif
      oOutlook:= NIL

   elseif oDrag:queryGetFormat(XBPCLPBRD_FILELIST)
      aFile := oDrag:getdata( XBPCLPBRD_FILELIST)
      iCnt  := len( aFile)

      for i := 1 to iCnt

            // dieser Codeblock erzeugt den Name der zu speichernen Datei, incl Pfad, etc
            cFile := eval( bArchivname, aFile[i] )

            if fcopy(aFile[i], cFile, .T. )
               aFile[i] := cFile
            else
               aFile[i] := ""
            endif
*        endif
      next
   else
      // kein verarbeitung hier definiert
   endif
   oDlg:setpointer()
RETURN aFile

PROCEDURE DoMyFilename(cIn)
Msgbox(cIn)
RETURN

FUNCTION ValidFileName(cIn)
Msgbox(cIn)
RETURN cIn

FUNCTION fcopy(aFile, cFile )
Msgbox( aFile, cFile )
RETURN .T.
have fun
Jimmy
User avatar
AidTIC
Posts: 117
Joined: Mon Apr 22, 2013 8:29 am
DBs Used: DBF
Contact:

Re: Drop files from Explorer to HMG Control

Post by AidTIC »

Vaya, no se por donde tirar. el C lo tengo oxidado. y el ejemplo que me pones no se que parámetros o de donde los coges (oDlg, oDrag, bArchivname) Estoy perdio.

Wow, I don't know where to go. I have rusty C. and the example you give me, I don't know what parameters or where you get them from (oDlg, oDrag, bArchivname) I'm lost.
Skydone Solutions
www.skydone.com
User avatar
AUGE_OHR
Posts: 2064
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: Drop files from Explorer to HMG Control

Post by AUGE_OHR »

hi,

as i say : i have no harbour Version for it

---

under Xbase++ i have this

Code: Select all

   ::DrawingArea:DropZone   := .T.
   ::DrawingArea:DragEnter  := {|aState,oData| ::HandleDragEnter(aState,oData) }
   ::DrawingArea:DragLeave  := {|aState,uNIL|  ::HandleDragLeave(aState,) }
*   ::DrawingArea:DragDrop   := {|aState,oData| ::HandleDragDrop(aState,oData) }
   ::DrawingArea:DragDrop   := {| aState, oDrag| DoMyDrag(self, oDrag,  {|cBase|  DoMyFilename(cBase) } ) }
IE / EDGE does not need DragAccept. you can drop anything to them direct.

Function DoMyDrag(oDlg, oDrag, bArchivname)
oDlg -> Windows Object here IE "self"
oDrag -> OLE Object -> have no HB_FUNC for queryGetFormat()
bArchivname -> Filename to Save Message
have fun
Jimmy
User avatar
AUGE_OHR
Posts: 2064
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: Drop files from Explorer to HMG Control

Post by AUGE_OHR »

hi,

found out that Fivewin have a OLE Drop_Target Interface

Code: Select all

typedef struct {
    IDropTargetVtbl *lpVtbl;
    ULONG refCount;
    HWND hwnd;
} DropTarget;

HRESULT STDMETHODCALLTYPE DropTarget_QueryInterface(IDropTarget *This, REFIID riid, void **ppvObject);
ULONG STDMETHODCALLTYPE   DropTarget_AddRef(IDropTarget *This);
ULONG STDMETHODCALLTYPE   DropTarget_Release(IDropTarget *This);
HRESULT STDMETHODCALLTYPE DropTarget_DragEnter(IDropTarget *This, IDataObject *pDataObj, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect);
HRESULT STDMETHODCALLTYPE DropTarget_DragOver(IDropTarget *This, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect);
HRESULT STDMETHODCALLTYPE DropTarget_DragLeave(IDropTarget *This);
HRESULT STDMETHODCALLTYPE DropTarget_Drop(IDropTarget *This, IDataObject *pDataObj, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect);

IDropTargetVtbl DropTarget_Vtbl = {
    DropTarget_QueryInterface,
    DropTarget_AddRef,
    DropTarget_Release,
    DropTarget_DragEnter,
    DropTarget_DragOver,
    DropTarget_DragLeave,
    DropTarget_Drop
};

HRESULT STDMETHODCALLTYPE DropTarget_QueryInterface(IDropTarget *This, REFIID riid, void **ppvObject) {
    if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDropTarget)) {
        *ppvObject = This;
        This->lpVtbl->AddRef(This);
        return S_OK;
    }
    *ppvObject = NULL;
    return E_NOINTERFACE;
}

ULONG STDMETHODCALLTYPE DropTarget_AddRef(IDropTarget *This) {
    DropTarget *pThis = (DropTarget *)This;
    return InterlockedIncrement(&pThis->refCount);
}

ULONG STDMETHODCALLTYPE DropTarget_Release(IDropTarget *This) {
    DropTarget *pThis = (DropTarget *)This;
    ULONG refCount = InterlockedDecrement(&pThis->refCount);
    if (refCount == 0) {
        hb_xfree( pThis );
    }
    return refCount;
}

HRESULT STDMETHODCALLTYPE DropTarget_DragEnter(IDropTarget *This, IDataObject *pDataObj, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect) {
    *pdwEffect = DROPEFFECT_COPY;
    return S_OK;
}

HRESULT STDMETHODCALLTYPE DropTarget_DragOver(IDropTarget *This, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect) {
    *pdwEffect = DROPEFFECT_COPY;
    return S_OK;
}

HRESULT STDMETHODCALLTYPE DropTarget_DragLeave(IDropTarget *This) {
    return S_OK;
}

typedef struct {
  DWORD dwSize;
  POINT pt;
  BOOL  fNC;
  BOOL  fWide;
  char  filename[ 1000 ];
} FW_DROPFILES;

static void lMsg( LONG lValue )
{
   char szBuffer[ 320 ];

   wsprintf( szBuffer, "%ld", lValue );
   MessageBox( NULL, szBuffer, "lMsg", MB_TASKMODAL );
}

HRESULT STDMETHODCALLTYPE DropTarget_Drop(IDropTarget *This, IDataObject *pDataObj, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect) {

    FORMATETC fmtetc = {CF_TEXT, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
    STGMEDIUM stgmed;
    HGLOBAL hMem;
    FW_DROPFILES * df;
    
   if (pDataObj->lpVtbl->QueryGetData(pDataObj, &fmtetc) == S_OK) {
       if (pDataObj->lpVtbl->GetData(pDataObj, &fmtetc, &stgmed) == S_OK) {
         #ifdef __BORLANDC__
            HDROP hDrop = ( HDROP ) GlobalLock( stgmed.u.hGlobal );
         #else   
            HDROP hDrop = ( HDROP ) GlobalLock( stgmed.hGlobal );
         #endif   
         hMem = GlobalAlloc( GHND, sizeof( FW_DROPFILES ) );
         df = GlobalLock( hMem );
         df->dwSize = ( INT_PTR ) df->filename - ( INT_PTR ) df;
         df->pt.x = pt.x;
         df->pt.y = pt.y;
         df->fNC = FALSE;
         df->fWide = FALSE;
         lstrcpyn( df->filename, ( char * ) hDrop, 1000 );
         GlobalUnlock( hMem ); 
         SendMessage( ( ( DropTarget * ) This )->hwnd, WM_DROPFILES, ( WPARAM ) hMem, 0 );
         #ifdef __BORLANDC__
            GlobalUnlock( stgmed.u.hGlobal );
         #else   
            GlobalUnlock( stgmed.hGlobal );
         #endif   
         ReleaseStgMedium(&stgmed);
      }
   }  

   GlobalFree( hMem );

   return S_OK;
}

and 2 x HB_FUNC()

Code: Select all

HB_FUNC( REGISTERDRAGDROP )
{
   DropTarget * pDropTarget = ( DropTarget * ) hb_xgrab( sizeof( DropTarget ) );
   HWND hWnd = fw_parH( 1 );

   pDropTarget->lpVtbl = &DropTarget_Vtbl;
   pDropTarget->refCount = 1;
   pDropTarget->hwnd = hWnd;
   
   OleInitialize( NULL );

   RegisterDragDrop( hWnd, ( IDropTarget * ) pDropTarget );  
   hb_retptr( pDropTarget ); 
}

Code: Select all

HB_FUNC( REVOKEDRAGDROP )
{
   RevokeDragDrop( fw_parH( 1 ) );
   OleUninitialize();
}
this is the Demo Sample

Code: Select all

#include "FiveWin.ch"

function Main()

   local oWnd, oBar, oBtn, cDrop := ""
   local lWeb  := .t.

   cDrop := "DROP HERE"

   DEFINE WINDOW oWnd TITLE "Drag&Drop me an Image"
   DEFINE BUTTONBAR oBar OF oWnd SIZE 120,48 //2007

   DEFINE BUTTON oBtn OF oBar PROMPT "Drop From ExternalApp" ;
      FILE "..\bitmaps\32x32\no.bmp","..\bitmaps\32x32\yes.bmp" LEFT ;
      ACTION If( lWeb, nil, ( oWnd:RegisterDragDrop(), lWeb := .t., oBar:Refresh() ) )
   oBtn:bBmpNo := { || If( lWeb, 2, 1 ) }

   DEFINE BUTTON oBtn OF oBar PROMPT "Drop From FileExplorer" ;
      FILE "..\bitmaps\32x32\no.bmp","..\bitmaps\32x32\yes.bmp" LEFT ;
      ACTION If( lWeb, ( oWnd:RevokeDragDrop(), lWeb := .f., oBar:Refresh() ), nil )
   oBtn:bBmpNo := { || If( lWeb, 1, 2 ) }

   oWnd:RegisterDragDrop()
   oWnd:bPainted := { |hDC,p,o| ShowDrop( hDC, o, cDrop ) }

   ACTIVATE WINDOW oWnd ;
      ON DROPFILES ( cDrop := aFiles[ 1 ], oWnd:Refresh() )

return nil

static function ShowDrop( hDC, oWnd, cDrop )

   local cExt
   local aRect    := oWnd:GetCliAreaRect():aRect

   if IsImageExt( cDrop )
      oWnd:DrawImage( cDrop, aRect )
   else
      oWnd:SayText( WrapToWidth( hDC, cDrop, aRect[ 4 ] - aRect[ 2 ], oWnd:oFont ), ;
                    aRect )
   endif

return nil
that CODE need to switch manual before receive DROP
have fun
Jimmy
User avatar
AUGE_OHR
Posts: 2064
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: Drop files from Explorer to HMG Control

Post by AUGE_OHR »

hi,

have try that Fivewin CODE using HMG but got Error/Warning
hbmk2: Compiling...
HB_FUNC.PRG: In function 'DropTarget_AddRef':
HB_FUNC.PRG:919:33: warning: pointer targets in passing argument 1 of 'InterlockedIncrement' differ in signedness [-Wpoi
nter-sign]
In file included from C:/hmg.3.4.4/mingw/i686-w64-mingw32/include/winbase.h:22:0,
from C:/hmg.3.4.4/mingw/i686-w64-mingw32/include/windows.h:70,
from HB_FUNC.PRG:42:
C:/hmg.3.4.4/mingw/i686-w64-mingw32/include/interlockedapi.h:29:37: note: expected 'volatile LONG * {aka volatile long i
nt *}' but argument is of type 'DWORD * {aka long unsigned int *}'
__MINGW_INTRIN_INLINE LONG WINAPI InterlockedIncrement(LONG volatile *lpAddend) {
^
HB_FUNC.PRG: In function 'DropTarget_Release':
HB_FUNC.PRG:924:43: warning: pointer targets in passing argument 1 of 'InterlockedDecrement' differ in signedness [-Wpoi
nter-sign]
In file included from C:/hmg.3.4.4/mingw/i686-w64-mingw32/include/winbase.h:22:0,
from C:/hmg.3.4.4/mingw/i686-w64-mingw32/include/windows.h:70,
from HB_FUNC.PRG:42:
C:/hmg.3.4.4/mingw/i686-w64-mingw32/include/interlockedapi.h:32:37: note: expected 'volatile LONG * {aka volatile long i
nt *}' but argument is of type 'DWORD * {aka long unsigned int *}'
__MINGW_INTRIN_INLINE LONG WINAPI InterlockedDecrement(LONG volatile *lpAddend) {
^
HB_FUNC.PRG: In function 'DropTarget_DragEnter':
HB_FUNC.PRG:931:61: warning: unused parameter 'This' [-Wunused-parameter]
HB_FUNC.PRG:931:80: warning: unused parameter 'pDataObj' [-Wunused-parameter]
HB_FUNC.PRG:931:96: warning: unused parameter 'grfKeyState' [-Wunused-parameter]
HB_FUNC.PRG:931:116: warning: unused parameter 'pt' [-Wunused-parameter]
HB_FUNC.PRG: In function 'DropTarget_DragOver':
HB_FUNC.PRG:936:60: warning: unused parameter 'This' [-Wunused-parameter]
HB_FUNC.PRG:936:72: warning: unused parameter 'grfKeyState' [-Wunused-parameter]
HB_FUNC.PRG:936:92: warning: unused parameter 'pt' [-Wunused-parameter]
HB_FUNC.PRG: In function 'DropTarget_DragLeave':
HB_FUNC.PRG:941:61: warning: unused parameter 'This' [-Wunused-parameter]
HB_FUNC.PRG: In function 'DropTarget_Drop':
HB_FUNC.PRG:962:91: warning: unused parameter 'grfKeyState' [-Wunused-parameter]
HB_FUNC.PRG:962:122: warning: unused parameter 'pdwEffect' [-Wunused-parameter]
HB_FUNC.PRG: In function 'HB_FUN_REGISTERDRAGDROP':
HB_FUNC.PRG:1005:16: warning: initialization makes pointer from integer without a cast [-Wint-conversion]
HB_FUNC.PRG: In function 'HB_FUN_REVOKEDRAGDROP':
HB_FUNC.PRG:1021:16: warning: initialization makes pointer from integer without a cast [-Wint-conversion]
HB_FUNC.PRG:1022:27: error: expected ';' before ')' token
HB_FUNC.PRG:1022:27: error: expected statement before ')' token
HB_FUNC.PRG: At top level:
HB_FUNC.PRG:953:13: warning: 'lMsg' defined but not used [-Wunused-function]
hbmk2[HBFM]: Error: Running C/C++ compiler. 1
gcc.exe -c -O3 -march=i586 -mtune=pentiumpro -fomit-frame-pointer -W -Wall -pipe -IC:/hmg.3.4.4/harbour/include -IC:/hm
g.3.4.4/harbour/contrib/hbmzip -I../../.. -IC:/hmg.3.4.4/include -IC:/hmg.3.4.4/harbour/contrib/hbtip ../../../.hbmk/win
/mingw/HB_FUNC.c
so it seems not compatible with MinGW, or :?:
have fun
Jimmy
User avatar
AidTIC
Posts: 117
Joined: Mon Apr 22, 2013 8:29 am
DBs Used: DBF
Contact:

Re: Drop files from Explorer to HMG Control

Post by AidTIC »

Lo probare y te cuento, yo trabajo con la HMG 3.5.

I'll try it and tell you, I work with the HMG 3.5
Skydone Solutions
www.skydone.com
Post Reply