Visual Basic Explorer
Visual Basic Explorer
 Navigation
 Home


 Coding
 Source Code

 FAQ Center

 VB Tips

 Downloads

 ToolBox

 Tutorials

 VB Games

 VB News

 VB Award

 VB Forums



 Affiliates
 Planet Source Code

 Rent a Coder

 DirectX4VB


 Misc
 Search

 Feedback

 Advertise

 About


Need to hire
a VB coder?

Please support our sponsor:

 Home 
 Site Map 
 Forums 
 News 
 Feedback 

Visual Basic 5
Unsupported Controls and Utilities

When you first load the Visual Basic 5 CD into your machine and run setup.exe, you're presented with the Master Setup dialog box, which acts more like a web page and duplicates the artwork from the Visual Basic packaging. The third hyperlink from the top is labeled "Explore the CD". If you're like most of us, you went right past this and clicked on "Install Visual Basic" so you could get into it! However, exploring the CD is something we should go back to. Some of the Microsoft development system CD's contain treasures most people are unaware of, and this one is no exception.

We're going to go back to the CD now and explore it a bit more. The \tools\unsupprt directory contains a large number of controls and utilities we know absolutely nothing about. A slew of these are also useful in developing GUI's for our own applications.

It almost appears as if these controls and utilities were Microsoft in-house samples they decided were good enough to give out. I’ve also heard a rumor that runs along these lines: "When the programmers are coding the extras (bell and whistles) of the program, sometimes the program manager will cut them off and say ‘No more, I don't care if it’s not done, they aren't necessary to begin with and we have to meet the ship date’". Regardless of why they’re there, or where they came from, the reality is that some of them still need a little work, but it's nothing which can't be overcome.

In this chapter we'll be looking at:

  • The MSVBCalendar Control

  • Dialog Automation Objects

  • The System Tray Icon Control

  • The Disclaimer

    Yes, we need to have one of these! Workarounds and "fixes" are going to seem commonplace with some of these items. But at the same time, we’ve got the code in most cases. Sooner or later we’ll figure out why these things don’t work quite right and we’ll be able to fix them. For now, however, we may have to kludge some of it the best we can.

    These, and the other items in the \tools\unsupprt directory of the Visual Basic 5 CD, are NOT supported by Microsoft. This is better explained by the following sentence from the bottom of the Help | About box for the MSVBCalendar control, which we’ll be looking at shortly:

    "Warning: This is an unsuported (sic) sample control. Microsoft takes no responsibility for this control and no official support is available for this control."

    And even though Wrox Press is providing a bit of documentation for some of these items through this book, we can’t take responsibility for them either. Remember, if you intend to use and/or distribute these items in your own applications, test it, retest it, then test it again. When you’re done with that, TEST IT SOME MORE! You’ll be the one getting the telephone calls if you don’t! And then, who ya’ gonna’ call?!?

    But these goodies are worth more than just a brief look. They’re quite nicely done and they deserve some use. In some instances, they’re also a new, rather "sideways" look at how to accomplish certain tasks which have been accomplished differently up until now.

    We’re going to start with something which has been a long time in coming -

    The MSVB Calendar Control

    Microsoft Access has always had a nice calendar control. Ever since the first calendar control was released in an earlier version of the Access Developer’s Toolkit, some Visual Basic developers have been a little jealous. Sure, calendar controls for Visual Basic from third-party developers have come and gone, but Visual Basic has never been released with one of its own.

    Well, it has come to pass! There’s quite a nice calendar control in the \tools\unsupprt directory of the Visual Basic 5 CD that has some extensive capabilities. It’s also supplied with a rather in-depth test program in order to show off the capabilities of, and enumerate the properties of, the calendar itself.

    Features

    An interesting aspect of the MSVBCalendar control is that it’s been supplied not as a finished *.ocx, but in the form of complete Visual Basic 5 source code! This is something the Access developers have never had to their advantage. At the same time, this calendar is fully compatible with 32-bit versions of Access.

    Also, the Access calendar control only handles the years from 1900 to 2100. In comparison, the Visual Basic Calendar Control is not only fully Y2K compatible, it uses a four-digit year field, and handles the years from 100 AD to 9999 AD without any problems! Since the source code is provided, the years could easily be extended even from this point outward. However, I don’t know of a reason to do such a thing as of yet. Maybe if someone was writing an application for some kind of extensive history exam …

    Getting Started

    First of all, we need to get the code for the control from the Visual Basic 5 CD and onto the local hard drive. I have a little place where I’ve placed these kinds of items so I can work with them more easily. We’ll get the code onto the hard drive, change some file attributes, then get going with a look at the control itself.

     

    Copying the Source Code

    Create a place on your hard drive to store the source code and other files for the items we’re going to be copying from the CD. For instance, the copy of Visual Basic 5 that I use is located in the e:\vb directory. Within this directory I’ve created a new folder and labeled it Projects:

    This is the same type of directory used in other development packages for this purpose. In fact, Microsoft Visual C++ installs a directory similar to this during its own setup program and saves new projects to it by default.

    Load the Visual Basic 5 CD into your CD drive and go to the c:\tools\unsupprt directory. Within this directory, highlight the Calendar directory:

    Right-click on this directory and click Copy from the pop-up menu.

    Now, go back to your new Project directory, right-click on it and click Paste. This places all the source code for the Calendar Control where we can get to it.

    When we get ready to run the test program for the control, we’ll do so before creating the control itself. At this point, the Visual Basic IDE will attempt to write information back to these files. Before this can occur, we need to change the attributes for these files since they are currently all "Read-only".

    Open the directory on your hard drive containing the source code you just copied. Highlight all of the files, excluding the Res subdirectory. This is most easily accomplished by highlighting the first file in the directory, holding down the Shift key, then clicking on the last file in the directory.

    With these files highlighted, right-click on the whole list. Select Properties from the pop-up menu and the dialog box will appear:

    Clear the "Read-only" check box and click the OK button. Then, repeat the last part of this procedure with the contents of the Res subdirectory.

    The Projects

    Unless you’ve built a custom control with Visual Basic before, you may not yet be aware that Visual Basic 5 is capable of hosting more than one project at a time in its IDE. The code for the calendar control is stored as a pair of projects, one for the control itself and one for its test program. These projects are named MSVBCldr.vbp and CldrTest.vbp respectively. There’s also a third project within the files for this control, which is named Clndr.vbg. This is the group project, which gives the Visual Basic IDE the information necessary to open both of the other projects at the same time.

    Looking At The Code

    Start Visual Basic and open the project group Clndr.vbg. Once it loads, the Project Explorer will look something like this:

    Notice the calendar control MSVBCalendar is made up of at least one of everything, while the test project contains only a single form. Open this form in design mode, and you’ll see that it is anything but simple. We’re going to use this form in our discussion on the various features of the Calendar Control.

    Try It Out - Running the Test Project

    Press the F5 key to start the test project. The CalendarTest project will be assembled, and will subsequently present its single form to you with the calendar in place.

    Since CalendarTest is bolded in the Project Explorer, this is the project that will run when you either press the F5 key or select Run \ Start from the menubar of the Visual Basic 5 IDE. This is set in the Project Explorer window. Place the mouse cursor directly over the CalendarTest heading and right-click. You’ll see the top item on the popup menu is "Set as Start Up". If you do the same thing with the MSVBCalendar heading, you’ll find this menu item is disabled. That’s because a control project cannot be opened without a project to open it into. If there were another project in this group, one would have its "Set as Start Up" menu item checked and the other would not.

    Click on some of the items on the Test form. You’ll notice that when you click on the calendar itself to change the highlighted day, or click on the command button with the caption ‘Set’, entries appear in the list box. Also, when you click on other items on the form, various properties of the control are changed.

    Properties of the Calendar Control

    The properties for the MSVBCalendar control are almost identical to those of the Access calendar control. So, if you’ve used the other control, this one will seem familiar. If you’re not familiar with it, it’s really not difficult to understand. Let’s take a look at the properties:

     

    Property

    Description

    Day

    Returns/Sets the day number of the selected date.

    DayColor

    Returns/Sets the color used for the day numbers

    DayFont

    Returns/Sets the font used for the day numbers

    DayNameColor

    Returns/Sets the color used for the day names (i.e. days of the week)

    DayNameFont

    Returns/Sets the font used for the day names

    DayNameFormat

    Returns/Sets the format to use for the day names (calShortName = "M", calMediumName = "Mon", calLongName = "Monday")

    Month

    Returns/Sets the month number of the currently selected date (i.e. calJanuary = 1)

    MonthReadOnly

    Returns/Sets the read-only state of the month navigation combo box

    ShowIterrationButtons

    Returns/Sets the visible state of the previous and next month navigation buttons

    StartOfWeek

    Returns/Sets the first day of the week which will be displayed in the left-most column (calUse System = 0, calUseSunday = 1, … calUseSaturday = 7)

    Year

    Returns/Sets the year number of the currently selected date (4-digit integer)

    YearReadOnly

    Returns/Sets the read-only state of the year navigation text box

    DataBindings

    Returns/Sets a DataBindings Collection object that collects the bindable properties that are available to the developer

    DataField

    Returns/Sets a value that binds a control to a field in the current record

    DataSource

    Sets a value that specifies the data control through which the current control is bound to a database

    The DataBindings, DataField, and DataSource properties aren’t implemented in the form within the CalendarTest project since there’s no database to go with this sample. If we need to connect this control to a database, we also need to provide a Data control on any form we design with this control in order to link the control to the correct database via the calendar’s DataSource property.

    Events of the Calendar Control

    Two events can be seen listed in the list box in the test sample whenever you click on a date on the calendar or click on the ‘Set’ button. The first one is WillChangeDate, whose syntax looks like this:

    WillChangeDate(ByVal NewDate As Date, Cancel As Boolean)

    This event indicates that the currently selected date is about to change to the value NewDate. Immediately after this event, you’ll see the listing for the occurrence of the DateChanged event:

    DateChange(ByVal OldDate As Date, ByVal NewDate As Date)

    This occurs immediately after the date value has been changed, and shows both the old and new dates.


    Visit us for other web hosting reviews for your projects.


    [Home Page] [Next Lesson] [Previous Lesson] [Dave Liske's Site] [Wrox Web-Developer]





    Home | About | What's New | Source Code | FAQ | Tips & Tricks | Downloads | ToolBox | Tutorials | Game Programming | VB Award | Search | VB Forums | Feedback | VBNews | Copyright & Disclaimer | Advertise | Privacy Policy |

    Quick searches: Site Search | Advanced Site Search 

    Copyright 2002 by Exhedra Solutions, Inc.
    By using this site you agree to its terms and conditions
    VB Explorer and VBExplorer.com are trademarks of Exhedra Solutions, Inc.