トップ回答者
COleDropTarget:複数のファイルがドロップされたときの処理

質問
-
こんにちは。
COleDropTarget::OnDrop をオーバーロードして、ドラッグ&ドロップを実現するプログラムを作成しています。
(Azulean 様には貴重な情報を頂いて、たいへんお世話になりました。)
今回質問したい内容は複数の特殊ファイル・フォルダ(マイコンピュータ、マイネットワーク、コンパネのアイテムなど)が複数選択された状態で同時に全選択ファイルをドロップされたとき、それをどう1件ずつクエリーすればいいのか教えていただきたいのです。
たとえば、
BOOL CDropTarget::OnDrop(CWnd *pWnd, COleDataObject *pDataObject, DROPEFFECT dropEffect, CPoint point)
で、
if( pDataObject->IsDataAvailable(CF_HDROP) )
が真であれば、
HDROP hdrop = (HDROP)GlobalLock(stgmed.hGlobal);
さえすれば、
int drop_cnt = DragQueryFile( hdrop , (DWORD)-1, NULL, 0 );
for( int i = 0; i < drop_cnt; i++ ){
char lpszFile[MAX_PATH];DragQueryFile( hdrop , i, lpszFile, sizeof(lpszFile) );
…のようにひとつひとつドロップされたファイルに分割できるのですが、
if( pDataObject->IsDataAvailable(RegisterClipboardFormat( CFSTR_SHELLIDLIST ) ) )
のように特殊ファイルをCFSTR_SHELLIDLIST で取得した場合、
前述のように、複数のドロップされたファイルを1件ずつ分解することは可能でしょうか?
可能であれば、そのやり方(キーワードだけでも)を教えてください。
よろしくお願いいたします。
回答
-
kokuchin さんからの引用 if( pDataObject->IsDataAvailable(RegisterClipboardFormat( CFSTR_SHELLIDLIST ) ) )
のように特殊ファイルをCFSTR_SHELLIDLIST で取得した場合、
前述のように、複数のドロップされたファイルを1件ずつ分解することは可能でしょうか?
前の記事で書きましたURLから辿れば分かると思います。
http://msdn.microsoft.com/en-us/library/bb776902(VS.85).aspx#CFSTR_SHELLIDLIST
The structure's hGlobal member points to a CIDA structure.
The aoffset member of the CIDA structure is an array containing offsets to the beginning of the ITEMIDLIST structure for each PIDL that is being transferred. To extract a particular PIDL, first determine its index. Then, add the aoffset value that corresponds to that index to the address of the CIDA structure.
The first element of aoffset contains an offset to the fully qualified PIDL of a parent folder. If this PIDL is empty, the parent folder is the desktop. Each of the remaining elements of the array contains an offset to one of the PIDLs to be transferred. All of these PIDLs are relative to the PIDL of the parent folder.
CIDA構造体であるから、CIDA構造体のヘルプを見れば要素数は分かりますよね。
あとは0番目の要素と1番目の要素の連結、0番目の要素と2番目の要素の連結の繰り返しでしょう。
すべての返信
-
kokuchin さんからの引用 if( pDataObject->IsDataAvailable(RegisterClipboardFormat( CFSTR_SHELLIDLIST ) ) )
のように特殊ファイルをCFSTR_SHELLIDLIST で取得した場合、
前述のように、複数のドロップされたファイルを1件ずつ分解することは可能でしょうか?
前の記事で書きましたURLから辿れば分かると思います。
http://msdn.microsoft.com/en-us/library/bb776902(VS.85).aspx#CFSTR_SHELLIDLIST
The structure's hGlobal member points to a CIDA structure.
The aoffset member of the CIDA structure is an array containing offsets to the beginning of the ITEMIDLIST structure for each PIDL that is being transferred. To extract a particular PIDL, first determine its index. Then, add the aoffset value that corresponds to that index to the address of the CIDA structure.
The first element of aoffset contains an offset to the fully qualified PIDL of a parent folder. If this PIDL is empty, the parent folder is the desktop. Each of the remaining elements of the array contains an offset to one of the PIDLs to be transferred. All of these PIDLs are relative to the PIDL of the parent folder.
CIDA構造体であるから、CIDA構造体のヘルプを見れば要素数は分かりますよね。
あとは0番目の要素と1番目の要素の連結、0番目の要素と2番目の要素の連結の繰り返しでしょう。
-
Azulean さんからの引用 前の記事で書きましたURLから辿れば分かると思います。
http://msdn.microsoft.com/en-us/library/bb776902(VS.85).aspx#CFSTR_SHELLIDLIST
The structure's hGlobal member points to a CIDA structure.
The aoffset member of the CIDA structure is an array containing offsets to the beginning of the ITEMIDLIST structure for each PIDL that is being transferred. To extract a particular PIDL, first determine its index. Then, add the aoffset value that corresponds to that index to the address of the CIDA structure.
The first element of aoffset contains an offset to the fully qualified PIDL of a parent folder. If this PIDL is empty, the parent folder is the desktop. Each of the remaining elements of the array contains an offset to one of the PIDLs to be transferred. All of these PIDLs are relative to the PIDL of the parent folder.
CIDA構造体であるから、CIDA構造体のヘルプを見れば要素数は分かりますよね。
あとは0番目の要素と1番目の要素の連結、0番目の要素と2番目の要素の連結の繰り返しでしょう。
なんと!
簡単だったのですね。10分でできちゃいました。
今回も本当にありがとうございました。