Programming/Delphi
파일을 폼으로 Drag&Drop 하기
통통만두
2011. 7. 5. 14:14
반응형
탐색기 같은 곳에서 파일을 Drag&Drop 하여 폼에 올리고 싶은 경우에는 아래와 같이 하면 된다.
// uses 절에 ShellAPI 를 추가하고, FormCreate 같은 곳에 아래와 같은 코드를 추가한다. DragAcceptFiles(Handle, True); // 그리고 적당한 곳에 파일이 Drag&Drop 되었을 때 받을 이벤트를 추가한다. procedure WMDropFiles(var Msg: TMessage); message WM_DROPFILES;
procedure TForm1.WMDropFiles(var Msg: TMessage); var DropCnt : Integer; hDropFile : THandle; FileName : array[0..MAX_PATH] of char; FileNameLen : Integer; i : Integer; begin hDropFile := Msg.WParam; try // 드래그 앤 드롭된 파일의 갯수 DropCnt := DragQueryFile(hDropFile, $FFFFFFFF, nil, 0); for i := 0 to DropCnt - 1 do begin // 드롭된 파일경로 길이 FileNameLen := DragQueryFile(hDropFile, i, nil, 0); // 드롭된 파일경로 DragQueryFile(hDropFile, i, FileName, FileNameLen + 1); // 여기다가 작업을 추가하면 된다. end; finally DragFinish(hDropFile); Msg.Result := 0; // 현재 폼을 활성화 시켜주는 쎈스! SetForegroundWindow(Handle); end; end;참 쉽죠잉~?
반응형