File Type Detection / Zhao Xiangning This article example remember that I have written previous articles about how to draw icons from a executable program. This article will discuss how to get the file icon associated with a specific file type? This problem relies on whether you want to get an icon for a specified file or just want to get an icon for a normal file. If you have a specific file, such as c: /myfile/somefile.zzp. Then you can call the extractassociatedIndon function to get the icon associated with a specific file. But this function is only available for actual files (or access to somewhere) on the disk. If you want to find an icon associated with a general file type, you must read the registry. For example, in order to find the icon used by the .cpp file, you have to look at the hkey_classes_root / .cpp in the registry, on my machine, the value of its first line is "cppfile", then continue to see the defaulticon of HKEY_CLASSES_ROOT / CPPFILE Key value, on my machine: hkey_classes_root / cppfile / defaulticon = "c: /prograu / 1/Micros ~ 4/common/msdev98/bin/msdev.exe ,-20209" So .cpp file icon in C: /Progra ~ 1/Micros ~ 4/common/msdev98/bin/msdev.exe file icon resource ID number is 20209. Under normal circumstances, HKCR / .foo has an inlet value similar to the Foofile and specifies an icon for the CPP file in HKCR / Foofile / Defaulticon. However, sometimes .foo's entry value is not foofile, but it is like "Superapp.Document.5", which means the fifth version of the Superapp document, there is no default, in HKEY_CLASSES_ROOT / SuPERAPP.Document.5, But there is a key value CLSID = {long and ugly hex hexadecimal guid}, this tells you. Foo is a COM object, and its class ID value is the long and ugly hexadecimal GUID. To get the associated icon, you must go to / clsid / {long and ugly hex GUID} / defaulticon lookup. Cry! too painful. But it's not finished! Because foofile may have a customized icon processor implemented in a hous-extended form. To do this, you have to check, load this icon processor, call ishellicon or iptracticon and continue to cry, this is really absurd! Fortunately, there is a better way to avoid a disgusting registry, that is, using the SHGETFILEINFO function, call this function to get information about the file. It has a smart option, SHGFI_USEFileAttribute, this option allows you to pass a fake file name, such as Mumble.txt. Even if the file does not exist, SHGETFILEINFO can also get the information you want. SHFILEINFO SHFI; MEMSET (& SHFI, 0, SIZEOF (SHFI)); SHGETFILEINFO ("foo.bmp", file_attribute_normal, & shfi, sizeof (shfi), shgfi_icon | SHGFI_USEFILEATTRIBUTES; in order to display its method, I wrote a small application Program, FileType (see Figure 1), there is an edit box in the chart, in which any file can be entered, such as TXT, JPG, BMP, etc. to look at the icon associated with the corresponding file.