home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / OS2BAS.ZIP / WINCURS.BAS < prev    next >
BASIC Source File  |  1989-08-27  |  4KB  |  124 lines

  1. '************************************************************************
  2. '* 
  3. '* Program Name: WinCurs.BAS
  4. '*
  5. '* Include File: WinMisc.BI
  6. '*
  7. '* Functions   :
  8. '*               WinCreateCursor
  9. '*               WinDestroyCursor
  10. '*               WinShowCursor
  11. '*               WinQueryCursorInfo
  12. '*
  13. '* Description : This is a PM program which demonstrates
  14. '*               the use of WinCreateCursor, WinShowCursor,
  15. '*               WinDestroyCursor and WinQueryCursorInfo. The
  16. '*               program displays a cursor in the current window
  17. '*               that is proportional to the window size in the
  18. '*               center of the window.  When the size of the window
  19. '*               is adjusted the cursor information is written to an
  20. '*               output file called "WinCurs.OUT".
  21. '*
  22. '************************************************************************
  23.  
  24. '*********         Initialization section        ***********
  25.  
  26. REM $INCLUDE: 'PMBase.BI'
  27. REM $INCLUDE: 'WinMisc.BI'
  28.  
  29. DIM aqmsg AS QMSG
  30.  
  31.  
  32. flFrameFlags& =  FCFTITLEBAR      OR FCFSYSMENU OR _
  33.                  FCFSIZEBORDER    OR FCFMINMAX  OR _
  34.                  FCFSHELLPOSITION OR FCFTASKLIST
  35.  
  36. szClientClass$ = "ClassName" + CHR$(0)
  37.  
  38. hab&  = WinInitialize    (0)
  39. hmq&  = WinCreateMsgQueue(hab&, 0)
  40.  
  41. bool% = WinRegisterClass(_
  42.         hab&,_
  43.         MakeLong(VARSEG(szClientClass$), SADD(szClientClass$)),_
  44.         RegBas,_
  45.         CSSIZEREDRAW,_
  46.         0)
  47.  
  48. hwndFrame& = WinCreateStdWindow (_
  49.              HWNDDESKTOP,_
  50.              WSVISIBLE,_
  51.              MakeLong (VARSEG(flFrameFlags&),  VARPTR(flFrameFlags&)),_
  52.              MakeLong (VARSEG(szClientClass$), SADD(szClientClass$)),_
  53.              0,_
  54.              0,_
  55.              0,_
  56.              0,_
  57.              MakeLong (VARSEG(hwndClient&), VARPTR(hwndClient&)))
  58.  
  59.  
  60.     OPEN "WinCurs.OUT" FOR OUTPUT AS #1
  61.  
  62. '**************         Message loop         ***************
  63.  
  64. WHILE WinGetMsg(hab&, MakeLong(VARSEG(aqmsg), VARPTR(aqmsg)), 0, 0, 0)
  65.   bool% = WinDispatchMsg(hab&, MakeLong(VARSEG(aqmsg), VARPTR(aqmsg)))
  66. WEND
  67.  
  68. '***********         Finalize section        ***************
  69.  
  70.     CLOSE #1
  71.  
  72.  
  73. bool% = WinDestroyWindow   (hwndFrame&)
  74. bool% = WinDestroyMsgQueue (hmq&)
  75. bool% = WinTerminate       (hab&)
  76.  
  77. END
  78.  
  79. '***********         Window procedure        ***************
  80.  
  81. FUNCTION ClientWndProc& (hwnd&, msg%, mp1&, mp2&) STATIC
  82.      DIM ClientRect AS RECTL
  83.      DIM Cursor AS CURSORINFO
  84.      ClientWndProc& = 0
  85.      SELECT CASE msg%
  86.      CASE WMPAINT     'Paint the window with background and place cursor
  87.         hps&  = WinBeginPaint(hwnd&, 0,_
  88.         MakeLong(VARSEG(ClientRect), VARPTR(ClientRect)))
  89.  
  90. '*** WinDestroyCursor destroys previous cursor before window is repainted
  91.  
  92.     bool% = WinDestroyCursor(hwnd&)
  93.  
  94.         bool% = WinFillRect(hps&,_
  95.         MakeLong(VARSEG(ClientRect), VARPTR(ClientRect)),0)
  96.  
  97. '*** Compute center of window and make size proprotional to window size
  98.  
  99.         x&  = (ClientRect.xLeft + ClientRect.xRight) / 2   'Center
  100.         y&  = (ClientRect.yBottom + ClientRect.yTop) / 2
  101.     cx& = x& / 10                       'Proportional
  102.     cy& = y& / 10
  103.  
  104. '*** Create and Show cursor
  105.  
  106.         bool% = WinCreateCursor(hwnd&, x&, y&, cx&, cy&,CURSORFLASH,0)
  107.     bool% = WinShowCursor(hwnd&,1)
  108.  
  109. '*** Get cursor info and print to file
  110.  
  111.     bool% = WinQueryCursorInfo(HWNDDESKTOP,_
  112.                 MakeLong(VARSEG(cursor),VARPTR(cursor)))
  113.     print #1,"Position: (";cursor.x;",";cursor.y;")"
  114.     print #1,"Size: (";cursor.cx;",";cursor.cy;")"
  115.     print #1,"Flags:";HEX$(cursor.fs)
  116.     print #1,"-----------------------------"
  117.  
  118.         bool% = WinEndPaint(hps&)
  119.  
  120.      CASE ELSE          'Pass control to system for other messages
  121.         ClientWndProc& = WinDefWindowProc(hwnd&, msg%, mp1&, mp2&)
  122.      END SELECT
  123. END FUNCTION
  124.