Click here to Skip to main content
13,195,026 members (100,820 online)
Click here to Skip to main content
Add your own
alternative version


23 bookmarked
Posted 6 Aug 2007

Drag and Drop on a Tray Icon

, 6 Aug 2007
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


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!


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);
        hWnd = FindWindowEx(hWnd,NULL,"TrayNotifyWnd", NULL);
            hWnd = FindWindowEx(hWnd,NULL,"SysPager", NULL);
                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.



  • 2007-08-07 Initial release


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


About the Author

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

You may also be interested in...

Comments and Discussions

Answerworking method of dragdrop onto a systray notification icon (without hooking) Pin
arnoudmulder21-Mar-11 13:53
memberarnoudmulder21-Mar-11 13:53 
Questionquery dropped filenames? Pin
IBM CH DevGroup10-Oct-08 23:31
memberIBM CH DevGroup10-Oct-08 23:31 
AnswerRe: query dropped filenames? Pin
Sven So.12-Oct-08 19:44
memberSven So.12-Oct-08 19:44 
Unfortunately not, I was hoping that someone here has a solution, that's why I posted the article unfinished. I am sorry. Do you have a way to get that info?
GeneralRe: query dropped filenames? Pin
Ben Voigt26-Oct-10 16:25
memberBen Voigt26-Oct-10 16:25 
GeneralC# Pin
Member 301674124-May-08 12:55
memberMember 301674124-May-08 12:55 

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

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

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