home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / progwin / chap12 / linedda.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-11-12  |  3.4 KB  |  106 lines

  1. /*----------------------------------------
  2.    LINEDDA.C -- LineDDA Demonstration
  3.                 (c) Charles Petzold, 1990
  4.   ----------------------------------------*/
  5.  
  6. #include <windows.h>
  7.  
  8. long FAR PASCAL WndProc (HWND, WORD, WORD, LONG) ;
  9. void FAR PASCAL LineProc (short, short, LPSTR) ;
  10.  
  11. HANDLE hInst ;
  12.  
  13. int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance,
  14.                     LPSTR lpszCmdLine, int nCmdShow)
  15.      {
  16.      static char szAppName[] = "LineDDA" ;
  17.      HWND        hwnd ;
  18.      MSG         msg ;
  19.      WNDCLASS    wndclass ;
  20.  
  21.      if (!hPrevInstance) 
  22.           {
  23.           wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
  24.           wndclass.lpfnWndProc   = WndProc ;
  25.           wndclass.cbClsExtra    = 0 ;
  26.           wndclass.cbWndExtra    = 0 ;
  27.           wndclass.hInstance     = hInstance ;
  28.           wndclass.hIcon         = NULL ;
  29.           wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
  30.           wndclass.hbrBackground = GetStockObject (WHITE_BRUSH) ;
  31.           wndclass.lpszMenuName  = NULL ;
  32.           wndclass.lpszClassName = szAppName ;
  33.  
  34.           RegisterClass (&wndclass) ;
  35.           }
  36.  
  37.      hInst = hInstance ;
  38.  
  39.      hwnd = CreateWindow (szAppName, "LineDDA Demonstration",
  40.                           WS_OVERLAPPEDWINDOW,
  41.                           CW_USEDEFAULT, CW_USEDEFAULT,
  42.                           CW_USEDEFAULT, CW_USEDEFAULT,
  43.                           NULL, NULL, hInstance, NULL) ;
  44.  
  45.      ShowWindow (hwnd, nCmdShow) ;
  46.      UpdateWindow (hwnd) ;
  47.  
  48.      while (GetMessage (&msg, NULL, 0, 0))
  49.           {
  50.           TranslateMessage (&msg) ;
  51.           DispatchMessage (&msg) ;
  52.           }
  53.      return msg.wParam ;
  54.      }
  55.  
  56. long FAR PASCAL WndProc (HWND hwnd, WORD message, WORD wParam, LONG lParam)
  57.      {
  58.      static FARPROC lpfnLineProc ;
  59.      static short   cxClient, cyClient, xL, xR, yT, yB ;
  60.      HDC            hdc ;
  61.      PAINTSTRUCT    ps ;
  62.  
  63.      switch (message)
  64.           {
  65.           case WM_CREATE:
  66.                lpfnLineProc = MakeProcInstance (LineProc, hInst) ;
  67.                return 0 ;
  68.  
  69.           case WM_SIZE:
  70.                xR = 3 * (xL = (cxClient = LOWORD (lParam)) / 4) ;
  71.                yB = 3 * (yT = (cyClient = HIWORD (lParam)) / 4) ;
  72.                return 0 ;
  73.  
  74.           case WM_PAINT:
  75.                hdc = BeginPaint (hwnd, &ps) ;
  76.  
  77.                LineDDA (xL, yT, xR, yT, lpfnLineProc, (LPSTR) &hdc) ;
  78.                LineDDA (xR, yT, xR, yB, lpfnLineProc, (LPSTR) &hdc) ;
  79.                LineDDA (xR, yB, xL, yB, lpfnLineProc, (LPSTR) &hdc) ;
  80.                LineDDA (xL, yB, xL, yT, lpfnLineProc, (LPSTR) &hdc) ;
  81.  
  82.                LineDDA (0,       0,       xL, yT, lpfnLineProc, (LPSTR) &hdc) ;
  83.                LineDDA (cxClient, 0,       xR, yT, lpfnLineProc, (LPSTR) &hdc) ;
  84.                LineDDA (cxClient, cyClient, xR, yB, lpfnLineProc, (LPSTR) &hdc) ;
  85.                LineDDA (0,       cyClient, xL, yB, lpfnLineProc, (LPSTR) &hdc) ;
  86.  
  87.                EndPaint (hwnd, &ps) ;
  88.                return 0 ;
  89.  
  90.           case WM_DESTROY:
  91.                PostQuitMessage (0) ;
  92.                return 0 ;
  93.           }
  94.      return DefWindowProc (hwnd, message, wParam, lParam) ;
  95.      }
  96.  
  97. void FAR PASCAL LineProc (short x, short y, LPSTR lpData)
  98.      {
  99.      static short nCounter = 0 ;
  100.  
  101.      if (nCounter == 2)
  102.           Ellipse (* (HDC far *) lpData, x - 2, y - 2, x + 3, y + 3) ;
  103.  
  104.      nCounter = (nCounter + 1) % 4 ;
  105.      }
  106.