What's New
Q & A
Tip Jar
Tips & Tricks
These are brief tips and tricks that can make Visual Basic programming easier.
New Control Usage Numerical Stuff
Starting & Stopping I/O Bug Alerts
Software Engineering Printing System Issues
Graphics Coding Techniques Other Programs
Databases Misc Forms


Display Bitmaps in Windows Explorer
By Ramprasad K Epram Technologies, India

For the Thumbnail view of your Bitmap, open the following key in the registry

Change the value to '%1' and restart your computer.
Convert WMF Files Into BMP Files
By Dang Tuan:

The answer is unexpectedly simple! Create a new project, add a form, then put a picture box and a command button into it. Add block of code into command button click event.

    Private Sub Command1_Click() 
        ' Load meta picture file
        Picture1.Picture = LoadPicture("e:\tuan.wmf") 

        ' Save meta picture to bitmap file
        SavePicture Picture1.Image, "e:\tuan.bmp" 
    End Sub 

Display Image File Previews in Windows Explorer
By Adrian Smith:

You can do this by simply changing the view in explorer to view as web page. This will also show any image types, gif, jpg, etc. when you click on them.

Breaking a color into red, green, and blue components
To break an RGB color value into its components, use:
    r = color And &HFF&
    g = (color And &HFF00&) \ &H100&
    b = (color And &HFF0000) \ &H10000
There are some system colors that have funny values like &H8000000F&. Unfortunately they don't work this way. You can use the GetSysColor API function to find these color values. Use And to mask off the leftmost digit. Then use GetSysColor to see get the color value.
Public Declare Function GetSysColor _
    Lib "user32" Alias "GetSysColor" _
    (ByVal nIndex As Long) As Long
    If color And &H80000000 Then _
        color = GetSysColor(color And &HFFFFFF)

One final case occurs if you use Point to get the color of a pixel that does not exist. For example, on a form with ScaleMode = vbPixels, Point(-100, -100) returns -1 because there is no pixel at (-100, -100).

The following subroutine breaks a color into its components. If the color is -1, the routine leaves r, g, and b unchanged. Depending on your application, you may want to set them to default values such as 0 or 255.
Public Declare Function GetSysColor _
    Lib "user32" Alias "GetSysColor" _
    (ByVal nIndex As Long) As Long

' Break a color into its components.
Private Sub BreakColor(ByVal color As Long, _
    ByRef r As Long, ByRef g As Long, _
    ByRef b As Long)

    If color = &HFFFFFFFF Then Exit Sub

    If color And &H80000000 Then _
        color = GetSysColor(color And &HFFFFFF)

    r = color And &HFF&
    g = (color And &HFF00&) \ &H100&
    b = (color And &HFF0000) \ &H10000
End Sub
Thanks to Horst F. Haupt (HorstFH@aol.com) and Kenneth Biel (Kenneth.Biel@wcom.com) for their suggestions.

Understand Compressed Graphics
If you include a GIF or JPEG picture in a PictureBox or Image control, either at design time or at run time, the control stores the image in its original compressed form. That means it takes less space in the program, but it will take longer to display.

For example, if you load compressed JPEG images into a form at design time and then create a compiled executable (in VB5), the executable will be smaller than it would had you used BMP images. This lets you cram a lot of pictures into a reasonably small image.

If you use PaintPicture to copy an image, the new picture is always in the larger, faster BMP format. If you need to speed the program up, save pictures in JPEG format. Then at run time use PaintPicture to copy them into new controls so you can display them from the BMP format.

Send your Tips and Tricks to feedback@vb-helper.com.

Subscribe to the VB Helper newsletter
Copyright © 1997-2001 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
www.vb-helper.com/tips9.htm Updated