2 Attachment(s)
[VB6] - Usercontrol PropertySheet Enumeration Enhancement
I was looking at a post on vbAccelerator on using a DLL and TLBs to customize the dropdown listing shown on IDE's property sheet for usercontrol properties. The project showed how a typical dropdown might look like the following and can be modified at will
Code:
Default Behavior Modified Behavior
0 - vbLeftJustified 0 - Left Aligned
1 - vbRightJustified 1 - Right Aligned
2 - vbCenter 2 - Centered
I really liked the idea and thought about a different way of accomplishing the same thing without any ActiveX DLL or TLBs. The attached is my version of vbAccelerator's project.
Note that the methods used allow on-demand, dynamic, "enumerations" that can even be strings vs numerical enumerations. These enumerations are not true enumerations but rather an array of strings that act like enumerations within the property sheet, providing a dropdown list to select from.
For example. Let's say your user control needs to show a listing of available textboxes on the form. In the past, we would have to offer a property page that basically added all the textbox names to a listbox so the user can select one from it. Now, we can provide that list in a dropdown box that will be displayed on the property sheet and no need for a property page just for that purpose.
Anyway, I thought vbAccelerator project was interesting enough to try and replicate it a diffferent way. This is the different way.
Warning. Pretty advanced stuff for such little gain, IMO, but it does present a more "professional" and personal touch to how enumerations are offered to users in design time.
Attachment 67919
1 Attachment(s)
Re: [VB6] - Usercontrol PropertySheet Enumeration Enhancement
Updated. The zip in the first post contains the updates.
Added capability of displaying dialog boxes or modal forms vs a property page.
Example, let's say you wanted the ability to select a file from the property sheet just like the richt text control does. Now you can. Your property will get an ellipse button and then the usercontrol will be notified to display the appropriate dialog box.
Attachment 67992
Re: [VB6] - Usercontrol PropertySheet Enumeration Enhancement
18 Dec 08. Bug/Patch Report. Zip in 1st post, contains all updates.
Fixed major thread safety errors and tested uncompiled controls intermixed with compiled ocx's using the same subclassing technique. Now, no problems.
Lessons learned from this bug search:
1) VB's class function table (vTable) is aligned differently when class is uncompiled (32 bytes btwn entries) vs compiled (13 bytes). Thunk fixed to account for this by using a variable offset vs hardcoded offset
2) Use of mapped memory file was a good idea, but failed to remember that it is cross-process capable. Therefore, data stored in it was available to any process running the compiled/uncompiled controls. Fix was simply to ensure mapped files are thread specific.
So far, works like a champ. Please let me know if you encounter any errors.
1 Attachment(s)
Re: [VB6] - Usercontrol PropertySheet Enumeration Enhancement
Attachment 171481
hello .... Is it possible to create a property page and display it as shown?
Re: [VB6] - Usercontrol PropertySheet Enumeration Enhancement
With lots of subclassing -- yes. ;)
Good luck with that. It becomes even more difficult because you have to undo/prevent VB doing what it wants to do (display a combbox listing), then make it behave the way you want without breaking VB. That is rarely an easy task.
Re: [VB6] - Usercontrol PropertySheet Enumeration Enhancement
Keith - brilliant as always.
The Filename property doesn't seem to stick
i. e. Selected a filename and the property still
indicates (No Filename Selected) plus
Debug.Print ucEnum1.FileName => Empty string