Using the Destination for Isolating the Window for Printing

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.

#include <vv_key.h>
 
#include <vv_main.h>
/* Main module header file



*/
int main()

{
   
    WINDOWPTR wnp, swnp, cwnp;
/* Pointers to windows we will use
*/
    SCRPTR msp;
/* Pointer to memory screen for
*/
 
/* isolation



*/
    vv_init();
/* Initialize Vermont Views
*/
    vs_clr();
/* Clear the video screen



*/
    /*  Allocate and initialize the main window.                    

    wnp = wn_nbdef(0, 0, 17, 40, (UCHAR)LHIGHLITE, BDR_DLNP);

    sw_mg(2, 2, 3, 3, CH_LIGHTSHADE, LCLINACT, wnp);
*/
    wn_msmod(wnp);
/* Match buffer to current size
*/
    wn_up(wnp);



 
*/
    /*  Allocate and initialize the child window.                    

    cwnp = wn_def(5, 5, 4, 10, (UCHAR)LHIGHLITE, BDR_SLNP);

    v_st("Child\n", cwnp); 

    v_st("Window", cwnp); 
*/
    sw_parent(cwnp, wnp);

    wn_up(cwnp);

/* Make main window its parent
*/
    /*  Allocate and initialize the higher sibling window.                

    swnp = wn_def(15, 15, 5, 15, (UCHAR)LHIGHLITE, BDR_SLNP);

    v_st("Higher\n", swnp); 

    v_st("Sibling\n", swnp); 

    v_st("Window", swnp); 
*/
    wn_up(swnp);
/* Last sibling set is top sibling



*/
    /*  Write instructions to the window that will be printed.            

    v_st("Hello, world!\n", wnp); 

    v_st("Press any key to write my image\n", wnp);

    v_st("directly to file wn_write.all", wnp);
*/
    ki();
/* Wait for a keystroke



*/
    /*  Write the window to the file wn_write.all.  Copies the whole
*/
    /*  window image, including the child window and part of the
*/
    /*  overlapping window.                                     wn_wr("wn_write.all", "w", PRINT_FULL, wnp);



*/
    /*  Clear the main window and write new instructions to it.                wn_clr(wnp);

    v_st("Now press any key to write my\n", wnp);

    v_st("image with just my CHILDREN\n", wnp);

    v_st("to file wn_write.chl", wnp);
*/
    ki();
/* Wait for a keystroke



*/
    /*  Create a memory screen and use sw_dest() to put window on it.
*/
    /*  The child window will inherit the new destination, too.
*/
    /*  wn_up() will redisplay the whole window, including borders AND
*/
    /*   children.
 
*/
    msp = ms_def(vs_rowq(), vs_colq(), LNORMAL);
*/
    sw_dest(msp, wnp);    
/* Change the window's destination
*/
    wn_dn(wnp);
/* WILL NOT CHANGE ORIGINAL SCREEN
*/
    wn_up(wnp);
/* Display window on new destination
*/
    wn_wr("wn_write.chl", "w", PRINT_FULL, wnp);
*/
    sw_dest(VID_SCRP, wnp);
/* RESTORE the window's destination



*/
    /*  Clear the main window and write new instructions to it.            

    wn_clr(wnp);

    v_st("Now press any key to write JUST\n", wnp);

    v_st("this window to file wn_write.me", wnp);
*/
    ki();
/* Wait for a keystroke



*/
    /*  Move JUST main window to memory screen by setting its
*/
    /*  destination directly.  Now the printed image will not include 
*/
    /*  ANY other windows.
 
*/
    wnp->destp = msp;
/* Set destination explicitly
*/
    wn_dn(wnp);
/* WILL NOT CHANGE ORIGINAL SCREEN
*/
    wn_up(wnp);
/* Display window on new destination
*/
    wn_wr("wn_write.me", "w", PRINT_FULL, wnp);
 
    wnp->destp = VID_SCRP;
/* Restore window to original
*/
 
/* destination



*/
    /*  Take windows down and free them.  Free the memory screen.
*/
    wn_dn(cwnp);

    wn_dn(swnp);

    wn_dn(wnp);

    wn_free(wnp);

    wn_free(swnp);

    wn_free(cwnp);

    ms_free(msp);

    
   
    vv_exit();
/* Exit Vermont Views
*/
    return(0);

}
   

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.


Home Contents Previous Next