- eliminate MSVC type conversion warning

- IShellLink::GetIconLocation(): get icons for shell links if not
  already set
This commit is contained in:
Martin Fuchs 2004-04-12 23:12:39 +00:00 committed by Alexandre Julliard
parent a1f01d353c
commit 1ab301d7be
1 changed files with 124 additions and 13 deletions

View File

@ -289,7 +289,7 @@ static HRESULT WINAPI IPersistFile_fnSave(IPersistFile* iface, LPCOLESTR pszFile
TRACE("(%p)->(%s)\n",This,debugstr_w(pszFileName));
if (!pszFileName || !This->sPath)
return ERROR_UNKNOWN;
return E_FAIL;
r = CreateStreamOnFile(pszFileName, STGM_READWRITE | STGM_CREATE, &stm);
if( SUCCEEDED( r ) )
@ -546,7 +546,7 @@ static HRESULT WINAPI IPersistStream_fnLoad(
if( FAILED( r ) )
return r;
}
This->wHotKey = hdr.wHotKey;
This->wHotKey = (WORD)hdr.wHotKey;
This->iIcoNdx = hdr.nIcon;
FileTimeToSystemTime (&hdr.Time1, &This->time1);
FileTimeToSystemTime (&hdr.Time2, &This->time2);
@ -1195,20 +1195,75 @@ static HRESULT WINAPI IShellLinkA_fnSetShowCmd(IShellLinkA * iface, INT iShowCmd
return NOERROR;
}
static HRESULT SHELL_PidlGeticonLocationA(IShellFolder* psf, LPITEMIDLIST pidl, LPSTR pszIconPath, int cchIconPath, int* piIcon)
{
LPCITEMIDLIST pidlLast;
HRESULT hr = SHBindToParent(pidl, &IID_IShellFolder, (LPVOID*)&psf, &pidlLast);
if (SUCCEEDED(hr)) {
IExtractIconA* pei;
hr = IShellFolder_GetUIObjectOf(psf, 0, 1, (LPCITEMIDLIST*)&pidlLast, &IID_IExtractIconA, NULL, (LPVOID*)&pei);
if (SUCCEEDED(hr)) {
hr = IExtractIconA_GetIconLocation(pei, 0, pszIconPath, MAX_PATH, piIcon, NULL);
IExtractIconA_Release(pei);
}
IShellFolder_Release(psf);
}
return hr;
}
static HRESULT WINAPI IShellLinkA_fnGetIconLocation(IShellLinkA * iface, LPSTR pszIconPath,INT cchIconPath,INT *piIcon)
{
ICOM_THIS(IShellLinkImpl, iface);
TRACE("(%p)->(%p len=%u iicon=%p)\n", This, pszIconPath, cchIconPath, piIcon);
if( cchIconPath )
if (cchIconPath)
pszIconPath[0] = 0;
if( This->sIcoPath )
WideCharToMultiByte( CP_ACP, 0, This->sIcoPath, -1,
pszIconPath, cchIconPath, NULL, NULL);
*piIcon = This->iIcoNdx;
return NOERROR;
if (This->sIcoPath) {
WideCharToMultiByte(CP_ACP, 0, This->sIcoPath, -1, pszIconPath, cchIconPath, NULL, NULL);
*piIcon = This->iIcoNdx;
return S_OK;
}
if (This->pPidl || This->sPath) {
IShellFolder* pdsk;
HRESULT hr = SHGetDesktopFolder(&pdsk);
if (SUCCEEDED(hr)) {
/* first look for an icon using the PIDL (if present) */
if (This->pPidl)
hr = SHELL_PidlGeticonLocationA(pdsk, This->pPidl, pszIconPath, cchIconPath, piIcon);
else
hr = E_FAIL;
/* if we couldn't find an icon yet, look for it using the file system path */
if (FAILED(hr) && This->sPath) {
LPITEMIDLIST pidl;
hr = IShellFolder_ParseDisplayName(pdsk, 0, NULL, This->sPath, NULL, &pidl, NULL);
if (SUCCEEDED(hr)) {
hr = SHELL_PidlGeticonLocationA(pdsk, pidl, pszIconPath, cchIconPath, piIcon);
SHFree(pidl);
}
}
IShellFolder_Release(pdsk);
}
return hr;
} else
return E_FAIL;
}
static HRESULT WINAPI IShellLinkA_fnSetIconLocation(IShellLinkA * iface, LPCSTR pszIconPath,INT iIcon)
@ -1519,19 +1574,75 @@ static HRESULT WINAPI IShellLinkW_fnSetShowCmd(IShellLinkW * iface, INT iShowCmd
return S_OK;
}
static HRESULT SHELL_PidlGeticonLocationW(IShellFolder* psf, LPITEMIDLIST pidl, LPWSTR pszIconPath, int cchIconPath, int* piIcon)
{
LPCITEMIDLIST pidlLast;
HRESULT hr = SHBindToParent(pidl, &IID_IShellFolder, (LPVOID*)&psf, &pidlLast);
if (SUCCEEDED(hr)) {
IExtractIconW* pei;
hr = IShellFolder_GetUIObjectOf(psf, 0, 1, (LPCITEMIDLIST*)&pidlLast, &IID_IExtractIconW, NULL, (LPVOID*)&pei);
if (SUCCEEDED(hr)) {
hr = IExtractIconW_GetIconLocation(pei, 0, pszIconPath, MAX_PATH, piIcon, NULL);
IExtractIconW_Release(pei);
}
IShellFolder_Release(psf);
}
return hr;
}
static HRESULT WINAPI IShellLinkW_fnGetIconLocation(IShellLinkW * iface, LPWSTR pszIconPath,INT cchIconPath,INT *piIcon)
{
_ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
TRACE("(%p)->(%p len=%u iicon=%p)\n", This, pszIconPath, cchIconPath, piIcon);
if( cchIconPath )
if (cchIconPath)
pszIconPath[0] = 0;
if( This->sIcoPath )
lstrcpynW( pszIconPath, This->sIcoPath, cchIconPath );
*piIcon = This->iIcoNdx;
return S_OK;
if (This->sIcoPath) {
lstrcpynW(pszIconPath, This->sIcoPath, cchIconPath);
*piIcon = This->iIcoNdx;
return S_OK;
}
if (This->pPidl || This->sPath) {
IShellFolder* pdsk;
HRESULT hr = SHGetDesktopFolder(&pdsk);
if (SUCCEEDED(hr)) {
/* first look for an icon using the PIDL (if present) */
if (This->pPidl)
hr = SHELL_PidlGeticonLocationW(pdsk, This->pPidl, pszIconPath, cchIconPath, piIcon);
else
hr = E_FAIL;
/* if we couldn't find an icon yet, look for it using the file system path */
if (FAILED(hr) && This->sPath) {
LPITEMIDLIST pidl;
hr = IShellFolder_ParseDisplayName(pdsk, 0, NULL, This->sPath, NULL, &pidl, NULL);
if (SUCCEEDED(hr)) {
hr = SHELL_PidlGeticonLocationW(pdsk, pidl, pszIconPath, cchIconPath, piIcon);
SHFree(pidl);
}
}
IShellFolder_Release(pdsk);
}
return hr;
} else
return E_FAIL;
}
static HRESULT WINAPI IShellLinkW_fnSetIconLocation(IShellLinkW * iface, LPCWSTR pszIconPath,INT iIcon)