zoukankan      html  css  js  c++  java
  • c++ 获取文件图标,类型名称,属性 SHGetFileInfo

    SHGetFileInfo是一个相当实用的Windows API函数。

    // 【MoreWindows工作笔记4】 获取文件图标,类型名称,属性 SHGetFileInfo
    #include <Windows.h>
    #include <iostream>
    using namespace std;
    int main()
    {
      printf("   【MoreWindows工作笔记4】 获取文件图标,类型名称,属性 SHGetFileInfo
    ");    
      printf(" - http://blog.csdn.net/morewindows/article/details/16358681 -
    ");    
      printf(" -- By MoreWindows( http://blog.csdn.net/MoreWindows ) --
    
    ");  
     
      CoInitialize(NULL);
      char file_name[] = "C:\MoreWindows.mp3";
      SHFILEINFO sfi = {0};
      
      cout<<"file name = "<<file_name<<endl;
     
      // type name
      SHGetFileInfo(file_name, 0, &sfi, sizeof(sfi), SHGFI_USEFILEATTRIBUTES | SHGFI_TYPENAME);
      cout<<"type name = "<<sfi.szTypeName<<endl;
     
      // display name
      SHGetFileInfo(file_name, 0, &sfi, sizeof(sfi), SHGFI_USEFILEATTRIBUTES | SHGFI_DISPLAYNAME);
      cout<<"display name = "<<sfi.szDisplayName<<endl;
     
      // attribute
      SHGetFileInfo(file_name, 0, &sfi, sizeof(sfi), SHGFI_USEFILEATTRIBUTES | SHGFI_ATTRIBUTES);
      cout<<"attribute = "<<hex<<sfi.dwAttributes<<endl;  // 使用IShellFolder::GetAttributesOf函数解析
      
      // HICON
      // 除了SHGFI_ICON之外还有SHGFI_LARGEICON(大图标), SHGFI_SMALLICON(小图标)
      SHGetFileInfo(file_name, 0, &sfi, sizeof(sfi), SHGFI_USEFILEATTRIBUTES | SHGFI_ICON);
      cout<<"HICON = 0x"<<hex<<sfi.hIcon<<endl;  // 使用IShellFolder::GetAttributesOf函数解析
      DestroyIcon(sfi.hIcon);
     
      // HICON system index
      SHGetFileInfo(file_name, 0, &sfi, sizeof(sfi), SHGFI_USEFILEATTRIBUTES | SHGFI_SYSICONINDEX);
      cout<<"HICON system index = "<<sfi.iIcon<<endl;  // 使用IShellFolder::GetAttributesOf函数解析
     
      CoUninitialize();
     
      // SHGFI_USEFILEATTRIBUTES 的说明
      // Indicates that the function should not attempt to access the file specified by pszPath. 
      // Rather, it should act as if the file specified by pszPath exists with the file attributes passed in dwFileAttributes.
      // This flag cannot be combined with the SHGFI_ATTRIBUTES, SHGFI_EXETYPE, or SHGFI_PIDL flags.
      return 0;
    }
  • 相关阅读:
    【TS】535- 7个超好用的 TypeScript 新功能
    【学习】一起加入重学 TypeScript 学习小组
    17.5W秒级交易峰值下的混合云弹性架构之路
    微服务架构:spring cloud之服务注册和服务发现
    消息队列服务RabbitMQ 和Kafka对比
    微服务架构:spring cloud简介
    2016 年度码云热门项目排行榜 TOP 10
    Netflix Conductor : 一个微服务的编排器
    Java 9的这一基本功能,你可能从未听过
    使用 Docker 搭建 Java Web 运行环境
  • 原文地址:https://www.cnblogs.com/blogpro/p/11339876.html
Copyright © 2011-2022 走看看