March 5, 1999

Use MouseMove for Easy StatusBar Updates

You can easily make your program show descriptive text on a StatusBar control in response to mouse movement. Assign the text to the appropriate panel in the MouseMove events of the appropriate controls, then use the Form_MouseMove event to clear text from the panel: Private Sub txtAddress_MouseMove(Button As Integer, Shift

Easy Confirmation

Sometimes you want to give your users the chance to confirm that they wish to proceed with the closure of a form. Instead of using a MsgBox function and a Select Case statement, put this code in the Form_Unload event: Private Sub Form_Unload(Cancel as Integer) Cancel = (MsgBox(“Quit now?”, vbOKCancel

Show Data With Outlook Grid

You can easily create a calendar grid similar to the one in Outlook to show data. First, start a VB project, then place an MSFlex Grid on the form, with two textboxes to set the start and end dates and a command button to populate the grid. Paste this code

Provide a Horizontal Scroll Event for a Listbox

Subclassing a listbox allows you to monitor horizontal scrolling. To subclass a listbox, you store the original WndProc in the UserData area of the listbox, allowing a single replacement of WndProc to work for all ListBox controls. WndProc notifies your form of a horizontal scroll message by sending a WM_MOUSEMOVE

Base Class Constructor With Arguments

When a constructor has to pass arguments to its base class constructor or to an embedded object, you must use a mem-initializer: class base {private: int num1; char * text;public: base(int n1, char * t) {num1 = n1; text = t; } //no default constructor, all arguments must be supplied};class

Pseudo Destructors

Fundamental types have a pseudo destructor. A pseudo destructor is a syntactic construct whose sole purpose is to satisfy the need of generic algorithms and containers. It is a no-op code and has no real effect on its object. typedef int N; int main(){ N i = 0; i.N::~N(); //1:

Exception Type Match

When an exception is thrown, the exception handling mechanism searches for a matching handler for it. The matching rules for exceptions are more restrictive than the matching rules for function overloading. For example: try{ throw int();}catch (unsigned int) //will not catch the exception from previous try-block{ } The exception thrown

std::string Should Never be Initialized With a NULL Pointer

You can initialize std::string with a pointer to char. However, it does not check the pointer. When the pointer happens to be NULL the results are undefined: #includeusing std::string;const char * getDescription(int symbol); // returns NULL when symbol cannot not foundvoid writeToString (string & str, int symbol){ str = getDescription(symbol);

Overloaded Operators May Not Have Default Parameters

Unlike ordinary functions, overloaded operators cannot declare a parameter with a default value (overloaded operator() is the only exception): class Date{ private: int day, month, year; public: Date & operator += (const Date & d = Date() ); //error, default arguments are not allowed}; This rule may seem arbitrary. However,

No more posts to show