-
...how will I know...?
I need to recieve data dragged from another application into my program in the form of Clipboard data. Question: how will I know when the user has dropped the data "in" (my app will already be running)? I will use a thread, presumably, but I just don't know when to initiate the transfer. I thougt maybe windows sends my app a message, but of the possible ones, none seemed conspicuous. Nonetheless, I'll try those first, but if anyone here knows, I'd appreciate the tip!
-
Aargh! One more thing. Windows won't let me drag anything onto my app anyway! How do I tell it to do so?
-
got it!
Ok, here's a little class that will take care of the implementation.
Just be sure to place the Allow() function under your WM_DROPFILES handler, and pass it your WPARAM.
Enjoy.
Code:
class DragDrop {
public:
int file_count;
String * files;
void Allow(HWND hwnd) {
DragAcceptFiles(hwnd, TRUE);
}
bool Accept(WPARAM wp) {
if( files ){
delete [] files;
}
iter = 0;
data = (HDROP)wp;
file_count = DragQueryFile(data, 0xFFFFFFFF, NULL, 0);
files = new String[ file_count ];
if( files == NULL ){
return false;
}
while(iter < file_count) {
DragQueryFile(data, iter, buffer, 256);
files[iter++] = buffer;
}
DragFinish(data);
return true;
}
DragDrop()
:files(NULL) {
/* */
}
~DragDrop() {
if( files ){
delete [] files;
}
}
private:
HDROP data;
int iter;
char buffer[256];
};
-
I've had this in my favorites for a while, I hope it's of use to you: http://cprogramming.com/cboard/showt...&threadid=7829
-
...or can register your wnd as a drop target by giving it the WS_EX_ACCEPTFILES extended style. Presumably that's what DragAcceptFiles does: calls SetWindowLong with the GWL_EXSTYLE flag to set the extended style bit.