Click here to Skip to main content
Click here to Skip to main content

Drag and Drop on a Tray Icon

, 6 Aug 2007 CPOL
Rate this:
Please Sign up or sign in to vote.
How to detect that an item was dropped on a specific tray icon
Screenshot - desktop.jpg

Introduction

If you ever wondered how to catch drag and drop on a tray icon, this article might help you to accomplish this. With the help of other CodeProject contributions, I was able to figure out most of the functionality. One thing I have not been able to get working is to successfully get the HDROP structure that usually ships with the WM_DROPFILES message. If anyone can help me here, it would be very great. Please post it here, thanks!

Background

So, how does one find the right window containing the tray icons? You can use Microsoft Spy++ that ships with Visual Studio. Look for a window called "Shell_TrayWnd" containing another window called "TrayNotifyWnd" which has another child window called "SysPager". The "SysPager" contains the actual window holding all icons called "ToolbarWindow32".

Screenshot - MSSpy__.jpg

HWND FindTrayToolbarWindow()
{
    HWND hWnd = FindWindow("Shell_TrayWnd", NULL);
    if(hWnd)
    {
        hWnd = FindWindowEx(hWnd,NULL,"TrayNotifyWnd", NULL);
        if(hWnd)
        {
            hWnd = FindWindowEx(hWnd,NULL,"SysPager", NULL);
            if(hWnd)
            {                
                hWnd = FindWindowEx(hWnd, NULL,"ToolbarWindow32", NULL);
            }
        }
    }
    return hWnd;
}

After the window is found, you need to figure out the correct icon. This is done by using the POINT send with the WM_DROPFILES and looping through all icons, which are actually buttons. This way, one can figure out on which icon you dropped the files.

Using the Code

The code is split into 2 files. One EXE file that represents the tray icon app and a message hook DLL. The DLL installs a message hook to catch the WM_DROPFILES message and will check if we dropped anything on our tray icon. Then I send the message to the window that belongs to our tray icon app.

To run the code, I recommend using dbgview (in the zip file), before trying the app. I used it to catch the debug messages during the drag and drop operation.

Still as mentioned before, I am missing the part where I should get the a pointer to a HDROP structure from the WM_DROPFILES messages. Somehow the message doesn't contain that even though it should. If one could figure out what's wrong there, I would be quite happy.

References

History

  • 2007-08-07 Initial release

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Sven So.
Software Developer (Senior) biggest furniture dealer in the world
Germany Germany
No Biography provided

Comments and Discussions

 
GeneralC# PinmemberMember 301674124-May-08 13:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141223.1 | Last Updated 7 Aug 2007
Article Copyright 2007 by Sven So.
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid