The functions used for writing and printing windows, wn_wr() and wn_print(), get the information from the window's destination. As we have said, in most cases this means that these functions use the video screen. They print the contents of the destination that correspond to the window's coordinates. Therefore, if you print a window that is on the screen, and it currently has other windows overlapping it on the screen, you will print portions of these windows as well. By modifying the destination, you can isolate a window from the other windows. The following tutorial, wn_write.c, demonstrates this technique.
|
||
|
|
|
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
|
|
||
|
|
|
|
||
The steps followed in the code example are discussed below.
| 1 | Define the main window and assign it a buffer. Because we are adding margins, we define the main window with wn_nbdef(), set the margins, and then assign it a buffer with wn_msmod(). |
| 2 | Define the child window and assign its parent. Normally windows have the full screen window FULL_WNP as a parent. We use sw_parent() to make this window a child of the main window. Then, when we put the window up, it is put into the main window's buffer. |
| 3 | Define the higher sibling window. Both this window and the main window are children of FULL_WNP, which makes them siblings. Because we put this window up last, it will be the HIGHEST child of FULL_WNP, and thus higher than the main window. Its coordinates are such that it partly overlaps the main window on the screen. |
| 4 | Write instructions, wait for a keystroke, and write the full dimensions of the window, including border and margins. Because wn_wr() copies the information directly from the window's destination (in this case, the screen), the image on the screen will be written exactly as it appears, complete with windows that overlap it. |
| 5 | Isolate the window image with sw_dest(), and write it again. A screen-sized memory screen is created with ms_def() and assigned to the window with sw_dest(). Because child windows appear within their parent, sw_dest() propagates the new destination to all children. Thus, when the main window is written, the overlapping part of the higher sibling is gone, but the child window still appears. This can be useful for printing complex forms that use several related windows. |
| 6 | Completely isolate the window, and write it again. To completely isolate the main window from all other windows, including its children, we set its destination to the memory screen directly instead of calling sw_dest(). This prevents the child window from inheriting the new destination. Although we do not generally recommend setting (or even referencing) structure members directly, some members are unlikely to change names from release to release, and wnp->destp falls into this category. |
| 7 | Take down the windows and free memory. |