Threads Containing Object Windows

When a secondary thread is created, and in turn creates an object window as shown in Figure "Secondary Thread Creating an Object Window", the handle of the calling window may be passed to the object window as part of the WM_CREATE message, and the object window procedure uses this handle to pass its own window handle back to the calling window as part of an acknowledgement message. This technique is illustrated in the sample object window procedure shown in Figure "Sample Object Window Procedure".

Once the calling window receives this message and extracts the object window's handle, it should store the handle in its own instance data. It may then use the handle at any time to pass a Presentation Manager message to the object window, in order to initiate an event in the object window.

By convention, messages passed to an object window should contain the window handle of the calling window, within the message parameters. The object window procedure may then use this handle to pass an acknowledgement message or return data to the calling window in the primary thread. This technique allows the same object window to process messages from multiple sources. See Client-Server Applications for additional considerations.

Note that messages passed to object windows in secondary threads should be posted using the WinPostMsg() function, rather than being sent using the WinSendMsg() function. This causes asynchronous processing of the message, and allows the primary thread to return to Presentation Manager and continue interaction with the end user.

In situations where the user must be prevented from carrying out certain actions while the object window processes an event, the calling window procedure should disable those actions in the action bar immediately before posting the message to the object window, and re-enable those actions only after a completion message has been received from the object window. This prevents the user from carrying out such actions, but does not prohibit other actions within the application, or interaction with other applications on the desktop.


[Back: Communicating With a Secondary Thread]
[Next: Threads Without Object Windows]