A sample application main routine is illustrated in Figure "Sample Application Main Routine (Part 1) - Registration" and Figure "Sample Application Main Routine (Part 2) - Window Creation". The functions performed by the main routine are as follows:
Note that under OS/2 Version 2.0, the WinCreateSwitchEntry() function is provided in addition to the WinAddSwitchEntry() function. These two functions accept identical parameters and carry out identical tasks; the WinCreateSwitchEntry() function is intended to provide consistent function naming conventions. The WinAddSwitchEntry() function is retained under OS/2 Version 2.0 for compatability with existing applications, but use of the WinCreateSwitchEntry() function is recommended.
The structure of the main routine is similar for both the application (that is, the application's primary thread) and any secondary threads created by the application. See Multitasking Considerations for further discussion on secondary threads.
In Figure "Sample Application Main Routine (Part 1) - Registration", note the use of the EXPENTRY keyword in the function prototype to specify the system linkage convention for the window procedure wpMain. This is required whenever declaring a window procedure or dialog procedure, since such procedures are normally invoked by Presentation Manager on the application's behalf, rather than directly by the application.
If the application is to appear in and be selectable from the Workplace Shell Window List, the main routine must issue a WinAddSwitchEntry() function call, after creating the application's main window and before entering the message processing loop. [Note that under OS/2 Version 2.0, use of the WinCreateSwitchEntry() function is recommended, for reasons of consistency in function names. ] This function call is shown in Figure "WinAddSwitchEntry() Function".
Note that the application may set the swTitle field of the SwitchData structure to NULL. Presentation Manager will then determine the title under which the application was started from the Presentation Manager shell, and use this title for the switch entry.
The WinAddSwitchEntry() function returns a switch entry handle, which may be stored by the application and used during termination to remove the switch entry from the Workplace Shell Window List using the WinRemoveSwitchEntry() function.
The switch entry may be accessed by a window procedure at any time during application execution. The switch entry handle is obtained using the WinQuerySwitchHandle() function, and the SwitchData control structure may then be obtained using the WinQuerySwitchEntry() function, and altered using the WinChangeSwitchEntry() function. This capability may be used to allow a window procedure to obtain the handle of the application's main window, in order to post or send messages to that window. This is discussed in Identifying the Destination Window.