1. Using Win32Lib's geFileInfo to show system icon
- Posted by Jonas Temple <jtemple at yhti.net> Jan 25, 2006
- 473 views
All, I'm trying to use Win32Lib's getFileInfo() function to display the small icon for a given file. The trick here is the file is not on the PC. According to MSDN, if I use SHGFI_USEFILEATTRIBUTES with FILE_ATTRIBUTE_NORMAL then this should give me the icon index even if the file doesn't exist. Here's a code snippet:
file_info = getFileInfo(trim(dir_data[i][2]), FILE_ATTRIBUTE_NORMAL, or_all({SHGFI_USEFILEATTRIBUTES, SHGFI_SYSICONINDEX, SHGFI_SMALLICON}))
Then this should return the handle/index of the small icon. Once I have that, how do I use addTVItem() to display this icon? I can't seem to put these together in my mind and was hoping someone has already done this. Thanks! Jonas Temple http://www.yhti.net/~jktemple
2. Re: Using Win32Lib's geFileInfo to show system icon
- Posted by Jonas Temple <jtemple at yhti.net> Jan 25, 2006
- 464 views
I think I may have answered my own question. What I realized is that Win32Lib maintains it's own image list and any icons used for tree/list views must be in that list. SO...I added the handle to the small icon returned from getFileInfo to the image list and it worked! Here's the code:
file_info = getFileInfo(trim(dir_data[i][2]), FILE_ATTRIBUTE_NORMAL, or_all({SHGFI_USEFILEATTRIBUTES, SHGFI_ICON, SHGFI_SMALLICON})) il_index = addIcon(file_info[4]) void = addTVItem(MainTV, il_index, il_index, trim(dir_data[i][2]), index)
What I don't know is if identical icons are added to the list if they already exist. Could this potentially become a resource problem/leak? Jonas Temple http://www.yhti.net/~jktemple
3. Re: Using Win32Lib's geFileInfo to show system icon
- Posted by Larry Miller <larrymiller at sasktel.net> Jan 25, 2006
- 466 views
- Last edited Jan 26, 2006
Using the code you are using could cause problems, particularly if the code is called many times and with Win98. But there is an alternative you might consider. Win32Lib does maintain it's own imagelist but you do not have to use it. You may be able to use the system imagelist whose handle can be obtained with the following code: file_info=getFileInfo("*.txt",#80, or_all({SHGFI_SYSICONINDEX+SHGFI_USEFILEATTRIBUTES+SHGFI_SMALLICON}) file_info[7] will contain the handle to the system imagelist. You can then do: void=sendMessage(MainTV,TVM_SETIMAGELIST,TVSIL_NORMAL,file_info[7]) to use this image list in the Treeview control. Use the icon index returned by getFileInfo() directly in addTVItem() But there are a number of things to remember when doing this. The system imagelist is owned and managed by the system and should never be destroyed or directly modified by the application. Doing this on Win98 will corrupt a vital system resource and require a reboot. getFileinfo() will add any required images. On NT platforms you will be working with a private copy of the real system imagelist and no problems should result. But any direct modification of this list is unsupported and discouraged by Microsoft. This means that you can use only images in the system imagelist, you can not add your own. If this is acceptable to your application then this would be a viable alternative. There should be no concerns over resource usage and performance will be much better. Adding an icon to an imagelist can be a time consuming operation. I learned this from a lot of browsing MSDN & elsewhere and trial and error - mostly error. Larry Miller
4. Re: Using Win32Lib's geFileInfo to show system icon
- Posted by Jonas Temple <jtemple at yhti.net> Jan 25, 2006
- 472 views
- Last edited Jan 26, 2006
Larry Miller wrote: > > Using the code you are using could cause problems, particularly if the code > is called many times and with Win98. That's what I was afraid of... > > But there is an alternative you might consider. Win32Lib does maintain it's > own imagelist but you do not have to use it. You may be able to use the system > imagelist whose handle can be obtained with the following code: > > file_info=getFileInfo("*.txt",#80, > or_all({SHGFI_SYSICONINDEX+SHGFI_USEFILEATTRIBUTES+SHGFI_SMALLICON}) > > file_info[7] will contain the handle to the system imagelist. > > You can then do: > > void=sendMessage(MainTV,TVM_SETIMAGELIST,TVSIL_NORMAL,file_info[7]) > > to use this image list in the Treeview control. > But what if I have other images not in the system image list that I want to use? Will using the TVM_SETIMAGELIST replace Win32Lib's image list that I'm using for other non-system images? Jonas Temple http://www.yhti.net/~jktemple
5. Re: Using Win32Lib's geFileInfo to show system icon
- Posted by Larry Miller <larrymiller at sasktel.net> Jan 25, 2006
- 468 views
- Last edited Jan 26, 2006
Yes, setting a Treeview control to use the system imagelist will will not allow the use of Win32Lib's imagelist for the treeview. For normal images a Treeview can use only one imagelist at one time. When Win32Lib adds an image to it's imagelist it checks for duplicate handles but this may not help you much. I don't know how getFileInfo manages the image handles that it creates and it probably varies on different systems. These image handles are owned by the application and the system has no idea how they may be used. If a new image is created for the same file or folder then Win32Lib will add it to the list. If the Treeview were created and the populated only once there should be no problem. But if the same directories are repeatedly accessed and updated in the treeview there will likely be problems over time, particularly with Win98. If I knew more of what you were trying to accomplish I may be able to help more. Larry Miller
6. Re: Using Win32Lib's geFileInfo to show system icon
- Posted by Jonas Temple <jtemple at yhti.net> Jan 25, 2006
- 468 views
- Last edited Jan 26, 2006
Larry Miller wrote: > > Yes, setting a Treeview control to use the system imagelist will will not > allow > the use of Win32Lib's imagelist for the treeview. For normal images a Treeview > can use only one imagelist at one time. Bummer > If the Treeview were created and the populated only once there should be no > problem. But if the same directories are repeatedly accessed and updated in > the treeview there will likely be problems over time, particularly with Win98. > If I knew more of what you were trying to accomplish I may be able to help > more. What I'm doing is presenting a Unix-like file system through a Windows interface. The user can open the file on the system on the local PC and I want to show the usual Windows icon so the user knows what will open the file. It's working now but I guess I need to figure out how to use both my custom icons and icons from the system. Here's a screen shot of the window: http://66.140.221.68/TreeView1.jpg Jonas Temple http://www.yhti.net/~jktemple
7. Re: Using Win32Lib's geFileInfo to show system icon
- Posted by Greg Haberek <ghaberek at gmail.com> Jan 25, 2006
- 476 views
- Last edited Jan 26, 2006
> It's working now but I guess I need to figure out how to use both my cust= om icons and icons from the system. Here's a screen shot of the window: Um... why not use a function that returns the handle to an icon, not its image list index? Have you looked at ExtractAssociatedIcon? There's a Win32Lib demo called icon00.exw. Here's a wrapper for the function.
global constant xExtractAssociatedIcon = registerw32Function( shell32, "ExtractAssociatedIconA", {C_INT,C_POINTER,C_POINTER}, C_INT ) global function extractAssociatedIcon( sequence pFilename ) atom mset, hInst, lpIconPath, lpiIcon, hIcon mset = w32new_memset() hInst = instance() lpIconPath = w32acquire_mem( mset, pFilename ) lpiIcon = w32acquire_mem( mset, Word ) hIcon = w32Func( xExtractAssociatedIcon, {hInst, lpIconPath, lpiIcon}= ) w32release_mem( mset ) return hIcon end function
8. Re: Using Win32Lib's geFileInfo to show system icon
- Posted by Jonas Temple <jtemple at yhti.net> Jan 26, 2006
- 480 views
Greg Haberek wrote: > > Um... why not use a function that returns the handle to an icon, not > its image list index? Have you looked at ExtractAssociatedIcon? > There's a Win32Lib demo called icon00.exw. Here's a wrapper for the > function. > Greg, Good idea and I did look at that function but the problem is the file doesn't actually exist on the PC, I just want to show the default icon in case the user opens the file to the PC. Unless I don't understand how ExtractIcon works. Jonas Temple http://www.yhti.net/~jktemple
9. Re: Using Win32Lib's geFileInfo to show system icon
- Posted by Greg Haberek <ghaberek at gmail.com> Jan 26, 2006
- 474 views
> What I don't know is if identical icons are added to the list if they alr= eady exist. Could this potentially become a resource problem/leak? Duplicate icons are not added to the list. And icon memory leaks exist only on Windows 9x. I believe you're operating in a Windows 2k/XP environment.