home *** CD-ROM | disk | FTP | other *** search
/ BUG 4 / BUGCD1997_05.BIN / aplic / clip4win / clip4win.exe / C4W30E.HUF / SOURCE / CMD / DRAW.PRG < prev    next >
Text File  |  1995-05-08  |  2KB  |  97 lines

  1. ////////////////////////////
  2. //
  3. //    draw.prg
  4. //
  5. //    Copyright (C) 1993 Skelton Software, Kendal Cottage, Hillam, Leeds, UK.
  6. //    All Rights Reserved.
  7. //
  8. //    Drawing program, using a window procedure.
  9. //
  10. //    Instructions:
  11. //        press left mouse button somewhere in the client area
  12. //        move around
  13. //        release button
  14. //
  15. //        (use system box or Alt-F4 to make program exit)
  16. //
  17. ////////////////////////////
  18.  
  19. #define    WIN_WANT_ALL
  20. #include "windows.ch"
  21. #include "msg.ch"
  22. #include "paint.ch"
  23. #include "topclass.ch"
  24. #define    NO_C4WCLASS
  25. #include "commands.ch"
  26.  
  27.  
  28. #define    MAXPOINTS    2000
  29. #define    MOUSE_LBUTTON    MK_LBUTTON    // from windows.ch
  30.  
  31.  
  32. static    aX[MAXPOINTS]
  33. static    aY[MAXPOINTS]
  34. static    nCount := 0
  35.  
  36.  
  37. function main()
  38. local    oApp, hWnd
  39.  
  40.  
  41. CREATE APPLICATION oApp  WINDOW hWnd  TITLE "Join the dots"        ;
  42.     CURSOR LoadCursor(0, IDC_CROSS)                    ;
  43.     ON WM_LBUTTONDOWN    OnLBtnDown()                ;
  44.     ON WM_LBUTTONUP        OnLBtnUp()                ;
  45.     ON WM_MOUSEMOVE        OnMouseMove()                ;
  46.     ON WM_PAINT        OnPaint()
  47.  
  48. return nil
  49.  
  50.  
  51. static function OnLBtnDown(hWnd, nMsg, nwParam, nlParam)
  52. // this is logically the 1st event we want to handle...
  53. nCount = 0
  54. InvalidateRect(hWnd)
  55. return 0    // 0 means we processed the msg
  56.  
  57.  
  58. static function OnMouseMove(hWnd, nMsg, nwParam, nlParam)
  59. local    hDC
  60. // ... but it would be faster to put this first
  61. //     (only matters on a _slow_ cpu) ...
  62. if C4W_And(nwParam, MOUSE_LBUTTON) != 0 .and. nCount < MAXPOINTS
  63.     nCount++
  64.     aX[nCount] = c4w_LoWord(nlParam)
  65.     aY[nCount] = c4w_HiWord(nlParam)
  66.  
  67.     // leave a trail of black dots
  68.     hDC = GetDC(hWnd)
  69.     SetPixel(hDC, aX[nCount], aY[nCount], RGB(0,0,0))
  70.     ReleaseDC(hWnd, hDC)
  71. endif
  72. return 0    // 0 means we processed the msg
  73.  
  74.  
  75. static function OnLBtnUp(hWnd, nMsg, nwParam, nlParam)
  76. // ... then this is the last of the sequence, before...
  77. InvalidateRect(hWnd)
  78. return 0    // 0 means we processed the msg
  79.  
  80.  
  81. static function OnPaint(hWnd, nMsg, nwParam, nlParam)
  82. local    aPaint[PS_LENGTH], hDC, i, j
  83.  
  84. // ... now we join the dots in many ways!
  85. hDC = BeginPaint(hWnd, aPaint)
  86.  
  87. for i = 1 to nCount - 1
  88.     for j = 1 to nCount
  89.         MoveTo(hDC, aX[i], aY[i])
  90.         LineTo(hDC, aX[j], aY[j])
  91.     next j
  92. next i
  93.  
  94. EndPaint(hWnd, aPaint)
  95. return 0    // 0 means we processed the msg
  96.  
  97.