home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 21 / CD_ASCQ_21_040595.iso / dos / prg / c / xlib612 / windemo / demo11.cpp < prev    next >
C/C++ Source or Header  |  1994-07-18  |  5KB  |  237 lines

  1. //Abnormal include files for an atypical Windows program... aCk!
  2. #include <windows.h>
  3. #include <mmsystem.h>
  4. #include <stdio.h>
  5.  
  6. extern "C"
  7. {
  8.     #include "wxlib.h"
  9.     #include "xcircle.h"
  10.     #include "xpal.h"
  11.     #include "xrect.h"
  12. }
  13.  
  14. #define A   asm
  15. #define A32 __emit__(0x67); asm
  16.  
  17. //This is the address of the screen selector.
  18. extern WORD _near _A000H;
  19.  
  20. //The undocumented Death() and Resurrection() Functions.  Oooo...
  21. extern "C"
  22. {
  23.     void FAR PASCAL Death(HDC dc);
  24.     void FAR PASCAL Resurrection(HDC dc, WORD w1, WORD w2, WORD w3, WORD w4, WORD w5, WORD w6);
  25. }
  26.  
  27. typedef void *Pvoid;
  28. typedef char *Pchar;
  29.  
  30. typedef struct
  31. {
  32.     int x, y;
  33.     int r;
  34.     int dx, dy;
  35.     int dr;
  36. } TPoint;
  37.  
  38. unsigned char bluepal[16*3] =
  39. {
  40.     0,  0,  4,
  41.     0,  0,  8,
  42.     0,  0, 12,
  43.     0,  0, 16,
  44.     0,  0, 20,
  45.     0,  0, 24,
  46.     0,  0, 28,
  47.     0,  0, 32,
  48.     0,  0, 36,
  49.     0,  0, 40,
  50.     0,  0, 44,    
  51.     0,  0, 48,    
  52.     0,  0, 52,    
  53.     0,  0, 56,    
  54.     0,  0, 60,
  55.     0,  0, 63
  56. };
  57.  
  58. TPoint cir[16];
  59. HWND hwnd;
  60.  
  61. //Check if a key is waiting in Windows message queue.
  62. int KeyHit()
  63. {
  64.     MSG msg;
  65.  
  66.     while (PeekMessage(&msg, hwnd, 0, 0x7FFF, PM_NOREMOVE))
  67.     {
  68.         if (msg.message == WM_KEYDOWN)
  69.             return TRUE;
  70.         GetMessage(&msg, hwnd, 0, 0x7FFF);
  71.     }
  72.     return FALSE;
  73. }
  74.  
  75. //Get a key from Windows message queue
  76. int GetChar()
  77. {
  78.     MSG msg;
  79.  
  80.     do
  81.     {
  82.         GetMessage(&msg, hwnd, 0, 0x7FFF);
  83.     } while (msg.message != WM_KEYDOWN);
  84.     return msg.wParam;
  85. }
  86.  
  87. //Kill the GDI, and initialize mode x.
  88. void gfxmode(WORD xmode, WORD width)
  89. {
  90.     ShowCursor(FALSE);
  91.     HDC dc = GetDC(NULL);
  92.     Death(dc);
  93.     ReleaseDC(NULL, dc);
  94.  
  95.     //This is in XLib, and we now set it to the correct selector
  96.     SCREEN_SEG = (WORD)&_A000H;
  97.  
  98.     x_set_mode(xmode, width);
  99. }
  100.  
  101. //Bring the GDI back to life!
  102. void winmode()
  103. {
  104.     x_text_mode();
  105.  
  106.     HDC dc = GetDC(NULL);
  107.     Resurrection(dc, 0, 0, 0, 0, 0, 0);
  108.     ReleaseDC(NULL, dc);
  109.     RedrawWindow(GetDesktopWindow(), NULL, NULL,
  110.         RDW_ERASE | RDW_FRAME | RDW_INVALIDATE |
  111.         RDW_ERASENOW | RDW_UPDATENOW | RDW_ALLCHILDREN);
  112.     ShowCursor(TRUE);
  113. }
  114.  
  115. //A generic memory allocation routine for Windows
  116. Pvoid AllocMem(DWORD size)
  117. {
  118.     HGLOBAL h = GlobalAlloc(GPTR, size);
  119.     GlobalFix(h);
  120.     GlobalPageLock(h);
  121.     return GlobalLock(h);
  122. }
  123.  
  124. //A generic memory deletion routine for Windows
  125. void FreeMem(Pvoid p)
  126. {
  127.     HGLOBAL h = (HGLOBAL)LOWORD(GlobalHandle(HIWORD((DWORD)p)));
  128.     GlobalUnlock(h);
  129.     GlobalPageUnlock(h);
  130.     GlobalUnfix(h);
  131.     GlobalFree(h);
  132. }
  133.  
  134. void RunIt()
  135. {
  136.     BOOL done = FALSE;
  137.     int ch;
  138.     int i;
  139.  
  140.     x_put_pal_raw(bluepal, 16, 16);
  141.  
  142.     cir[ 0].x = 120; cir[ 0].y =  60; cir[ 0].r = 20;
  143.     cir[ 1].x = 125; cir[ 1].y =  65; cir[ 1].r = 22;
  144.     cir[ 2].x = 130; cir[ 2].y =  70; cir[ 2].r = 24;
  145.     cir[ 3].x = 135; cir[ 3].y =  75; cir[ 3].r = 26;
  146.     cir[ 4].x = 140; cir[ 4].y =  80; cir[ 4].r = 28;
  147.     cir[ 5].x = 145; cir[ 5].y =  85; cir[ 5].r = 30;
  148.     cir[ 6].x = 150; cir[ 6].y =  90; cir[ 6].r = 32;
  149.     cir[ 7].x = 155; cir[ 7].y =  95; cir[ 7].r = 34;
  150.     cir[ 8].x = 160; cir[ 8].y = 100; cir[ 8].r = 36;
  151.     cir[ 9].x = 165; cir[ 9].y = 105; cir[ 9].r = 38;
  152.     cir[10].x = 170; cir[10].y = 110; cir[10].r = 40;
  153.     cir[11].x = 175; cir[11].y = 115; cir[11].r = 42;
  154.     cir[12].x = 180; cir[12].y = 120; cir[12].r = 44;
  155.     cir[13].x = 185; cir[13].y = 125; cir[13].r = 46;
  156.     cir[14].x = 190; cir[14].y = 130; cir[14].r = 48;
  157.     cir[15].x = 195; cir[15].y = 135; cir[15].r = 50;
  158.  
  159.     for (i = 0; i < 16; i++)
  160.     {
  161.         cir[i].dr = -1;
  162.         cir[i].dx = 1;
  163.         cir[i].dy = 1;
  164.     }
  165.  
  166.     sndPlaySound("BEAT.WAV", SND_ASYNC | SND_LOOP);
  167.  
  168.     while (!done)
  169.     {
  170.         if (KeyHit())
  171.         {
  172.             ch = GetChar();
  173.             switch (ch)
  174.             {
  175.                 case VK_LEFT: // left
  176.                 {
  177.                     break;
  178.                 }
  179.                 case VK_RIGHT: // right
  180.                 {
  181.                     break;
  182.                 }
  183.                 case VK_UP: // forward
  184.                 {
  185.                     break;
  186.                 }
  187.                 case VK_DOWN: // down
  188.                 {
  189.                     break;
  190.                 }
  191.                 case '\x1B':
  192.                 {
  193.                     done = TRUE;
  194.                     break;
  195.                 }
  196.             }
  197.         }
  198.         for (i = 0; i < 16; i++)
  199.         {
  200.             x_circle(cir[i].x, cir[i].y, cir[i].r, i+16, HiddenPageOffs);
  201.             cir[i].x += cir[i].dx;
  202.             cir[i].y += cir[i].dy;
  203.             cir[i].r += cir[i].dr;
  204.             if (cir[i].r > 50 || cir[i].r < 10)
  205.                 cir[i].dr = -cir[i].dr;
  206.             if (cir[i].x + 50 > 319 || cir[i].x - 50 < 1)
  207.                 cir[i].dx = -cir[i].dx;
  208.             if (cir[i].y + 50 > 199 || cir[i].y - 50 < 1)
  209.                 cir[i].dy = -cir[i].dy;
  210.         }
  211.         x_page_flip(0,0);
  212.         x_rect_fill(0, 0, 320, 240, HiddenPageOffs, 0);
  213.     }
  214.     sndPlaySound(NULL, NULL);
  215. }
  216.  
  217. int PASCAL WinMain(HANDLE, HANDLE, LPSTR, int)
  218. {
  219.     _InitEasyWin();
  220.     hwnd = GetFocus();
  221.  
  222.     //Kill GDI, initialize mode x.
  223.     gfxmode(X_MODE_320x240, 0);
  224.     x_set_doublebuffer(200);
  225.  
  226.     //Run the program's main loop
  227.     RunIt();
  228.  
  229.     DestroyWindow(hwnd);
  230.  
  231.     //Back to text mode.
  232.     winmode();
  233.  
  234.     return 0;
  235. }
  236.  
  237.