读书人

VC 如何获取选中的文件文件夹的的决

发布时间: 2013-03-20 15:25:24 作者: rapoo

VC 怎么获取选中的文件,文件夹的的决定路径
请教下IShellExtInit::Initialize这个函数
HRESULT Initialize( PCIDLIST_ABSOLUTE pidlFolder,
IDataObject *pdtobj,
HKEY hkeyProgID
);
我理解的是第一参数是指向的选中的文件夹的完整路径,但是我用log打出来不是,是加载的dll的全路径,使用的是SHGetPathFromIDList(pidlFolder, m_szFolderDroppedIn);这个函数,第一个参数是获取的路径,是不是我的函数使用的不正确,
请问怎么可以获取我点击的那个文件或文件夹的全路径呢?谢谢! VC?获取绝对路径
[解决办法]

// IShellExtInit::Initialize
HRESULT CCopyPathExt::Initialize(LPCITEMIDLIST /*pidlFolder*/, LPDATAOBJECT lpdobj, HKEY /*hKeyProgID*/)
{
try {

if ( lpdobj == NULL )
return E_INVALIDARG;


const HINSTANCE hinst = _Module.GetResourceInstance();
if ( hinst ) {
m_hbmpUnchecked = ::LoadBitmap( hinst, MAKEINTRESOURCE( IDB_CopyPath ) );
if ( m_hbmpUnchecked ) {
// We loaded the bitmap, so attach the CBitmap to it.
VERIFY( m_bmp.Attach ( m_hbmpUnchecked ) );
}
}

// Get the data as CF_HDROP
STGMEDIUM medium;
FORMATETC fe = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
HRESULT hr = lpdobj->GetData( &fe, &medium );
if ( FAILED( hr ) )
return E_INVALIDARG;

// Get the number of selected files
m_cFiles = DragQueryFile( reinterpret_cast<HDROP>(medium.hGlobal), 0xFFFFFFFF, NULL, NULL );

// Build the list of file names
m_lstFiles.clear();
for ( int iFile = 0; iFile < m_cFiles; iFile++ )
{
// Get the name of the selected file
memset( m_szFile, 0, sizeof m_szFile );
DragQueryFile( reinterpret_cast<HDROP>(medium.hGlobal),
iFile,


m_szFile,
sizeof(m_szFile)/sizeof(m_szFile[0]) );
m_lstFiles.push_back( m_szFile );
}

ReleaseStgMedium(&medium);
return hr;

} catch ( ... ) {
return E_FAIL;
}
}


[解决办法]
这是从一个对文件、文件夹、逻辑盘都起作用的ToDir.dll(Shell Extension)的注册表项提取结果。
注意其中11、13、15行内容。

[解决办法]
另外提醒注意5楼代码。

读书人网 >C++

热点推荐