Exemplo n.º 1
0
// @pymethod |PyIExtractIconW|GetIconLocation|Description of GetIconLocation.
PyObject *PyIExtractIconW::GetIconLocation(PyObject *self, PyObject *args)
{
	IExtractIconW *pIEI = GetI(self);
	if ( pIEI == NULL )
		return NULL;
	// @pyparm int|uFlags||Description for uFlags
	// @pyparm int|cchMax|MAX_PATH+MAX_FNAME|Buffer size to allocate for file name
	UINT uFlags;
	INT cchMax = MAX_PATH + _MAX_FNAME;
	if ( !PyArg_ParseTuple(args, "i|i:GetIconLocation", &uFlags, &cchMax))
		return NULL;
	WCHAR *buf = (WCHAR *)malloc(cchMax * sizeof(WCHAR));
	if (!buf)
		return PyErr_NoMemory();
	INT iIndex;
	UINT flags;
	HRESULT hr;
	PY_INTERFACE_PRECALL;
	hr = pIEI->GetIconLocation( uFlags, buf, cchMax, &iIndex, &flags);
	PY_INTERFACE_POSTCALL;
	if ( FAILED(hr) ) {
		free(buf);
		return PyCom_BuildPyException(hr, pIEI, IID_IExtractIconW );
	}
	PyObject *retStr = PyWinObject_FromWCHAR(buf);
	free(buf);
	return Py_BuildValue("iNii", hr, retStr, iIndex, flags);
}
Exemplo n.º 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;
    }

    HICON hIcon = NULL;

    HRESULT hres;
    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();
    }
    return (jlong)hIcon;
}