home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l430 / 1.ddi / CHAP8.ZIP / RSIN.C < prev   
Encoding:
C/C++ Source or Header  |  1992-06-11  |  1.9 KB  |  79 lines

  1. /*
  2.     RSIN.C -- Demonstrates use of 3.0 functions RSin and RCos
  3.  
  4.     From Chapter 9 of "Undocumented Windows" (Addison-Wesley 1992)
  5.     by Andrew Schulman, Dave Maxey and Matt Pietrek
  6.  
  7.     Build using: WINIOBC RSIN (for Borland C++ v3.00)
  8.                  WINIOMS RSIN (for Microsoft C/SDK)
  9.     
  10.     NOTE: the above functions are only available in version 3.0
  11. */
  12.  
  13. #include <windows.h>
  14. #include "winio.h"
  15.  
  16. /* Undocumented functions */
  17. extern int FAR PASCAL RSin(int nRadius, int n10thDegrees);
  18. extern int FAR PASCAL RCos(int nRadius, int n10thDegrees);
  19.  
  20. #include "checkord.c"
  21.  
  22. BOOL DrawStar(HWND hwnd, HDC hDC, PAINTSTRUCT *pps, PWINIOINFO pwi)
  23.     {
  24.     RECT rectClient;
  25.     POINT middle;
  26.     int nRadius;
  27.     int d;
  28.     HPEN hPen, hPenOld;
  29.  
  30.     hPen = CreatePen(PS_SOLID, 1, RED);
  31.     
  32.     hPenOld = SelectObject(hDC, GetStockObject(BLACK_PEN));
  33.     
  34.     GetClientRect(hwnd, (LPRECT) &rectClient);
  35.     
  36.     middle.x = (rectClient.right - rectClient.left) / 2;
  37.     middle.y = (rectClient.bottom - (rectClient.top + pwi->dimChar.y)) / 2;
  38.     nRadius = min(middle.x, middle.y) - 2;
  39.     middle.x -= pwi->rectView.left * pwi->dimChar.x;
  40.     middle.y -= pwi->dimChar.y * pwi->rectView.top;
  41.  
  42.     for (d = 0; d < 90; d++)
  43.         {
  44.         MoveTo(hDC, middle.x, middle.y);
  45.         LineTo(hDC, middle.x + RSin(nRadius, d * 40),
  46.                     middle.y + RCos(nRadius, d * 40));
  47.         }
  48.     
  49.     SelectObject(hDC, hPenOld);
  50.     
  51.     DeleteObject(hPen);
  52.     
  53.     return TRUE;
  54.     }
  55.  
  56.  
  57. int main()
  58.     {
  59.     winio_about("RSIN"
  60.         "\nDemonstrates use of 3.0 functions RSin and RCos"
  61.         "\n\nFrom Chapter 9 of"
  62.         "\n\"Undocumented Windows\" (Addison-Wesley, 1992)"
  63.         "\nby Andrew Schulman, David Maxey and Matt Pietrek"
  64.         );
  65.     
  66.     if ((! CheckOrdName("RCos", "GDI", 177)) ||
  67.         (! CheckOrdName("RSin", "GDI", 178)))
  68.         return 1;
  69.     
  70.     winio_onpaintentry(__hMainWnd, (PAINT_FUNC) DrawStar);
  71.  
  72.     InvalidateRect(__hMainWnd, NULL, TRUE);
  73.     
  74.     printf("The star is drawn using RSin and RCos.");
  75.     
  76.     return 0;
  77.     }
  78.  
  79.