김상면 님이 쓰신 글 :
: 일반 윈도우에서 Drag&Drop하는 방법 알켜주세요!
: 그럼
mainunit.cpp :
void __fastcall TMainform::DropFile(String filename)
{
ShowMessage(filename); // filename check
}
mainunit.h :
class TMainform : public TForm
{
public: // User declarations
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_DROPFILES, TWMDropFiles, WMDropFiles) // Drop Message Handler.
END_MESSAGE_MAP(TForm)
// Drag & Drop Message Handler
void __fastcall WMDropFiles(TWMDropFiles &Msg)
{
int nFileCount = DragQueryFile((HDROP)Msg.Drop, 0xFFFFFFFF, NULL, 0);
for(int i = 0; i < nFileCount; i++)
{
TCHAR filename[MAX_PATH];
int nLength = DragQueryFile((HDROP)Msg.Drop, i, filename, MAX_PATH);
// Do something..
if (nLength) DropFile(filename);
}
DragFinish((HDROP)Msg.Drop);
}
// Drag to WinControl, call it FormCreate Handler.
//
void __fastcall InitDragAccept()
{
DragAcceptFiles(Handle, true);
}
// Drag & Drop Message Handler end
}
Form Create 에서 초기화 한번 호출
InitDragAccept(); // Drag & Drop
하면 됩니다. Drag n Drop 한 파일이름을 DropFile(...) 함수에서 하나씩 처리 됩니다.
|