Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How I can hook drag-and-drop operation

Posted on 1999-09-08
14
Medium Priority
?
1,372 Views
Last Modified: 2012-06-21
I need change file witch draging to my file ?
How I can this?

My application need to exchange file witch user move with drag-and-drop operation ( and drop to specific app )
0
Comment
Question by:cdesigner
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
14 Comments
 
LVL 6

Expert Comment

by:WxW
ID: 2031225
Please clear your question.
0
 
LVL 9

Author Comment

by:cdesigner
ID: 2031247
Edited text of question.
0
 
LVL 86

Expert Comment

by:jkr
ID: 2031314
Do you want to receive the file name?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 9

Author Comment

by:cdesigner
ID: 2031326
yes
I need to exchange file name to my file
0
 
LVL 86

Accepted Solution

by:
jkr earned 200 total points
ID: 2031352
Aaah, In this case use:

(Plain Win32, no MFC or so ;-)

LONG FAR PASCAL WndProc(HWND     hWnd,
                        unsigned uMsg,
                        WPARAM   wParam,
                        LPARAM   lParam)
{

  //Process messages  
   switch(uMsg)
   {
    case WM_CREATE: //Window creation actions
                   {
                    //Tell the shell that we accep dragged files ...  
                    DragAcceptFiles(hWnd, TRUE);

                    break;

    case WM_DROPFILES: DragFunc(hWnd, wParam); //Something was dropped - OK!
                       break;

//...
   }


void DragFunc(HWND hWnd, WPARAM wParam)
{
int       i, nFiles;
char      acFile[MAX_PATH];

// get number of files dropped...
nFiles = DragQueryFile((HANDLE) wParam, 0xFFFFFFFF, (LPSTR) NULL, 0);

       for (i = 0; i < nFiles; i++)
           {
            DragQueryFile((HANDLE) wParam, i, acFile, sizeof(acFile));

            // do something with it - the filename is stored in 'acFile'
           }
}

Feel free to ask if you need more information!
0
 
LVL 9

Author Comment

by:cdesigner
ID: 2031370
OK I already have ContextMenu item
Drag and drop similary to this?
can you send me source more?
ICQ EMAIL AIM ... ?
0
 
LVL 9

Author Comment

by:cdesigner
ID: 2031395
I need hook drag and drop  not to My app!!!
0
 
LVL 86

Expert Comment

by:jkr
ID: 2031543
So you're trying to do this using the explorer's context menu?
0
 
LVL 9

Author Comment

by:cdesigner
ID: 2032110
No
but I read in book this very similary to IContextMenu interface.

0
 
LVL 86

Expert Comment

by:jkr
ID: 2033195
Hmm - to see if I get it right: You're about to monitor drag and drop operations to 3rd party apps and want to receive the name of the files dropped?
0
 
LVL 9

Author Comment

by:cdesigner
ID: 2033425
yes
and replase dragged filename
0
 
LVL 86

Expert Comment

by:jkr
ID: 2033519
I suggest using a global message hook to accomplish this:

(In order to capture messages from an application different to your process, you'll have to use a global hook, which must reside in a DLL,as it is mapped to the other processes' address space)

mydll.h:

#ifdef __DLL // assume this is defined when building the DLL
#define __DYNLINK __declspec( dllexport)
#else
#define __DYNLINK __declspec( dllimport)
#endif

// prototypes
LONG __DYNLINK SetHook  ();
LONG __DYNLINK UnHook  ();

mydll.cpp:

#define __DLL

#ifndef _DEBUG
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>

#ifdef _DEBUG
#include <crtdbg.h>
#endif

#pragma data_seg( ".shared")
HHOOK g_hhk = NULL;
#pragma data_seg()

HINSTANCE   g_hThisDll;


LRESULT CALLBACK    HookProc    (   int     nCode,  
                                    WPARAM  wParam,
                                    LPARAM  lParam  
                                );

int APIENTRY    DllMain (   HINSTANCE   hInstance,
                            DWORD       dwReason,
                            LPVOID      lpReserved
                        )
{
    if  (   dwReason    ==  DLL_PROCESS_ATTACH)
        {
            g_hThisDll  =   hInstance;

            return  (   DisableThreadLibraryCalls   (   g_hThisDll));
        }


    return( TRUE);
}

LRESULT CALLBACK HookProc   (   int     nCode,  // hook code
                                WPARAM  wParam, // removal flag
                                LPARAM  lParam  // address of structure with message
                            )
{
    PMSG    pmsg    =   ( PMSG) lParam;

    if  (   0   >   nCode   ||  PM_NOREMOVE ==  wParam)
        {
            return  (   CallNextHookEx  (   g_hhk,
                                            nCode,
                                            wParam,
                                            lParam
                                        )
                    );
        }

    if  (       WM_DROPFILES  ==  pmsg->message    
        )
        {
            /* this one is for us */
            DragFunc(pmsg->hwnd, pmsg->wParam);
        }

    return  (   CallNextHookEx  (   g_hhk,
                                    nCode,
                                    wParam,
                                    lParam
                                )
            );
}

LONG __DYNLINK SetHook  ()
{
    if  (   g_hhk)  return  (   ERROR_ALREADY_EXISTS);

    g_hhk   =   SetWindowsHookEx    (   WH_GETMESSAGE,
                                        ( HOOKPROC) HookProc,
                                        g_hThisDll,
                                        0
                                    );

    return  (   0);
}

LONG __DYNLINK UnHook   ( void)
{

    UnhookWindowsHookEx (   g_hhk);

    g_hhk   =   NULL;

    return  (   0);
}

Simply call 'SetHook()' from your app, and the DLL sets the hook...
0
 
LVL 9

Author Comment

by:cdesigner
ID: 2043128
hey
I build Dll
and call SetHook from my app
But drag-and-drop not worked...
dll runned ...
0
 

Expert Comment

by:packetpimps
ID: 11822731
Will this work for just dragging and dropping text?  I need to beable to monitor, system wide, all drag and dropped files and text.  I am familiar with global hooking, but just dont know what message to watch for.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

664 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question