home *** CD-ROM | disk | FTP | other *** search
/ BUG 4 / BUGCD1997_05.BIN / aplic / clip4win / clip4win.exe / C4W30E.HUF / SOURCE / CONTRIB / SPIN.ZIP / SPIN.PRG < prev   
Text File  |  1993-05-30  |  6KB  |  180 lines

  1.  
  2. // Spinning Cursor - 06/30/93 - Hugh A. Lokey
  3. // Having used FoxBase on the Mac I was impressed by the spinning
  4. // ball cursor when something was going on.  So I decided to see
  5. // if it could be done with Clip4Win.  When the computer/your
  6. // program is doing something that might take a little time it is
  7. // nice to give the user some visual clue that the computer is
  8. // actually working and not "hung up".  While the Windows hourglass
  9. // cursor does do this it is not really enough in my lowly opinion!
  10.  
  11. // To use these routines you will need to have a copy of the
  12. // Microsoft Resource Compiler (RC.EXE) to add the cursors to
  13. // your exe file.
  14.  
  15. // Since Windows uses co-operative multi-tasking you will have to
  16. // call SpinBall() to make the cursor change/spin.  I toyed around
  17. // with using a timer and checking for EVENT_TIMER but the code
  18. // overhead was much higher.
  19.  
  20. // Example of usage:
  21. //
  22. // LoadBalls() // Only needs to be called once at the start of your
  23. // program.
  24.  
  25. // Working(.T.,"Starting message to let user know what is going on...")
  26. // SELECT FOO
  27. // GO TOP
  28. // DO WHILE !EOF()
  29. //    SpinBall()
  30. //    DO SOMETHING HERE
  31. //    SKIP
  32. // ENDDO
  33. // Working(.F.)
  34. //
  35. // DestroyBalls() // Call upon exit from your program to free up
  36. // system resources..
  37.  
  38. // Depending on what you are doing and the speed of the machine being
  39. // used you can include an optional delay in the call to SpinBall().
  40. // This delay should be in hundreds of seconds.  You will know if
  41. // you need a delay when the "ball" spins so fast that it strobes and
  42. // appears to spin backwards!
  43.  
  44.  
  45. // Declare statics to hold handles to ball cursors
  46.  
  47. STATIC HBALL1,HBALL2,HBALL3,HBALL4
  48.  
  49. FUNCTION LoadBalls
  50.  
  51.          HBALL1   := LoadCursor(hInst,"BALL1"+CHR(0))
  52.          HBALL2   := LoadCursor(hInst,"BALL2"+CHR(0))
  53.          HBALL3   := LoadCursor(hInst,"BALL3"+CHR(0))
  54.          HBALL4   := LoadCursor(hInst,"BALL4"+CHR(0))
  55. RETURN(NIL)
  56.  
  57. FUNCTION DestroyBalls
  58.  
  59.          DestroyCursor(HBALL1)
  60.          DestroyCursor(HBALL2)
  61.          DestroyCursor(HBALL3)
  62.          DestroyCursor(HBALL4)
  63. RETURN(NIL)
  64.  
  65. FUNCTION Working(lOnOff,cText,cMsg)
  66.          STATIC hOldCur, hOldWnd, cOldMsg
  67.  
  68.          IF lOnOff == .T.
  69.             IF cMsg != NIL
  70.                cOldMsg := cMsg
  71.             ENDIF
  72.             hOldWnd := _LasthWnd()
  73.             hOldCur := SetCursor(HBALL1)
  74.             IF cText != NIL
  75.                Message(hOldWnd,cText)
  76.             ENDIF
  77.          ELSE
  78.             SelectWindow(hOldWnd)
  79.             SetCursor(hOldcur)
  80.             IF cOldMsg != NIL
  81.                Message(hOldWnd,cOldMsg)
  82.             ENDIF
  83.          ENDIF
  84. RETURN(NIL)
  85.  
  86. FUNCTION SpinBall(nDelay)
  87.          STATIC nBall := 1
  88.  
  89.          IF nDelay != NIL
  90.             Delay(nDelay)
  91.          ENDIF
  92.          DO CASE
  93.             CASE nBall == 1
  94.                  SetCursor(HBALL2)
  95.                  nBall := 2
  96.             CASE nBall == 2
  97.                  SetCursor(HBALL3)
  98.                  nBall := 3
  99.             CASE nBall == 3
  100.                  SetCursor(HBALL4)
  101.                  nBall := 4
  102.             CASE nBall == 4
  103.                  SetCursor(HBALL1)
  104.                  nBall := 1
  105.          ENDCASE
  106. RETURN(.T.)
  107.  
  108. // Not a very good delay function - depends on speed of machine as
  109. // to actual delay.  If anyone has a GOOD delay function I would
  110. // very much like a copy!!!!
  111.  
  112. STATIC FUNCTION Delay(nDelay)
  113.  
  114.        DO WHILE (SECONDS()+(nDelay/100)) < SECONDS()
  115.        ENDDO
  116. RETURN(NIL)
  117.  
  118. // Delete these if you have already downloaded them....
  119.  
  120. // Display a message in a sunken message bar at the bottom of a window
  121.  
  122. FUNCTION Message(hWnd,cText)
  123.          LOCAL nLeft, nTop, nRight, nBottom, aCRect, hDC
  124.          LOCAL nOldBkClor
  125.  
  126.          aCRect  := GetClientRect(hWnd)
  127.          nLeft   := 0
  128.          nTop    := aCRect[4]-26
  129.          nRight  := aCRect[3]
  130.          nBottom := nTop+28
  131.  
  132.          hDC        := GetDC(hWnd)
  133.          nOldBkClor := SetBkColor(hDC,RGB(192,192,192))
  134.          MsgBar(hWnd)
  135.          DrawText(hDC,cText,;
  136.                      {nLeft+20,nTop+5,nRight-11,nBottom-5},DT_LEFT)
  137.          SetBkColor(hDC,nOldBkClor)
  138.          ReleaseDC(hWnd,hDC)
  139. RETURN(NIL)
  140.  
  141. // Called by Message() to draw a sunken bar at the bottom of a window
  142. // Can be called directly to just draw the bar.
  143.  
  144. FUNCTION MsgBar(hWnd)
  145.          LOCAL nLeft, nTop, nRight, nBottom, aCRect, hOldPen
  146.          LOCAL hDC, hColor, hBlackPen, hGreyPen, hWhitePen
  147.  
  148.          hDc     := GetDC(hWnd)
  149.          aCRect  := GetClientRect(hWnd)
  150.          nLeft   := 0
  151.          nTop    := aCRect[4]-26
  152.          nRight  := aCRect[3]
  153.          nBottom := nTop+26
  154.  
  155.          hBlackPen := CreatePen(PS_SOLID,1,RGB(0,0,0))
  156.          hGreyPen  := CreatePen(PS_SOLID,1,RGB(128,128,128))
  157.          hWhitePen := CreatePen(PS_SOLID,1,RGB(255,255,255))
  158.  
  159.          hOldPen   := SelectObject(hDC,hBlackPen)
  160.          Rectangle(hDC,nLeft,nTop,nRight,nBottom)
  161.          hColor := CreateSolidBrush(RGB(192,192,192))
  162.          FillRect(hDC,nLeft,nTop+1,nRight,nBottom,hColor)
  163.  
  164.          SelectObject(hDC,hGreyPen)
  165.          MoveTo(hDC,nLeft+10,nBottom-4)
  166.          LineTo(hDC,nLeft+10,nTop+4)
  167.          LineTo(hDC,nRight-10,nTop+4)
  168.  
  169.          SelectObject(hDC,hWhitePen)
  170.          LineTo(hDC,nRight-10,nBottom-4)
  171.          LineTo(hDC,nLeft+10,nBottom-4)
  172.  
  173.          SelectObject(hDC,hOldPen)
  174.          ReleaseDC(hWnd,hDC)
  175.          DeleteObject(hColor)
  176.          DeleteObject(hBlackPen)
  177.          DeleteObject(hGreyPen)
  178.          DeleteObject(hWhitePen)
  179. RETURN(NIL)
  180.