☰ Menu

Drawing standard Windows images

(Visual Basic 6)

Example screenshot

A rather handy function exists in the Windows API that can be used to draw various standard Windows images into a picturebox or similar control on your forms. This has a number of interesting uses, one of which is being very useful when you are developing ActiveX controls.

Using this API function in place of storing bitmaps in your application to achieve the same effect has a number of advantages:

  • The API method takes all the system colours into account.
  • It can draw images at any size.
  • A number of options are available to change the appearance of the graphic when it is drawn.
  • If a future version of Windows modifies the look of the GUI, your application will automatically take on the new look without any modification.

The API function in question is DrawFrameControl. The following link is to a zip file containing a VB project demonstrating the use of the function, and the different graphics it is capable of drawing.

Zip icon
DrawFrameControl.zip

The project is created in VB6 but should load into VB5 without any problems (you may get some warnings when first opening the project -- ignore these).

When you run the program, you will be presented with a window looking like that in the picture above. There are four categories of image that can be drawn by DrawFrameControl, and each of these can be selected from the "Frame type" combo. After choosing the type, the "Frame image" combo will be filled with all of the types of image that are contained within that category. Select any of these to see what it looks like.

The checkboxes to the right of the window allow you to change various flags that are used to modify the way in which the images are drawn. In your own programs, you can use these for effects such as causing a button to be pushed in when the user clicks the mouse on it.

For further information on this function, see the appropriate topic in the MSDN library.

If you have any comments or suggestions regarding this article, please don't hesitate to contact me.

This article is copyright © Adam Dawes, 2000.