[VB6] Dynamic Resize: Use a slider to change ListView icon/thumbnail size on the fly
One of the features of the Vista and newer Explorer views is the icon size slider; you can do more than just pick between a couple sizes- you can set it to any value in the icon range. Previously to do this in VB was quite a lot of work; you'd have to manually resize each image and rebuild each ImageList since you can't scale up without quality loss... so it's not something that could be rapidly changed without any lag. This project, however, takes advantage of a feature of the new IImageList2 COM interface: it has a .Resize command that can scale down the entire ImageList at once with the speed of Windows API. To avoid quality loss, we load the maximum size images into a primary ImageList, then we dynamically generate the API-made duplicate in the smaller size that the user is looking for, always scaling down instead of up.
Right now this project is focused on standard image file thumbnails; really small images that need to be grey-boxed and standard file icons will be addressed in a future version of this demo.
Here's the key function:
Code:
Private Sub ResizeThumbView(cxNew As Long)
ImageList_Destroy himl
himl = ImageList_Duplicate(himlMax)
HIMAGELIST_QueryInterface himl, IID_IImageList2, pIML
If (pIML Is Nothing) = False Then
pIML.Resize cxNew, cxNew
End If
himl = ObjPtr(pIML)
bSetIML = True
ListView_SetImageList hLVS, himl, LVSIL_NORMAL
bSetIML = False
ListView1.Refresh
End Sub
While it's certainly possible to forgo the standard HIMAGELIST and entirely use IImageList, I wanted to retain some (hopefully) more familiar territory by using that and the 5.0 VB ListView control. As the API HIMAGELIST_QueryInterface indicates, they're pretty much interchangable anyway, as the ObjPtr returns the same handle as when we made it with ImageList_Create.
Requirements
-Windows Vista or newer
-Common Controls 6.0 Manifest - The demo project has a manifest built into its resource file. Your IDE may have to be manifested to run it from there. If you need to manifest your IDE or a new project, see LaVolpe's Manifest Creator
-oleexp.tlb v4.0 or newer - Only needed in the IDE; not needed once compiled.
-oleexp addon mIID.bas - Included in the oleexp download. Must be added to the demo project the first time you open it.
Scrolling
To make it truly like Explorer, where it sizes while you move the mouse, you can move the code in Slider1_Change over to Slider1_Scroll:
Code:
Private Sub Slider1_Change()
'cxThumb = Slider1.Value
'Label1.Caption = cxThumb & "x" & cxThumb
'ResizeThumbView cxThumb
End Sub
Private Sub Slider1_Scroll()
cxThumb = Slider1.Value
Label1.Caption = cxThumb & "x" & cxThumb
ResizeThumbView cxThumb
End Sub
It works perfectly with the small number of images currently there, but I'm hesitant to trust the stability if there's hundreds or thousands of list items, at least without it being a virtual ListView. I'll take a look at it for future versions; if anyone experiments with it before then let me know!
Last edited by fafalone; Aug 16th, 2017 at 02:51 AM.
Re: [VB6] Dynamic Resize: Use a slider to change ListView icon/thumbnail size on the
High Performance Version
API-Created ListView in Virtual Mode
This version is set to resize while moving the mouse (as discussed above). To hopefully keep the performance good and stable, I've converted the ListView into an API-based one (made with CreateWindowEx) running in virtual mode (LVS_OWNERDATA). The idea is to only have to load/draw images for the items that are displayed, instead of redrawing the entire imagelist like the original version. There's also Unicode support, which isn't possible with the normal VB controls.
This version is actually a good way to learn those approaches too, because unlike the other projects posted by me and others, this one is very simple, just a barebones thumbnail display.
The requirements are identical to the original version.
Use this version if you expect to have more than a few items at a time.
Last edited by fafalone; Aug 16th, 2017 at 04:49 AM.
Re: [VB6] Dynamic Resize: Use a slider to change ListView icon/thumbnail size on the
I want to try use this for a small 25 student school class attendance program, in which pictures of students are supplied (with the students names as names of the picture files). Looks nice. Hopefully its fairly stable. A great many thanks for the virtual mode update.
Re: [VB6] Dynamic Resize: Use a slider to change ListView icon/thumbnail size on the
Two possibilities:
First, your project, and the IDE if you're running from there, need to have a manifest for Common Controls 6.0. See this project for information on how to create one.
Second, Windows XP would result in that error; it's not possible to run this type of project on XP because it doesn't include the IImageList interface.
Re: [VB6] Dynamic Resize: Use a slider to change ListView icon/thumbnail size on the
Originally Posted by fafalone
Two possibilities:
First, your project, and the IDE if you're running from there, need to have a manifest for Common Controls 6.0. See this project for information on how to create one.
Second, Windows XP would result in that error; it's not possible to run this type of project on XP because it doesn't include the IImageList interface.
Created new manifest and imported to project resources still error, System WIndows 7 Attachment 178684
Last edited by Pax345; Sep 12th, 2020 at 02:45 AM.
Re: [VB6] Dynamic Resize: Use a slider to change ListView icon/thumbnail size on the
I gave up, thank you for reply fafalone i didnt expected to get reply in this old thread.
This app doesnt work. If anyone are looking for anything similar go for this :
Re: [VB6] Dynamic Resize: Use a slider to change ListView icon/thumbnail size on the
Does the demo work?
(Also note that adding the resource file in the IDE means it will work when compiled, you need to insert a manifest into VB6.EXE if you want it to work running from the IDE)
Re: [VB6] Dynamic Resize: Use a slider to change ListView icon/thumbnail size on the
Damn you are right it is working when compiled... but not working in IDE, how to insert manifest in vb6.exe???? i have tryed to run vb6 in compatibiliy mode with winxp sp2 and i have put manifest created in manifest creator into vb6.exe folder "VB6.EXE.manifest.res" but still it didnt solved the problem.
Re: [VB6] Dynamic Resize: Use a slider to change ListView icon/thumbnail size on the
Just VB6.EXE.manifest; where that file is just the manifest text, not a resource file.
That may or may not work depending on your system settings.
If it's not working, you have two options:
1) Try changing the registry setting to prefer external manifests:
Set the 'PreferExternalManifest' key to '1' in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\SideBySide, and reboot.
2) Some Windows builds will simply flat out refuse to use external manifests no matter what that key is set to. So if the above is still not working, or you would prefer to just go straight to the sure bet, you need to modify VB6.EXE.
FIRST, make a back up copy of the original EXE. You never want to not have a backup.
Now, get the ResHacker program here. It's free, no ads, nothing funky.
1) Open VB6.EXE in it.
2) Go to the Action menu, and select 'Add using script template'
3) Select MANIFEST from the dropdown, and click Add Resource
4) Replace the text with the manifest you want. I use the following to just add CC6.0 and not mess around with anything else (I'm also on Windows 7):
Re: [VB6] Dynamic Resize: Use a slider to change ListView icon/thumbnail size on the
I apologize; I forgot to include it in the most recent release. I've now updated the attachment to include it, and for convenience I'm attaching the current version here as well.