beautypg.com

HP Integrity NonStop J-Series User Manual

Page 265

background image

//1

This is the constructor for DemoWindow. It requires the handle of the application instance
creating it, mom, the handle of any previously existing instance, prev, and whether to
show the window in iconic form. These variables are as received from WinMain, the main
windows procedure that we have already seen.

//2

The constructor checks to see if any previous application instance has been run and, if not,
registers the class.

//3

The new window is created.

//4

A key feature is the use of the Windows extra data feature to store the this pointer for this
DemoWindow. The procedure to do this is somewhat cumbersome, but very useful. The
value placed here will appear in the CREATESTRUCT structure, which we can retrieve
when processing the WM_CREATE message generated by the CreateWindow function.

//5

This member function is only called for the first instance of an application.

//6

The global function DemoWindow_Callback is registered as the callback procedure for
this window.

//7

We ask Windows to set aside space for the this pointer in this Windows class. This will be
used to associate a Windows handle with a particular DemoWindow.

//8

The destructor calls clearAndDestroy() to delete all items that have been inserted into
myList.

//9

The member function insert(RWDrawable*) inserts a new item into the window. Because
RWDrawable inherits from

RWCollectable

, as we shall see later on, there is no need to do

a cast when calling RWSlistCollectables::insert(RWCollectable*). By making myList
private and offering a restricted insert that takes arguments of type RWDrawable* only,
we ensure that only drawables will be inserted into the window.

//10 Here's the paint procedure, called when it is time to repaint the window.

//11 We start by getting the handle for this window, then calling BeginPaint to fill a

PAINTSTRUCT with information about the painting.

//12 An iterator is constructed in preparation for traversing the list of items to be painted.

//13 Get the next item to be painted. If nil is returned, then there are no more items and the

while loop will finish.

//14 For each item, call the virtual function drawWith, causing the item to paint itself onto the

given device context.

//15 The PAINTSTRUCT is returned.

//16 Here's the callback routine to be called when it is necessary to process a message for this

window. It uses the very convenient _export keyword of Borland C++ to indicate that this
function should be exported. If you use this procedure, you don't have to list the function
in an Exports section of the module definition file.

This manual is related to the following products: