August 20, 1999

Never Use Incompatible Pointers to Member Functions

A reader posted a message on one of the C++ newsgroups recently. He had to port a huge project from Borland C++ 5.0 to Visual C++ 6.0. The project uses the callback mechanism through pointers to member functions. Unfortunatly, these pointers are assigned member functions with incompatible signatures. For example:

Reading a String that Contains Whitespaces

In many C++ primers and courses, one of the common exercises is: “Write a function that reads a string of characters, say, the title of a book, from a keyboard and either write it to a file or to the screen.” Using the getline() member function for that purpose seems

Return Focus After Button Click

Here’s an easy way to return the focus to a control after the user clicks on a button on the screen. If you use the keyboard, you can save time this way by not having to tab back to where you were. First, create a module variable of type Control,

Determine Which ListView Column Was Checked

When using the ListView control in list mode (Listview.View = lvwList), no property indicates which column the user clicked on within the selected row. The ListView’s HitTest method returns only a reference to the ListItem the user clicked on, not the specific subitem. Use the SendMessage API function in the

Create Better Button Arrows

Many times developers use a form’s default font arrow characters for To and From buttons between listboxes. To give your app a nicer, more solid look, do what Microsoft does-use the Marlett font, which is added by default to all Windows 95, 98, and NT4 and later installations. Instead of

Perform Complex Tests in the Immediate Window

If you’ve ever tried to type a small program into the Immediate window or the Debug window in Access, you might have found that the style of VB programming you use in most of your code didn’t work there. For example, this code doesn’t work when you type it into

An Alternative STL Implementation

The STLport organization offers an alternative implementation of the Standard Template Library. You can install the alternative instead of using the existing STL implementation shipped with your compiler. The creators of this implementation claim that it’s fully compatible with VC++ 5.0 and 6.0, as well as many other platforms. You

Close all MDI Children Simply

This code allows you to close all the MDI child forms in an MDI form at once. First, create a menu item in the MDI form, then paste in this code: Private Sub mnuCloseAll_Click() Screen.MousePointer = vbHourglass Do While Not (Me.ActiveForm Is Nothing) Unload Me.ActiveForm Loop Screen.MousePointer = vbDefaultEnd Sub

Efficient Array Copying

Suppose you want to assign the contents of a two-dimensional array to another two-dimensional array: int weekly_hours[5][5]; // source int another_array[5][5]; // destination You can use a nested loop to copy every element of weekly_hours to another_array, as in this example: for (int i = 0; i

No more posts to show