< prev index next >

src/java.desktop/windows/native/libawt/windows/ShellFolder2.cpp

Print this page


   1 /*
   2  * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 903 
 904     INT index = -1;
 905 
 906     HRESULT hres;
 907     // http://msdn.microsoft.com/library/en-us/shellcc/platform/Shell/programmersguide/shell_int/shell_int_programming/std_ifaces.asp
 908     if (pIShellIcon != NULL) {
 909         hres = pIShellIcon->GetIconOf(pidl, GIL_FORSHELL, &index);
 910     }
 911 
 912     return (jint)index;
 913 }
 914 
 915 
 916 /*
 917  * Class:     sun_awt_shell_Win32ShellFolder2
 918  * Method:    extractIcon
 919  * Signature: (JJZZ)J
 920  */
 921 JNIEXPORT jlong JNICALL Java_sun_awt_shell_Win32ShellFolder2_extractIcon
 922     (JNIEnv* env, jclass cls, jlong pIShellFolderL, jlong relativePIDL,
 923                                 jboolean getLargeIcon, jboolean getDefaultIcon)
 924 {
 925     IShellFolder* pIShellFolder = (IShellFolder*)pIShellFolderL;
 926     LPITEMIDLIST pidl = (LPITEMIDLIST)relativePIDL;
 927     if (pIShellFolder == NULL || pidl == NULL) {
 928         return 0;
 929     }
 930 
 931     HICON hIcon = NULL;
 932 
 933     HRESULT hres;
 934     IExtractIconW* pIcon;
 935     hres = pIShellFolder->GetUIObjectOf(NULL, 1, const_cast<LPCITEMIDLIST*>(&pidl),
 936                                         IID_IExtractIconW, NULL, (void**)&pIcon);
 937     if (SUCCEEDED(hres)) {
 938         WCHAR szBuf[MAX_PATH];
 939         INT index;
 940         UINT flags;
 941         UINT uFlags = getDefaultIcon ? GIL_DEFAULTICON : GIL_FORSHELL | GIL_ASYNC;
 942         hres = pIcon->GetIconLocation(uFlags, szBuf, MAX_PATH, &index, &flags);
 943         if (SUCCEEDED(hres)) {
 944             HICON hIconLarge;
 945             hres = pIcon->Extract(szBuf, index, &hIconLarge, &hIcon, (16 << 16) + 32);
 946             if (SUCCEEDED(hres)) {
 947                 if (getLargeIcon) {
 948                     fn_DestroyIcon((HICON)hIcon);
 949                     hIcon = hIconLarge;
 950                 } else {
 951                     fn_DestroyIcon((HICON)hIconLarge);
 952                 }
 953             }
 954         } else if (hres == E_PENDING) {
 955             pIcon->Release();
 956             return E_PENDING;
 957         }
 958         pIcon->Release();
 959     }
 960     return (jlong)hIcon;
 961 }
 962 
 963 
 964 /*
 965  * Class:     sun_awt_shell_Win32ShellFolder2
 966  * Method:    disposeIcon
 967  * Signature: (J)V
 968  */
 969 JNIEXPORT void JNICALL Java_sun_awt_shell_Win32ShellFolder2_disposeIcon
 970     (JNIEnv* env, jclass cls, jlong hicon)
 971 {
 972     fn_DestroyIcon((HICON)hicon);
 973 }


   1 /*
   2  * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 903 
 904     INT index = -1;
 905 
 906     HRESULT hres;
 907     // http://msdn.microsoft.com/library/en-us/shellcc/platform/Shell/programmersguide/shell_int/shell_int_programming/std_ifaces.asp
 908     if (pIShellIcon != NULL) {
 909         hres = pIShellIcon->GetIconOf(pidl, GIL_FORSHELL, &index);
 910     }
 911 
 912     return (jint)index;
 913 }
 914 
 915 
 916 /*
 917  * Class:     sun_awt_shell_Win32ShellFolder2
 918  * Method:    extractIcon
 919  * Signature: (JJZZ)J
 920  */
 921 JNIEXPORT jlong JNICALL Java_sun_awt_shell_Win32ShellFolder2_extractIcon
 922     (JNIEnv* env, jclass cls, jlong pIShellFolderL, jlong relativePIDL,
 923                                 jint size, jboolean getDefaultIcon)
 924 {
 925     IShellFolder* pIShellFolder = (IShellFolder*)pIShellFolderL;
 926     LPITEMIDLIST pidl = (LPITEMIDLIST)relativePIDL;
 927     if (pIShellFolder == NULL || pidl == NULL) {
 928         return 0;
 929     }
 930 
 931     HICON hIcon = NULL;
 932 
 933     HRESULT hres;
 934     IExtractIconW* pIcon;
 935     hres = pIShellFolder->GetUIObjectOf(NULL, 1, const_cast<LPCITEMIDLIST*>(&pidl),
 936                                         IID_IExtractIconW, NULL, (void**)&pIcon);
 937     if (SUCCEEDED(hres)) {
 938         WCHAR szBuf[MAX_PATH];
 939         INT index;
 940         UINT flags;
 941         UINT uFlags = getDefaultIcon ? GIL_DEFAULTICON : GIL_FORSHELL | GIL_ASYNC;
 942         hres = pIcon->GetIconLocation(uFlags, szBuf, MAX_PATH, &index, &flags);
 943         if (SUCCEEDED(hres)) {
 944             hres = pIcon->Extract(szBuf, index, &hIcon, NULL, size);









 945         } else if (hres == E_PENDING) {
 946             pIcon->Release();
 947             return E_PENDING;
 948         }
 949         pIcon->Release();
 950     }
 951     return (jlong)hIcon;
 952 }
 953 
 954 
 955 /*
 956  * Class:     sun_awt_shell_Win32ShellFolder2
 957  * Method:    disposeIcon
 958  * Signature: (J)V
 959  */
 960 JNIEXPORT void JNICALL Java_sun_awt_shell_Win32ShellFolder2_disposeIcon
 961     (JNIEnv* env, jclass cls, jlong hicon)
 962 {
 963     fn_DestroyIcon((HICON)hicon);
 964 }


< prev index next >