Parsing icon for applications issue

こ雲淡風輕ζ 提交于 2019-12-24 06:59:06

问题


I want to get applications icon from the registry. The problem is that I'm getting only default application icon. How to get the actual application icon? Thanks.

Screenshot:

Code:

QStringList allLocalMachineX86Keys;
QString displayIcon;
QString iconFile;
QIcon programIcon;
QStringList displayIconSplitted;
QString iconSplittedData;
QFileIconProvider fileIconProvider;
QString displayName;

QSettings registryKeyLocalMachineX86("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall", QSettings::NativeFormat);
allLocalMachineX86Keys = registryKeyLocalMachineX86.allKeys();

for (QString key : allLocalMachineX86Keys) {
    if (!key.isEmpty()) {
        if (key.contains("DisplayIcon")) {
            displayIcon = registryKeyLocalMachineX86.value(key).toString();

            if (displayIcon.contains("\"")) {
                displayIconSplitted = displayIcon.split("\"");
                iconSplittedData = displayIconSplitted.value(displayIconSplitted.length() - 2);
                iconFile = iconSplittedData;
            } else if (displayIcon.contains(",")) {
                displayIconSplitted = displayIcon.split(",");
                iconSplittedData = displayIconSplitted.value(displayIconSplitted.length() - 2);
                iconFile = iconSplittedData;
            } else {
                iconFile = displayIcon;
            }

            if (iconFile.contains(".ico")) {
                programIcon = QIcon(iconFile);
            } else {
                QFileInfo fileInfo(iconFile);
                programIcon = fileIconProvider.icon(fileInfo);
            }
        } else {
            programIcon = QtWin::fromHICON(LoadIcon(NULL, IDI_APPLICATION));
        }

        if (key.contains("DisplayName") && registryKeyLocalMachineX86.value(key).toString() != "") {
            displayName = registryKeyLocalMachineX86.value(key).toString();
            emit appData(programIcon, displayName);
        }
    }
}

Update: When I have commented these lines of code:

// } else {
//     programIcon = QtWin::fromHICON(LoadIcon(NULL, IDI_APPLICATION));
// }

the apps icon displays but some are empty or not from the application (image below):

Anyone know how to fix it? Thanks in advance.

来源:https://stackoverflow.com/questions/44250058/parsing-icon-for-applications-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!