home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / c / pcw_c.zip / DEMO_C.C < prev    next >
C/C++ Source or Header  |  1991-12-28  |  4KB  |  145 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <conio.h>
  4. #include <ctype.h>
  5. #include <pcwproto.h>
  6. #include <menu.h>
  7. #include <keys.h>
  8.  
  9. void help(void) {
  10.  
  11.    WNDPTR *wnd;
  12.    static char *helpmsg[] = {
  13.       "Use the menu to select which window you want to move around.",
  14.       "Once you have made your selection use the arrow keys to move",
  15.       "the window around the screen or use the mouse to point where",
  16.       "you want to move the window and \"click\" with  the left mouse",
  17.       "key.  To return to the menu use the right Mouse key  or  the",
  18.       "escape key.  This help screen can be invoked from  the  menu",
  19.       "or by using F1 when moving windows around.                  ",
  20.       " ", "Press any key to return",""
  21.    };
  22.  
  23.    bordercolor(LIGHTBLUE,BLACK);
  24.    titlecolor(WHITE,RED);
  25.    if (mpresent) hide_mouse();
  26.    wnd = wframe(5, 5, 17, 75,YELLOW,BLACK);
  27.    wtitle(wnd, TOP,LEFT," Friendly Help ");
  28.    w_block_write(wnd,2,CENTER,helpmsg);
  29.    keyin();
  30.    wnd = wpop(wnd);
  31. }
  32.  
  33. void move_window(WNDPTR *window) {
  34.  
  35.    int  *wnd, wr, wc, key;
  36.    int  row, col, bstatus;
  37.  
  38.    wnd = (int *) window;
  39.    wr  = wnd[4]; wc = wnd[5];
  40.    for (;;) {
  41.      key = keyin();
  42.      if ( ischar ( key ) ) key = toupper( key );
  43.      switch( key ) {
  44.          case 'H' :
  45.          case F1  : help(); break;
  46.          case ESC : return;
  47.          case UPARROW :
  48.             wr -= 1;
  49.             if (mpresent) hide_mouse();
  50.             wndmove(window,wr,wc);
  51.             if (mpresent) show_mouse();
  52.             wr = wnd[4];
  53.             break;
  54.          case DOWNARROW :
  55.             wr += 1;
  56.             if (mpresent) hide_mouse();
  57.             wndmove(window,wr,wc);
  58.             if (mpresent) show_mouse();
  59.             wr = wnd[4];
  60.             break;
  61.          case LEFTARROW :
  62.             wc -= 1;
  63.             if (mpresent) hide_mouse();
  64.             wndmove(window,wr,wc);
  65.             if (mpresent) show_mouse();
  66.             wc = wnd[5];
  67.             break;
  68.          case RITEARROW :
  69.             wc += 1;
  70.             if (mpresent) hide_mouse();
  71.             wndmove(window,wr,wc);
  72.             if (mpresent) show_mouse();
  73.             wc = wnd[5];
  74.             break;
  75.          case LEFT_MOUSE_KEY :
  76.             get_mpos( &row, &col, &bstatus );
  77.             hide_mouse();
  78.             wndmove(window,row,col);
  79.             wr = wnd[4]; wc = wnd[5];
  80.             show_mouse();
  81.             break;
  82.          case RITE_MOUSE_KEY : return;
  83.          case BOTH_MOUSE_KEY : help();
  84.          default : break;
  85.      }
  86.   }
  87. }
  88.  
  89. int demo_c(void) {
  90.  
  91.    WNDPTR *mwnd, *wnd1, *wnd2;
  92.    int    selection, *wnd, wr, wc;
  93.  
  94.    static PMNUFLDS plist[] = {
  95.           { '1', "1. Move Window One Around"},
  96.           { '2', "2. Move Window Two Around"},
  97.           { '3', "3. Move the Menu Around  "},
  98.           { 'H', "H. Helpful Program Notes "},
  99.           { 'E', "E. End Demonstration.    "},
  100.           { 0, (char *) 0}
  101.    };
  102.  
  103.    static PMNUTYPE pmenu = {
  104.       NULL,
  105.       1,1,7,31,RED,LIGHTGRAY,
  106.       SINGLESIDES,BLACK,LIGHTGRAY,
  107.       " Moving Window Menu ", TOP, MIDDLE,BLUE,LIGHTGRAY,
  108.       WHITE,BLUE,0,
  109.       plist
  110.    };
  111.  
  112.    bordercolor(BLACK,LIGHTGRAY);
  113.    titlecolor(RED,LIGHTGRAY);
  114.    if ( mpresent ) hide_mouse();
  115.    wnd1 = wframe(1,33,7,53,BLUE,LIGHTGRAY);
  116.    wtitle(wnd1,TOP,MIDDLE," Window One ");
  117.    wnd2 = wframe(1,55,7,75,RED,LIGHTGRAY);
  118.    titlecolor(BLUE,LIGHTGRAY);
  119.    wtitle(wnd2,TOP,MIDDLE," Window Two ");
  120.  
  121.    mwnd = makepmenu(&pmenu);
  122.    wnd  = (int *) mwnd;
  123.    if ( mpresent ) show_mouse();
  124.    do {
  125.       if (mpresent) {
  126.          wr = wnd[4]; wc = wnd[5];
  127.          set_mpos(wr + 1, wc + 1);
  128.       }
  129.       selection = pmenuinput(&pmenu);
  130.       switch (selection) {
  131.          case '1' : move_window(wnd1); break;
  132.          case '2' : move_window(wnd2); break;
  133.          case '3' : move_window(mwnd); break;
  134.          case 'H' : help(); break;
  135.          default  : break;
  136.       }
  137.    } while (selection != 'E');
  138.    if ( mpresent ) hide_mouse();
  139.    mwnd = wpop ( mwnd );
  140.    wnd1 = wpop ( wnd1 );
  141.    wnd2 = wpop ( wnd2 );
  142.    if ( mpresent ) show_mouse();
  143.    return(0);
  144. }
  145.