Display an Icon and Text in a Window

I am new to Windows programming and need some help with a simple task(?!) How do I display a folder, with icon and name in a window?
Last edited on
Obtaining the system icons for files and folders is no simple thing. Is this what you are after? Or will any folder icon do the trick?

If you are looking for a way of obtaining/enumerating the folders, that's easily googled.
I've been doing some googling and assuming I have to use getfileinfo and displayimage for this task. And yes I am looking to display system icons for folders and files. I am reading through Petzold and making progress. Something like this to get the icon?

SHFILEINFO FileInfo = { 0 };
SHGetFileInfo( FilePath,
0,
&FileInfo,
sizeof( FileInfo ),
SHGFI_ICON );
Last edited on
Are you trying to display the contents of the folder, as well as its name and icon?

Nothing to do with the Shell API is "simple"!

Or are you using the File Management API (FindFirstFile, etc.) to enumerate the files, so you only need SHGetFileInfo to get the icon?

Andy
Andy

I am actually using dirent.h as file management and have found loads of stuff on ShGetFileInfo but I am getting confused with all the stuff on DrawIcon, DrawImage etc and there seems to be nothing written recently to help with displaying the icons! It all started like this....I have a Touchsmart TX2 and am interested in writing a touch screen file browser, but using treeview and list view aren't possible due to the layout I want to use. Java is fine but MT4J is a pig to work out, Windows has multitouch support as standard but the API is a dog and the multi touch support for linux is still in development. I have looked into Qt, which has problems with VS2010! I have the basic code to get files/folders from their locations and display them in a console, that is working fine, but to progress I need to graphically represent the files/folders so that I can use mouseover and mouse events and I am drawing a blank. I used to program in C at uni, many moons ago, so the structure of programs isn't an issue. I know what I want to do, but just can't seem to get it working. Oh well, I will keep on trying as learning VS, C++ and the WINAPI at the same time is a very steep learning curve....sigh...

TCP
Finally got it after much faffing. I was trying to load the icon twice duh....

PTSTR filePath = _T("C:\\Test");
SHFILEINFOW sfi = {0};
SHGetFileInfo(filePath, 0, &sfi, sizeof(sfi), SHGFI_ICON|SHGFI_LARGEICON|SHGFI_DISPLAYNAME);
hIcon = sfi.hIcon;
PTSTR name = sfi.szDisplayName;

DrawIconEx (hdc, 10 , 20, hIcon, 48, 48, 0, NULL, DI_NORMAL);
TextOut (hdc , 10, 70, name, lstrlen(name));

thanks for all of your replies

TCP
Last edited on
Cool!

I have a TX2, too! But so far I've only played with the touch screen samples (Microsoft and NTrig).

As I'm still using Vista, I had to install NTrig's DuoSense dll, which behaves very erratically with mouse gestures for me. Are you using Windows 7?

I also have Ubuntu (Lucid) responding to touch, but so far I've only had a go with Xournal. I don't know my way round Qt or GTK+ (?) well enough to work on a Linux touch screen app.

Andy
Topic archived. No new replies allowed.