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

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