home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / window / c_winsrc / windemo.c < prev   
Encoding:
C/C++ Source or Header  |  1994-06-11  |  6.0 KB  |  223 lines

  1.  
  2. #include <stdlib.h>
  3. #include <stddef.h>
  4. #include <time.h>
  5. #include <conio.h>
  6. #include "win.h"
  7.  
  8.  
  9. static void Delay(nSeconds)
  10. short       nSeconds;
  11. {
  12.     auto     time_t    lQuitTime;
  13.  
  14.     time(&lQuitTime);
  15.     lQuitTime += (time_t) nSeconds;
  16.     while (time(NULL) < lQuitTime)
  17.     ;
  18.     return;
  19. }
  20.  
  21.  
  22.  
  23. static HWND IntroWindow()
  24. {
  25.     register HWND     hWnd;
  26.     auto     short     nTxtClr   = WHITE | REV_BLUE | HI_INTENSITY;
  27.     auto     short     nBriteClr = YELLOW | REV_BLUE | HI_INTENSITY;
  28.  
  29.     hWnd = WinCreateWindow(7, 10, 60, 10, nTxtClr,
  30.                SNGL_LINE_ALL_SIDES, nTxtClr, TRUE);
  31.     WinCenterText(hWnd, 1, "Welcome to C-WIN", nTxtClr);
  32.     WinCenterText(hWnd, 3, "a public domain contribution by", nTxtClr);
  33.     WinCenterText(hWnd, 5, "Bob Withers", nBriteClr);
  34.     WinCenterText(hWnd, 6, "649 Meadowbrook St", nBriteClr);
  35.     WinCenterText(hWnd, 7, "Allen, Texas 75002", nBriteClr);
  36.     Delay(5);
  37.     WinMoveWindow(hWnd, 1, 10);
  38.     return(hWnd);
  39. }
  40.  
  41.  
  42. static void DocWindow()
  43. {
  44.     register HWND     hWnd;
  45.     auto     short    nTxtClr = REV_WHITE | BLUE;
  46.  
  47.     hWnd = WinCreateWindow(9, 10, 60, 16, nTxtClr,
  48.                DBL_LINE_ALL_SIDES, nTxtClr, FALSE);
  49.     WinCenterText(hWnd, 1, "C-WIN Version 1.00", nTxtClr);
  50.     WinSetCursorPos(hWnd, 3, 2);
  51.     WinTextOut(hWnd,
  52.            "C-WIN is a collection of simple windowing routines for",
  53.            nTxtClr);
  54.     WinSetCursorPos(hWnd, 4, 2);
  55.     WinTextOut(hWnd,
  56.            "the IBM/PC and true clones. The package was written with",
  57.            nTxtClr);
  58.     WinSetCursorPos(hWnd, 5, 2);
  59.     WinTextOut(hWnd,
  60.            "the Microsoft C Compiler V5.00 and has been tested under",
  61.            nTxtClr);
  62.     WinSetCursorPos(hWnd, 6, 2);
  63.     WinTextOut(hWnd,
  64.            "the Turbo-C as well as Quick-C compilers. In the past I",
  65.            nTxtClr);
  66.     WinSetCursorPos(hWnd, 7, 2);
  67.     WinTextOut(hWnd,
  68.            "have developed several windowing packages for the PC but",
  69.            nTxtClr);
  70.     WinSetCursorPos(hWnd, 8, 2);
  71.     WinTextOut(hWnd,
  72.            "always in assembly language. I wanted a package written",
  73.            nTxtClr);
  74.     WinSetCursorPos(hWnd, 9, 2);
  75.     WinTextOut(hWnd,
  76.            "in C to allow it to easily be ported to other compilers.",
  77.            nTxtClr);
  78.     WinSetCursorPos(hWnd, 10, 2);
  79.     WinTextOut(hWnd,
  80.            "C-WIN is the result of my first efforts at this goal.",
  81.            nTxtClr);
  82.     WinSetCursorPos(hWnd, 11, 2);
  83.     WinTextOut(hWnd,
  84.            "I'm releasing it to the public domain in the hopes that",
  85.            nTxtClr);
  86.     WinSetCursorPos(hWnd, 12, 2);
  87.     WinTextOut(hWnd,
  88.            "others may find it a suitable base for their own work.",
  89.            nTxtClr);
  90.     WinCenterText(hWnd, 14, "* Press any key to continue *",
  91.            REV_RED | WHITE | HI_INTENSITY);
  92.     getch();
  93.     WinDestroyWindow(hWnd);
  94.     return;
  95. }
  96.  
  97.  
  98. static void ShowBorders()
  99. {
  100.     register short    i;
  101.     auto     short    nTxtClr = REV_WHITE | BLUE;
  102.     auto     HWND    hWnd[6];
  103.     static   char      *pText[] = {  "Windows can",
  104.                      "be drawn with",
  105.                      "various borders,",
  106.                      "or with",
  107.                      "no border",
  108.                      "at all!"
  109.                   };
  110.  
  111.     for (i = 0; i < 6; ++i)
  112.     {
  113.     hWnd[i] = WinCreateWindow(2 + i * 2, 2 + i * 2, 30, 6,
  114.                   nTxtClr, i,
  115.                   REV_WHITE | i | HI_INTENSITY, TRUE);
  116.     WinCenterText(hWnd[i], 1, pText[i], nTxtClr);
  117.     Delay(1);
  118.     }
  119.     Delay(5);
  120.     for (i = 5; i >= 0; --i)
  121.     {
  122.     WinMoveWindow(hWnd[i], 2 + (5 - i) * 2, 50 - (5 - i) * 2);
  123.     Delay(1);
  124.     }
  125.     Delay(5);
  126.     for (i = 0; i < 6; ++i)
  127.     WinMoveWindow(hWnd[i], 2 + i * 2, 1);
  128.     Delay(5);
  129.     for (i = 5; i >= 0; --i)
  130.     WinDestroyWindow(hWnd[i]);
  131.     return;
  132. }
  133.  
  134.  
  135. void HideShowWindow(hHideWnd)
  136. HWND        hHideWnd;
  137. {
  138.     auto     HWND    hWnd;
  139.     auto     short   nTxtClr = REV_MAGENTA | BLUE | HI_INTENSITY;
  140.  
  141.     hWnd = WinCreateWindow(1, 1, 30, 6, nTxtClr, NO_BOX, nTxtClr, FALSE);
  142.     WinCenterText(hWnd, 1, "Windows can be hidden", nTxtClr);
  143.     Delay(5);
  144.     WinHideWindow(hHideWnd);
  145.     WinCenterText(hWnd, 2, "Moved while hidden", nTxtClr);
  146.     Delay(2);
  147.     WinMoveWindow(hHideWnd, 7, 10);
  148.     WinCenterText(hWnd, 3, "and", nTxtClr);
  149.     WinCenterText(hWnd, 4, "re-shown at any time", nTxtClr);
  150.     Delay(5);
  151.     WinShowWindow(hHideWnd);
  152.     WinDestroyWindow(hWnd);
  153.     return;
  154. }
  155.  
  156.  
  157. void ScrollWindow(hWnd)
  158. register HWND     hWnd;
  159. {
  160.     auto     short     nRow, nCol;
  161.     auto     short     nWidth, nHeight;
  162.     auto     short     nWinClr;
  163.     auto     short     nNoRows;
  164.     auto     char     *pBuf;
  165.  
  166.     nRow    = WinGetWindowRow(hWnd);
  167.     nCol    = WinGetWindowCol(hWnd);
  168.     nWidth  = WinGetWindowWidth(hWnd);
  169.     nHeight = nNoRows = WinGetWindowHeight(hWnd);
  170.     nWinClr = WinGetWindowClr(hWnd);
  171.     if (WinGetBorderType(hWnd) != NO_WIND_BORDER)
  172.     {
  173.     nWidth    += 2;
  174.     nHeight += 2;
  175.     }
  176.     pBuf = malloc(ScrGetRectSize(nWidth, nHeight));
  177.     if (NULL == pBuf)
  178.     return;
  179.     ScrSaveRect(nRow, nCol, nWidth, nHeight, pBuf);
  180.     WinScrollWindowUp(hWnd);
  181.     WinScrollWindowUp(hWnd);
  182.     WinCenterText(hWnd, nNoRows, "Windows can be scrolled up", nWinClr);
  183.     Delay(2);
  184.     WinScrollWindowUp(hWnd);
  185.     Delay(2);
  186.     WinScrollWindowUp(hWnd);
  187.     Delay(2);
  188.     WinScrollWindowDown(hWnd);
  189.     WinScrollWindowDown(hWnd);
  190.     WinCenterText(hWnd, 1, "Windows can be scrolled down", nWinClr);
  191.     Delay(2);
  192.     WinScrollWindowDown(hWnd);
  193.     Delay(2);
  194.     WinScrollWindowDown(hWnd);
  195.     Delay(2);
  196.     ScrRestoreRect(nRow, nCol, nWidth, nHeight, pBuf);
  197.     free(pBuf);
  198.     WinCenterText(hWnd, nNoRows, " Press any key to end demo ",
  199.           REV_RED | WHITE | HI_INTENSITY);
  200.     return;
  201. }
  202.  
  203.  
  204. main()
  205. {
  206.     auto     HWND      hIntroWnd;
  207.  
  208.     WinInitialize();
  209.     ScrCursorOff();
  210.     WinClearScreen(NULL, BLACK);
  211.     hIntroWnd = IntroWindow();
  212.     DocWindow();
  213.     WinMoveWindow(hIntroWnd, 16, 10);
  214.     ShowBorders();
  215.     HideShowWindow(hIntroWnd);
  216.     ScrollWindow(hIntroWnd);
  217.     getch();
  218.     WinDestroyWindow(hIntroWnd);
  219.     WinTerminate();
  220.     ScrCursorOn();
  221.     return(0);
  222. }
  223.