Quantcast
Viewing all articles
Browse latest Browse all 1448

[VB6] DPI Assistant Drop-In UserControl

The attached sample projects include the DPI Assistant tool. This tool is designed to help the coder prepare their projects for system DPI awareness. This tool is not designed for dynamic DPI awareness, i.e., per-monitor awareness... That's another project to create.

The tool is designed to be a drop-in, simply add it to an existing project as an uncompiled usercontrol. Do not compile the tool outside of your projects. It has features to detect IDE design and compiled host. When compiled and when in run-time, not compiled, the tool will turn some features off. The tool is strictly designed for the IDE and image scaling during runtime. It can be removed permanently after satisfied you are DPI-aware enough, as long as you are not using any of its image or control scaling options.

What does it do? It has several properties to alert you when DPI-awareness issues exist in your project. It contains several image-related functions to make it easier to scale images due to DPI changes. It can scale nearly all of your controls and allow you to override the scaling. It does not automatically scale images, but will provide the suggested new dimensions relative to current DPI. Scaling an image can be as simple as a single call to one of the tool's scaling functions.

This tool does NOT make your project DPI aware, it assists only. You still should provide multiple sizes of your icons and/or bitmaps/PNGs, etc. The scaling features use GDI+ to perform high quality scaling, but there is only so much quality that can be expected when scaling something 2 -3 times its size; hence, having multiple sizes in your resource file is a good strategy.

Along with the image scaling functions, there is also a function that will allow you to load PNG and TIFF images. However, transparency is still an issue since VB doesn't like to support that outside of icons and GIFs. But faking transparency by having the tool load the PNG over a solid background color works really nice if the image does not need to be shown over a dynamic background. There are options that will create pre-multiplied RGB bitmaps that can be used in menus on Vista and newer, load alphablended icons drawn over solid backgrounds that can be added to an ImageList for display in a TreeView or ListView control. And a few more image options.

But for any of this to help, you must declare your project DPI aware. This requires a simple manifest added to a resource file. The manifest simply tells Windows not to stretch your application when DPI changes, that your application can scale itself without much help from Windows. This is explained in more detail in post #2.

Here are some of the things that the tool will assist you with. Following are explained in more detail in posting #3.
- Image scaling
- Identifying non-TrueType fonts and alerting you so you can fix that
- Identifying known problems with VB controls that can occur when DPI changes
- Auto-scaling controls, as needed, and allowing you to prevent it (per control)
- Counter-scaling your controls when VB's DPI is different than the system

The screenshots below have been resized for upload here. In post #2 (maxed out my number of attachments on this posting) is a zip with full images, unscaled, of how atypical DPI, like at 175% DPI (as were these), can hose up your DPI-aware application if you are not prepared for it. The images below are, from top to bottom, an example of app not DPI aware, app DPI aware but failed to address VB-related problems, and a DPI aware app after addressing those problems

Image may be NSFW.
Clik here to view.
Name:  DPIunaware.jpg
Views: 72
Size:  53.9 KB

Image may be NSFW.
Clik here to view.
Name:  DPIawareNoAssist.jpg
Views: 61
Size:  64.6 KB

Image may be NSFW.
Clik here to view.
Name:  DPIawareAssist.jpg
Views: 59
Size:  56.6 KB


The attachments below each have the DPI Assistant tool. Just copy the .ctl & .ctx file to wherever you may want it. A good place could be your VB folder where templates are stored. That way it will show up in the list of usercontrols when you opt to add a "new" usercontrol to your project, i.e., ...VB98\Template\Userctls

I do expect changes to this code as more & more people play with it and report bugs and request enhancements. Recommend compiling each sample project and seeing how they differ in other DPIs. Always test your apps in 175% DPI. If VB breaks, it'll break there.
Attached Images
Image may be NSFW.
Clik here to view.
 Image may be NSFW.
Clik here to view.
 Image may be NSFW.
Clik here to view.
 
Attached Files

Viewing all articles
Browse latest Browse all 1448

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>