/*
  * Class:     sun_awt_shell_Win32ShellFolder
  * Method:    getIcon
  * Signature: (JJZ)J
  */
 JNIEXPORT jlong JNICALL Java_sun_awt_shell_Win32ShellFolder_getIcon__JJZ
 (JNIEnv* env, jobject folder, jlong parentIShellFolder, jlong relativePIDL,
  jboolean getLargeIcon)
 {
     IShellFolder* pParent = (IShellFolder*)parentIShellFolder;
     if (pParent == NULL) {
         return 0;
     }
     LPITEMIDLIST pidl = (LPITEMIDLIST)relativePIDL;
     if (pidl == NULL) {
         return 0;
     }
     IExtractIcon* pIcon;
     if (pParent->GetUIObjectOf(NULL, 1, const_cast<LPCITEMIDLIST*>(&pidl),
                                IID_IExtractIcon, NULL, (void**)&pIcon) != S_OK) {
         return 0;
     }
     CHAR szBuf[MAX_PATH];
     INT index;
     UINT flags;
     if (pIcon->GetIconLocation(
                 GIL_FORSHELL, szBuf, MAX_PATH, &index, &flags)
             != S_OK) {
         pIcon->Release();
         return 0;
     }
     HICON hIcon;
     HICON hIconLarge;
     if (pIcon->Extract(szBuf, index, &hIconLarge, &hIcon, (16 << 16) + 32) != S_OK) {
         pIcon->Release();
         return 0;
     }
     return (jlong)(getLargeIcon ? hIconLarge : hIcon);
 }
Example #2
0
QString FhoIcon::getImageIdForFile(IShellFolder *psfParentItem, LPITEMIDLIST pidlChildItem) {
	HRESULT hres;
	IExtractIcon *pExtractIcon = NULL;

	hres = psfParentItem->GetUIObjectOf(NULL, 1, const_cast<LPCITEMIDLIST *>(&pidlChildItem), IID_IExtractIcon, NULL, reinterpret_cast<LPVOID *>(&pExtractIcon));
	if (SUCCEEDED(hres)) {
		TCHAR str[MAX_PATH] = {0};
		int index;
		UINT flags;

		// Get the file location where the icons are stored.
		hres = pExtractIcon->GetIconLocation(0, str, MAX_PATH, &index, &flags);
		if (SUCCEEDED(hres)) {
            QString iconResourceFile = QString::fromWCharArray(str);
			// this may return "*" and does not always refer to a real existing file; see above!
			
			QString imageId = "@" + iconResourceFile + "," + QString::number(index); // did we already expand the resource file name?
			return imageId;
		} else {
			return getImageIdForFile(pidlChildItem);
		}
		pExtractIcon->Release();
	} else {
		return getImageIdForFile(pidlChildItem);
	}
}
Example #3
0
QImage FhoIcon::getIconForFile(IShellFolder *psfParentItem, LPITEMIDLIST pidlChildItem) {
	HRESULT hres;
	IExtractIcon *pExtractIcon = NULL;

	hres = psfParentItem->GetUIObjectOf(NULL, 1, const_cast<LPCITEMIDLIST *>(&pidlChildItem), IID_IExtractIcon, NULL, reinterpret_cast<LPVOID *>(&pExtractIcon));
	if (SUCCEEDED(hres)) {
		TCHAR str[MAX_PATH] = {0};
		int index;
		UINT flags;

		// Get the file location where the icons are stored.
		hres = pExtractIcon->GetIconLocation(0, str, MAX_PATH, &index, &flags);
		//hres = pExtractIcon->GetIconLocation(GIL_FORSHELL, str, MAX_PATH, &index, &flags);
		if (SUCCEEDED(hres)) {
            QString iconResourceFile = QString::fromWCharArray(str);
			
			// do not use 'general' getIconFromResource() -> ExtractIcon()!
			// use 'specific' pExtractIcon->Extract() instead!
			// this is because iconResourceFile returned may be "*" and not refer to a real file! pExtractIcon->Extract() will handle this, ExtractIcon() cannot handle this!
			// "*" is dangerous for caching the imageId! we could check if iconResourceFile refers to an existing file!?
			HICON hIconLarge = NULL;
			UINT nIconSize = MAKELONG(0, 0); // this requests the default size!?
			hres = pExtractIcon->Extract(str, index, &hIconLarge, NULL, nIconSize);
			if (hres == NOERROR) {
				if (hIconLarge) {
					QImage image = getIconFromHandle(hIconLarge);
				
					DestroyIcon(hIconLarge);

					return image;
				} else {
					return getIconFromResource(iconResourceFile, index);
				}
			} else {
				return getIconFromResource(iconResourceFile, index);
			}
		} else {
			return getIconForFile(pidlChildItem);
		}
		pExtractIcon->Release();
	} else {
		return getIconForFile(pidlChildItem);
	}
}
Example #4
0
BOOL CPropertiesCtrl::OnExpanding( HTREEITEM hItem, UINT nCode )
{
	int i, nChild = 0;
	CFTCItemData * pItemData = (CFTCItemData*)GetItemData( hItem );

	switch( nCode )
	{
		case TVE_EXPAND:
			{
				CWaitCursor cur;
				nChild = GetChildCount( hItem );
				for( i = 0; i < nChild; i++ )
				{
					DelItemRecursive( GetNextItem( hItem, TVGN_CHILD ) );
					Invalidate();
				}

				CComPtr<IEnumIDList> piIDList;
				ULONG nRes = 0;
				ITEMIDLIST * pItem = NULL;
				HRESULT hr = pItemData->m_piFolder->EnumObjects( NULL, SHCONTF_FOLDERS, &piIDList );
				_STRRET strret;
				CSCADString sPath, sName;
				IExtractIcon * piEI = NULL;
				IShellFolder * piChildFolder = NULL;

				if( hr != NOERROR )
				{
					Invalidate();
					return FALSE;
				}
				for( hr = piIDList->Next( 1, &pItem, &nRes ); hr == NOERROR && nRes > 0; hr = piIDList->Next( 1, &pItem, &nRes ) )
				{
					hr = pItemData->m_piFolder->GetDisplayNameOf( pItem, SHGDN_INFOLDER, &strret );
					sName = StrRetToStr(pItem, strret, true, m_piMalloc );
					hr = pItemData->m_piFolder->GetDisplayNameOf( pItem, SHGDN_NORMAL | SHGDN_FORPARSING, &strret );
					sPath = StrRetToStr(pItem, strret, true, m_piMalloc );
					hr = pItemData->m_piFolder->GetUIObjectOf( NULL, 1, (LPCITEMIDLIST*)&pItem, IID_IExtractIcon, NULL, (void**)&piEI );
					hr = pItemData->m_piFolder->BindToObject( pItem, NULL, IID_IShellFolder, (void**)&piChildFolder );
					if( piChildFolder )
					{
						if( !piEI )
						{
							//hr = piChildFolder->CreateViewObject( NULL, IID_IExtractIcon, (void**)&piEI );
						}
						//InsertFolder( pItem, piChildFolder, piEI, sName, sPath, hItem );
						piChildFolder->Release();
						piChildFolder = NULL;
					}
					if( piEI )
					{
						piEI->Release();
						piEI = NULL;
					}
				}
			}
			return TRUE;
		default:
			nChild = GetChildCount( hItem );
			for( i = 0; i < nChild; i++ )
				DelItemRecursive( GetNextItem( hItem, TVGN_CHILD ) );
			if( !IsFolderEmpty( pItemData->m_piFolder ) )
				InsertItem( _T(""), hItem, TVI_LAST );
			break;
	}

	return TRUE;
}