ドラッグ&ドロップのサンプル
#include "stdafx.h"
#define MAX_LOADSTRING 100
#include <Windows.h>
typedef struct _DROPFILES {
DWORD pFiles;
POINT pt;
BOOL fNC;
BOOL fWide;
} DROPFILES, *LPDROPFILES;
const char *FileNameList[]={
"C:\\Users\\ookubo\\Desktop\\ivent.vbs",
NULL,
};
INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR arg, INT cmdShow)
{
HWND hwnd;
hwnd = FindWindow(NULL,"Adobe Reader");
#if 0
//アプリケーションの終了
if(hwnd != NULL){
PostMessage(hwnd,WM_CLOSE,NULL,NULL);
}
#endif
//ドラッグ&ドロップイベントの作成
// ファイル名の記述に必要なメモリ量を計算
int size=0;
for(int i=0;FileNameList[i];i++)
size+=strlen(FileNameList[i])+1;
size++;
HANDLE hMem=GlobalAlloc(GMEM_ZEROINIT,sizeof(DROPFILES)+size);
char *p=(char *)GlobalLock(hMem);
DROPFILES *DropFiles=(DROPFILES *)p;
DropFiles->pFiles=sizeof(*DropFiles);
DropFiles->pt.x=20;
DropFiles->pt.y=30;
DropFiles->fNC=1;
DropFiles->fWide=0;
p+=sizeof(*DropFiles);
for(int i=0;FileNameList[i];i++){
strcpy(p,FileNameList[i]);
p+=strlen(p)+1;
}
*p='\0';
GlobalUnlock(hMem);
PostMessage(hwnd,WM_DROPFILES,(WPARAM)hMem,0);
return 0;
}
最終更新:2009年12月18日 01:02