home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / window / ultrawin / uwdemo / start_1.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-02  |  11.3 KB  |  274 lines

  1. /****************************************************************************/
  2. /*                                                                          */
  3. /* START_1.C                                                                */
  4. /*                                                                          */
  5. /*     This C skeleton program was written to show you how to get up and    */
  6. /* running quickly with the UltraWin library.  But first, allow me to       */
  7. /* explain a little about the techniques we use.                            */
  8. /*                                                                          */
  9. /*     UltraWin was written with two "levels" in mind.  The first level     */
  10. /* includes the routines that do all the down and dirty work of windowing.  */
  11. /* This program is a demonstration showing how to use the lowest level      */
  12. /* functions in an application.  The advantage to using this "first level"  */
  13. /* layer is speed!  If you want the maximum speed, use this starter program */
  14. /* as a "shell" to your application.                                        */
  15. /*                                                                          */
  16. /*     The second layer is what we call the window manager.  This is the    */
  17. /* really slick part of UltraWin, as this provides capabilities to write    */
  18. /* to any window at any time, regardless of overlap!  This layer is dealt   */
  19. /* with in the START_2.C skeleton program.                                  */
  20. /*                                                                          */
  21. /*     The main thing to remember when using the "first level" style of     */
  22. /* windowing is never mix the window manager routines with these routines,  */
  23. /* unless you are absolutely sure you know what your are doing.  The        */
  24. /* functions to stay away from when using the style used in this skeleton   */
  25. /* are:                                                                     */
  26. /*                                                                          */
  27. /*                1)  add_window()                                          */
  28. /*                2)  remove_window()                                       */
  29. /*                2)  make_top_window()                                     */
  30. /*                                                                          */
  31. /* All other functions are ok to use.                                       */
  32. /*                                                          Boyd Gafford    */
  33. /*                                                          EnQue Software  */
  34. /*                                                          12/18/90        */
  35. /*                                                                          */
  36. /****************************************************************************/
  37. #include <ctype.h>
  38. #include "uw.h"                           /* include the necessary headers  */
  39. #include "uw_globx.h"
  40. #include "uw_keys.h"
  41.  
  42.  
  43. /*----------------------- global window variables --------------------------*/
  44. WINDOW   Desk_window;                    /* global window for "desktop"     */
  45. WINDOW   Pop_window;                     /* global POPUP window!            */
  46.  
  47.  
  48. /*------------------------------ prototypes --------------------------------*/
  49. void display_event( void );
  50.  
  51. /*********/
  52. /* ~main */
  53. /*       ********************************************************************/
  54. /* This is the main routine, which does the simple skeleton demo!           */
  55. /****************************************************************************/
  56. int main()
  57. {
  58.  
  59.   init_video(80, 50);
  60.  
  61.   /* This function initializes the window library, and sets the screen to   */
  62.   /* 80 columns and 50 rows.  After the function call, the global variables */
  63.   /* V_cols will contain the actual number of columns on the screen, and    */
  64.   /* V_rows will contain the actual number of rows.  If you have a VGA      */
  65.   /* board, you will get V_cols = 80 and V_rows = 50.  If you have an EGA   */
  66.   /* board, you will get V_cols = 80 and V_rows = 43.  If you just have CGA */
  67.   /* you will get V_cols = 80 and V_rows = 25.  If you wanted to use the    */
  68.   /* 80x25 screen on ANY board, just use init_video(80, 25).                */
  69.  
  70.     init_clock(0x3333);
  71.  
  72.     /* This function takes over the PC clock, setting the timer interrupt to  */
  73.     /* occur 91 times a second.  Once this call is made, you can use any of   */
  74.     /* the UltraWin user timers, or the tone() function.  You do not have to  */
  75.     /* call this if you are not going to use any of the UltraWin PC timer     */
  76.     /* routines.                                                              */
  77.  
  78.     init_mouse();
  79.  
  80.   /* This will check for a mouse, and set the global Mouse_exists variable  */
  81.   /* to 1 if one is found, or 0 if one is not.  To actually show the mouse, */
  82.   /* you must call m_show after this function.                              */
  83.  
  84.  
  85.   wn_create(0, 0, V_cols-1, V_rows-1, SLD_BDR, WN_POPUP, &Desk_window);
  86.  
  87.   /* This call will create a window equal to the size of the screen.        */
  88.  
  89.  
  90.   wn_color(YELLOW, BLUE, &Desk_window);
  91.  
  92.   /* Set the color of the Desk_window to YELLOW text on a BLUE background.  */
  93.  
  94.  
  95.   wn_bdr_color(WHITE, BLUE, &Desk_window);
  96.  
  97.   /* Set the border color of the Desk_window to WHITE on BLUE               */
  98.  
  99.  
  100.   wn_name("[ Desktop Window ]", &Desk_window);
  101.  
  102.   /* Set the title of the back window to something kind of descriptive.     */
  103.  
  104.   wn_set(&Desk_window);
  105.  
  106.   /* Now, actually draw the window to the screen, saving what was below     */
  107.   /* since the window was defined as a POPUP window when created!           */
  108.  
  109.  
  110.   wn_plst(CENTERED, V_rows / 2, "Press a key or click the mouse!", &Desk_window);
  111.  
  112.   /* This just centers the message on line 2 of the Desk_window.  Note that */
  113.   /* we use the special CENTERED define to replace the x-coord in the place */
  114.   /* string output function.  We just as easily could have specified an xy  */
  115.   /* pair, LEFT_JUST, or RIGHT_JUST to make string placement super easy!    */
  116.  
  117.   m_show();
  118.  
  119.   /* This shows the mouse on the screen!  Please note that a call to        */
  120.   /* m_hide() before any of your window output routines is necessary to     */
  121.   /* maintain screen integrity.  We chose to let you set when you show and  */
  122.   /* hide the mouse rather than making it automatic, as calling hide and    */
  123.   /* show after every output function possible is a little overkill and can */
  124.   /* slow things down a little.                                             */
  125.  
  126.   wait_event();
  127.  
  128.   /* Just sit around and wait for either a mouse press or a key.  When the  */
  129.   /* event occurs, the global Event variable will contain the key press     */
  130.   /* information,  or mouse click information.                              */
  131.  
  132.  
  133.   display_event();
  134.  
  135.   /* This is a function at the end of this skeleton file that demonstrates  */
  136.   /* how to set a POPUP window on top of another window.  After the window  */
  137.   /* is "popped up", the information in the global Event variable is shown, */
  138.   /* and waits for another event while you look at it!                      */
  139.  
  140.  
  141.   wn_plst(CENTERED, V_rows-5, "POPUP off now, area restored!", &Desk_window);
  142.   m_show();
  143.   wait_event();
  144.  
  145.   /* Display another message, and wait for an event before dropping to DOS. */
  146.  
  147.  
  148.   wn_destroy(&Desk_window);
  149.  
  150.   /* this destroys the window you created, which means since it was defined */
  151.   /* as a POPUP what was under it is restored.                              */
  152.  
  153.   m_hide();
  154.   end_mouse();
  155.  
  156.   /* This routine tells UltraWin to turn off the mouse if present, and get  */
  157.   /* ready to return to DOS.  If you don't call this function before you    */
  158.   /* exit the program, you may find that your mouse will be active at the   */
  159.   /* DOS prompt!                                                            */
  160.  
  161.  
  162.   end_video();
  163.  
  164.   /* This cleans up and resets the video mode that was active when you      */
  165.   /* first began the program.  Be sure to call this as the last function    */
  166.     /* before you return to DOS!                                              */
  167.  
  168.   return(1);
  169. }
  170. /*** end of main ***/
  171.  
  172.  
  173. /******************/
  174. /* ~display_event */
  175. /*                ***********************************************************/
  176. /* Demo a popup window that displays the info in the Event global!          */
  177. /****************************************************************************/
  178. void display_event( void )
  179. {
  180.   int    width = 40;
  181.   int    height = 15;
  182.   int    x1 = (V_cols - width) / 2;
  183.   int    y1 = (V_rows - height) / 2;
  184.   int    x2 = x1 + width - 1;
  185.   int    y2 = y1 + height - 1;
  186.  
  187.   /* Just a couple of calculations based on screen size to make wn_create   */
  188.   /* look a little cleaner.  This sets a window in the middle of the screen */
  189.   /* regardless of the number of rows (V_rows) we are working with!         */
  190.  
  191.  
  192.   wn_create(x1, y1, x2, y2, SGL_BDR, WN_POPUP, &Pop_window);
  193.  
  194.   /* This call will create a little popup window centered in the screen.    */
  195.  
  196.  
  197.   wn_color( WHITE, RED, &Pop_window);
  198.  
  199.   /* Set the color of the Pop_window                                        */
  200.  
  201.  
  202.   wn_bdr_color( WHITE, RED, &Pop_window);
  203.  
  204.   /* Set the border color of the Pop_window                                 */
  205.  
  206.  
  207.   wn_name("[ Event Contents ]", &Pop_window);
  208.  
  209.   /* Set the title of the little popup window to somthing descriptive.      */
  210.  
  211.  
  212.   m_hide();
  213.  
  214.   /* Hide the mouse before we popup the window on the screen                */
  215.  
  216.  
  217.   wn_set(&Pop_window);
  218.  
  219.   /* Now, actually draw the window to the screen, saving what was below     */
  220.   /* since the window was defined as a POPUP window when created!           */
  221.  
  222.  
  223.   if (Event.is_mouse)
  224.   {
  225.     wn_plst(CENTERED, 4, "Mouse Clicked!", &Pop_window);
  226.     mv_cs(12, 7, &Pop_window);
  227.     wn_printf(&Pop_window, "X = %d, Y = %d", Event.m_x, Event.m_y);
  228.     mv_cs(9, 10, &Pop_window);
  229.     switch(Event.m_button)
  230.     {
  231.       case LB: wn_st("Left Button Pressed", &Pop_window);   break;
  232.       case MB: wn_st("Middle Button Pressed", &Pop_window); break;
  233.       case RB: wn_st("Right Button Pressed", &Pop_window);   break;
  234.     }
  235.   } else
  236.   {
  237.     wn_plst(CENTERED, 5, "Key pressed!", &Pop_window);
  238.     mv_cs(15, 9, &Pop_window);
  239.     if (isalnum(Event.key))
  240.       wn_printf(&Pop_window, "key = %c", Event.key);
  241.     else
  242.       wn_printf(&Pop_window, "key = 0x%02x", Event.key);
  243.   }
  244.  
  245.   /* The above code simply displays the event information in the window!    */
  246.   /* note the format for wn_printf.  Also note the use of the mv_cs()  macro*/
  247.   /* to place the "window cursor" at the xy pair passed.  Any subsequent    */
  248.   /* output, such as wn_st or wn_printf, occurs at that location            */
  249.  
  250.  
  251.   m_show();
  252.   /* Ok all the output we want to do before we wait for a key is done, so   */
  253.   /* we can show the mouse on the screen again.                             */
  254.  
  255.  
  256.   wait_event();
  257.  
  258.   /* Just sit around and wait for either a mouse press or a key.            */
  259.  
  260.  
  261.   m_hide();
  262.  
  263.   /* Hide the mouse while we call wn_destroy to restore the POPUP.          */
  264.  
  265.  
  266.   wn_destroy(&Pop_window);
  267.  
  268.   /* this destroys the window you created, which means since it was defined */
  269.   /* as a POPUP what was under it is restored.                              */
  270. }
  271. /*** end of display_event ***/
  272.  
  273. /*** END OF FILE ***/
  274.