Tips and Techniques - January 1995

By IBM

Tip:

Control the content of instances of WPFolder subclasses (using the Developer's Toolkit for OS/2 Warp).

Technique:

To know when objects have been added to or taken out of instances of your subclass, you can override the WPFolder methods: wpAddToContent and wpDeleteFromContent. These methods are invoked when objects are being added to or removed from a folder's content list (as the result of a copy, move, delete, and so forth). Your overrides to these methods can serve as "notifications" of the action you want to know about.

Tip:

Make sure that you notify the Workplace Shell when you have changed a piece of data that can be visible in a details view to allow all views containing this data to remain "in sync."

Technique:

The values of application-introduced instance data can be changed in a number of places (via a setting page, as a side effect of a UI action, and so forth). However, if you have an open details view containing one of your class's instances, its instance data might not appear to be updated in the details column.

Wherever you change a piece of instance data that is used as a piece of details data, you should invoke _wpCnrRefreshDetails on the modified object. This will update any open details views containing the object.

Tip:

Make sure that your user-defined view of an object appears with a checkmark next to it on the Open submenu when it is the default.

Technique:

There are two values in the system related to each Open-> submenu item. There is a corresponding "menu ID" referenced in the resource file that is associated with the menu item. There is also a "view ID" recognized by various methods in the Workplace Shell (for example, _wpOpen, _wpclsQueryDefaultView, and so forth). In order for your default "view ID" to be associated with the default "menu ID," they must be the same value.

Consider, for example, the "Icon View" of folder objects. Its "view ID" is OPEN_CONTENTS, and its "menu ID" is WPMENUID_ICON. Both IDs have the same value. That is why, for WPFolder, when the method wpclsQueryDefaultView returns the value OPEN_CONTENTS, which is used to determine the appropriate menu choice in the Open-> submenu, it will place the default checkmark on the WPMENUID_ICON menu item.

In addition, if your view is to be the default view you must override wpclsQueryDefaultView and return your view ID.

Tip:

To know when a single view of an object has been closed, do not use wpClose-use wpDeleteFromObjUseList.

Technique:

The wpClose method closes all views of an object (for example, when it is deleted). This may not be what you want. Every object maintains an "in-use list" which holds, among other things, information about each open view of the object. When a view is opened, a use item is added to this list. When a view is closed, a use item is removed from this list. To know when any given view of an object has closed, you can override _wpDeleteFromObjUseList, and examime the type of the USEITEM passed in. If it has a type of USAGE_OPENVIEW, then you are receiving a notification of a view being closed. You can then examine the hwnd or the view type in the use item structure, if necessary (for example, OPEN_CONTENTS, OPEN_RUNNING, and so forth).

Tip:

Take advantage of OS/2 Warp's new animated icon feature for folders to add a customized "open" icon for instances of your WPFolder subclass.

Technique:

Override the method wpclsQueryIconDataN for your subclass. In this method, if the value of the N parameter is 1, that denotes that the "open" icon is being queried, and simply return the icon data for the open icon of your choice. Any instance of WPFolder can also have an open icon other than the default, which can be set by passing the ICONNFILE or ICONNRESOURCE setup string. See the Toolkit documentation for this setup string value.

Tip:

Try using WinStoreWindowPos and WinRestoreWindowPos.

Technique:

This lets your PM Window frames come up in the same position as they were when they were last closed. As a bonus, it saves and restores all your presentation parameters as well.

Tip:

Always use wpViewObject instead of wpOpen to open an object. Always use wpSaveDeferred instead of wpSaveImmediate to save the object state.

Tip:

Open a data file using its default association.

Technique:

Use the following:

hobject = WinQueryObject( "ctxt" ); if ( hobject ) WinSetObjectData( hobject, "OPEN=DEFAULT" );

Tip:

Know when a serious error has occurred in the operating system, use the new DevHlp_RegisterKrnlExit! DevHlp_RegisterKrnlExit allows an OS/2 device driver to handle NMIs (Non-Masked Interrupts), which are Trap 2 Parity Errors, and System Fatal Faults (Ring 0 Traps).

This DevHlp provides a notification to the device driver that a serious error occurred in the operating system and gives the device driver limited access to system resources. Notification occurs during initialization time and kernel-task mode.

Tip:

If your driver needs a context hook, be sure to declare the context hook as far pascal or you'll know the true meaning of a trap D.

Tip:

If you need to display a driver variable periodically, but don't want to stop your driver from executing, place a call to int 3 where you'd like it to be displayed on the debug terminal. Change the default debugger command r to perform your output and then continue executing by using the zs command. The zs command is the default command the debugger executes when it is called as a result of an int 3. If you wanted to display the contents of the variable count, for example, enter the following: zs "dw _count;g" The next time the debugger is entered, it will display the contents of the count variable, then continue running. The commands you wish to perform need to be separated by semi-colons. To reset the default command, just enter: zs "r" This will return the debugger to normal operation.