// @pymethod |PyIExtractIcon|Extract|Description of Extract.
PyObject *PyIExtractIcon::Extract(PyObject *self, PyObject *args)
{
	IExtractIconA *pIEI = GetI(self);
	if ( pIEI == NULL )
		return NULL;
	// @pyparm <o unicode>|pszFile||Description for pszFile
	// @pyparm int|nIconIndex||Description for nIconIndex
	// @pyparm int|nIconSize||Description for nIconIndex
	HICON hiconLarge;
	HICON hiconSmall;
	PyObject *obpszFile;
	char *pszFile;
	UINT nIconIndex;
	UINT nIconSize;
	if ( !PyArg_ParseTuple(args, "Oii:Extract", &obpszFile, &nIconIndex, &nIconSize) )
		return NULL;
	BOOL bPythonIsHappy = TRUE;
	if (!PyWinObject_AsString(obpszFile, &pszFile)) bPythonIsHappy = FALSE;
	if (!bPythonIsHappy) return NULL;
	HRESULT hr;
	PY_INTERFACE_PRECALL;
	hr = pIEI->Extract( pszFile, nIconIndex, &hiconLarge, &hiconSmall, nIconSize );
	PyWinObject_FreeString(pszFile);
	PY_INTERFACE_POSTCALL;
	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr, pIEI, IID_IExtractIcon );
	if (hr==S_FALSE)
		return Py_BuildValue("OO", Py_None, Py_None);
	return Py_BuildValue("NN", PyWinLong_FromHANDLE(hiconLarge),
			           PyWinLong_FromHANDLE(hiconSmall));
	// @rdesc The result is (hicon_large, hicon_small), or
	// (None,None) if the underlying function returns S_FALSE, indicating
	// the calling application should extract it.
}
示例#2
0
/*
 * Class:     sun_awt_shell_Win32ShellFolder2
 * Method:    extractIcon
 * Signature: (JJZ)J
 */
JNIEXPORT jlong JNICALL Java_sun_awt_shell_Win32ShellFolder2_extractIcon
    (JNIEnv* env, jclass cls, jlong pIShellFolderL, jlong relativePIDL, jboolean getLargeIcon)
{
    IShellFolder* pIShellFolder = (IShellFolder*)pIShellFolderL;
    LPITEMIDLIST pidl = (LPITEMIDLIST)relativePIDL;
    if (pIShellFolder == NULL || pidl == NULL) {
        return 0;
    }

    ::CoInitialize(NULL);

    HRESULT hres;
    HICON hIcon = NULL;
    if (IS_NT) {
        IExtractIconW* pIcon;
        hres = pIShellFolder->GetUIObjectOf(NULL, 1, const_cast<LPCITEMIDLIST*>(&pidl),
					IID_IExtractIconW, NULL, (void**)&pIcon);
        if (SUCCEEDED(hres)) {
	    WCHAR szBuf[MAX_PATH];
	    INT index;
	    UINT flags;
	    hres = pIcon->GetIconLocation(GIL_FORSHELL, szBuf, MAX_PATH, &index, &flags);
	    if (SUCCEEDED(hres)) {
	        HICON hIconLarge;
	        hres = pIcon->Extract(szBuf, index, &hIconLarge, &hIcon, (16 << 16) + 32);
	        if (SUCCEEDED(hres)) {
		    if (getLargeIcon) {
                        fn_DestroyIcon((HICON)hIcon);
                        hIcon = hIconLarge;
                    } else {
                        fn_DestroyIcon((HICON)hIconLarge);
		    }
	        }
	    }
	    pIcon->Release();
        }
    } else {
        IExtractIconA* pIcon;
        hres = pIShellFolder->GetUIObjectOf(NULL, 1, const_cast<LPCITEMIDLIST*>(&pidl),
					IID_IExtractIconA, NULL, (void**)&pIcon);
        if (SUCCEEDED(hres)) {
	    CHAR szBuf[MAX_PATH];
	    INT index;
	    UINT flags;
	    hres = pIcon->GetIconLocation(GIL_FORSHELL, szBuf, MAX_PATH, &index, &flags);
	    if (SUCCEEDED(hres)) {
	        HICON hIconLarge;
	        hres = pIcon->Extract(szBuf, index, &hIconLarge, &hIcon, (16 << 16) + 32);
	        if (SUCCEEDED(hres)) {
		    if (getLargeIcon) {
                        fn_DestroyIcon((HICON)hIcon);
                        hIcon = hIconLarge;
                    } else {
                        fn_DestroyIcon((HICON)hIconLarge);
		    }
	        }
	    }
	    pIcon->Release();
        }
    }
    ::CoUninitialize();
    return (jlong)hIcon;
}