How to display system icon for a file in SWT?

后端 未结 4 1528
谎友^
谎友^ 2021-01-02 04:40

I want to display a file tree similarly to java2s.com \'Create a lazy file tree\', but include the actual system icons - especially for folders. SWT does not seem to offer t

4条回答
  •  旧巷少年郎
    2021-01-02 05:16

    share you the code,it works ok for me.

        /** extract the exe file's icon */
    public static Image getImage4exe(String path) {
        /* Use the character encoding for the default locale */
        TCHAR lpszFile = new TCHAR(0, path, true);
        long[] phiconSmall = new long[1];
        OS.ExtractIconEx(lpszFile, 0, null, phiconSmall, 1);
        if (phiconSmall[0] == 0) {
            return null;
        }
        Image ret = Image.win32_new(null, SWT.ICON, phiconSmall[0]);
        return ret;
    }
    

提交回复
热议问题