So I've desperately been trying to automate drag and drop functionality, and have narrowed my search for solutions down to a fairly refined chunk of code:
// DragAndDrop.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <Windows.h>
#include <Shlobj.h>
#include <tchar.h>
int main(int argc, char* argv[]) {
for (int i = 0; i <= WM_DROPFILES; i++)
{
ChangeWindowMessageFilter (i, MSGFLT_ADD);
}
if (HWND hwnd = FindWindow ("OpusApp", NULL)) {
//HGLOBAL hGlobal = GlobalAlloc (GMEM_FIXED,
//sizeof ("d:\\DragMe.txt") + 2);
//char *strFile = (char*) GlobalLock
//(hGlobal);
//strcpy (strFile, "d:\\DragMe.txt");
//strFile [strlen ("d:\\DragMe.txt") +
//1] = NULL;
char filename[] = "d:\\DragMe.txt";
POINT point;
point.x = 480;
point.y = 480;
HGLOBAL hMem = GlobalAlloc(GHND, sizeof(DROPFILES) + strlen(filename)+2);
DROPFILES *dfiles = (DROPFILES*) GlobalLock(hMem);
if (!dfiles)
{
GlobalFree(hMem);
return NULL;
}
dfiles->pFiles = sizeof(DROPFILES);
dfiles->pt = point;
dfiles->fNC = TRUE;
dfiles->fWide = FALSE;
memcpy(&dfiles[1], filename, strlen(filename));
GlobalUnlock(hMem);
printf ("Sending Message...\n");
if (!PostMessage(hwnd, WM_DROPFILES, (WPARAM)hMem, 0)) {
printf("Error Posting Message!");
GlobalFree(hMem);
}
}
int temp = 0;
scanf("&d", temp);
return 0;
}
... I apologize for any bad words in my code... they are just for debugging purposes. Anyway, the above is very simple, and it works with Microsoft Word, Excel, and Notepad... but for a number of applications it does not work at all (Spy++ does not even log a WM_DROPFILES message system-wide in these cases, which is strange...). I have even tried compiling the code as x64 or x86 for the problem applications, but no change...
I feel like I may be using FindWindow incorrectly (I'm using the Window Info Tool bundled with AutoIT to get the window class, as I find Spy++ pretty confusing). In anycase, I am setting a bounty because I realllllllly need to get this figured out.
The application I will need to use this with is named Dartfish, and it is a 32-bit app on Windows 7... I need to send a list of video files to a specific region of its interface (specific pane), and I am trying to do this with the above code.
Any help? I greatly appreciate it!!