I am trying to enable drag and drop on the tray icon in my application.
I know it is not possible to do this using the C # WindowsForms top-level APIs, since NotifyIcon does not support drag and drop events.
So, a little helping a more experienced friend from Windows, I decided to try this through the Win32 API. The idea was to register the hook in the tray window handler (after installing DragAcceptFiles(hWnd,TRUE); in the SysPager window handler).
The catching and dropping part works from the tray in the DLL.
LRESULT CALLBACK myHookProc (int code, WPARAM wParam, LPARAM lParam){ if (code == HC_ACTION) { PMSG msg = (PMSG) lParam; switch(msg->message){ case WM_DROPFILES: ::MessageBox(NULL, L"Dropped files!", L"Test", MB_OK);
As expected, I get a message box.
The problem is that now I need to call a function in my C # application (WindowsForms) to notify about this event. Here, where I ran into a brick wall.
When I register a callback from my application in the DLL, I store it; but when myHookProc is myHookProc , the value is NULL.
Turns out I don't understand how DLLs work; there is no common instance between my application and the tray area (they are copied or each has its own โinstanceโ if you could name it), so I canโt use any static variables or something like that to store the opposite call back to my application.
Spent a couple of hours researching this, and the only solution seems to be shared memory (tried #pragma data_seg , which I came across on some forum, but to no avail), but it starts to feel too much excess for such a โsimpleโ use case .
So, the million dollar questions:
- Is it really necessary to disable DLL binding?
- Do I need to resort to shared memory for this?
- (Bonus question) WM_DROPFILES only works for files; how can i get the drop event fired for text?
Please keep in mind that this is my first snapshot with .NET, C # and Win32 (less than a week); detailed answers explaining why - and not just an expression - we will be very grateful!
Thanks.