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

  1. '***********************************************************
  2. '* 
  3. '* Program Name: WinInput.BAS
  4. '*
  5. '* Include File: WinInput.BI
  6. '*
  7. '* Functions   :
  8. '*               WinSetFocus
  9. '*               WinFocusChange
  10. '*               WinSetCapture
  11. '*               WinQueryCapture
  12. '*               WinQueryFocus
  13. '*               WinGetKeyState
  14. '*               WinGetPhysKeyState
  15. '*               WinEnablePhysInput
  16. '*               WinIsPhysInputEnabled
  17. '*               WinSetKeyboardStateTable
  18. '*
  19. '* Description : This is a PM program to demonstrate the
  20. '*               various mouse and keyboard functions.
  21. '*               This also gives an example of using two of
  22. '*               the main messages associated with mouse and
  23. '*               keyboard input (WMCHAR and WMBUTTON1DBLCLK).
  24. '*               Return values for the functions are written
  25. '*               to the file, WinInput.OUT.
  26. '***********************************************************
  27.  
  28. '*********         Initialization section        ***********
  29.  
  30. REM $INCLUDE: 'PMBase.BI'
  31. REM $INCLUDE: 'WinInput.BI'
  32.  
  33. DIM aqmsg AS QMSG
  34.  
  35. flFrameFlags& =  FCFTITLEBAR      OR FCFSYSMENU OR _
  36.                  FCFSIZEBORDER    OR FCFMINMAX  OR _
  37.                  FCFSHELLPOSITION OR FCFTASKLIST
  38.  
  39. szClientClass$ = "ClassName" + CHR$(0)
  40.  
  41. hab&  = WinInitialize    (0)
  42. hmq&  = WinCreateMsgQueue(hab&, 0)
  43.  
  44. bool% = WinRegisterClass(_
  45.         hab&,_
  46.         MakeLong(VARSEG(szClientClass$), SADD(szClientClass$)),_
  47.         RegBas,_
  48.         0,_
  49.         0)
  50.  
  51. hwndFrame& = WinCreateStdWindow (_
  52.              HWNDDESKTOP,_
  53.              WSVISIBLE,_
  54.              MakeLong (VARSEG(flFrameFlags&),  VARPTR(flFrameFlags&)),_
  55.              MakeLong (VARSEG(szClientClass$), SADD(szClientClass$)),_
  56.              0,_
  57.              0,_
  58.              0,_
  59.              0,_
  60.              MakeLong (VARSEG(hwndClient&), VARPTR(hwndClient&)))
  61.  
  62. '*********                 Test  section                ***********
  63.  
  64. OPEN "WinInput.OUT" FOR OUTPUT AS #1
  65.  
  66. '*** Get original physical input state
  67.    Original% = WinIsPhysInputEnabled (HWNDDESKTOP)
  68.    PRINT #1, "WinIsPhysInputEnabled:", Original%
  69.  
  70. '*** Disable physical input
  71.    bool%     = WinEnablePhysInput    (HWNDDESKTOP, 0)
  72.    Disabled% = WinIsPhysInputEnabled (HWNDDESKTOP)
  73.    PRINT #1,  "WinEnablePhysInput(0):", Disabled%
  74.  
  75. '*** Re-enable physical input
  76.    bool%    = WinEnablePhysInput    (HWNDDESKTOP, 1)
  77.    Enabled% = WinIsPhysInputEnabled (HWNDDESKTOP)
  78.    PRINT #1, "WinEnablePhysInput(1):", Disabled%
  79.  
  80. '*** Set keyboard focus to client window
  81.    Focus% = WinSetFocus (HWNDDESKTOP, hwndClient&)
  82.    PRINT #1, "WinSetFocus:", Focus%
  83.  
  84. '*** Set mouse capture to desktop
  85.    Capture% = WinSetCapture (HWNDDESKTOP, HWNDDESKTOP)
  86.    PRINT #1, "WinSetCapture:", Capture%
  87.  
  88. '*** Get handle for keyboard focus (Client)
  89. '    NOTE: Second parameter allows locking the window
  90.    HFocus& = WinQueryFocus (HWNDDESKTOP, 0)
  91.    PRINT #1, "WinQueryFocus:", HEX$(HFocus&)
  92.  
  93. '*** Get handle for mouse capture (desktop)
  94. '    NOTE: Second parameter allows locking the window
  95.    HCapture& = WinQueryCapture (HWNDDESKTOP, 0)
  96.    PRINT #1, "WinQueryCapture:",  HEX$(HCapture&)
  97.  
  98. '*** Following section Gets the current keyboard state,
  99. '    sets the escape virtual key (no effect on phys),
  100. '    and simulates a WMCHAR message.  This will cause
  101. '    the WMCHAR message handler to print a value for
  102. '    the virtual key state and 0 for physical key state.
  103.    REM $DYNAMIC
  104.    DIM KeyArray(0 to 255) AS STRING * 1  'Array for key states
  105.  
  106. '*** Get key state table.  Last parameter determines get/set.
  107.    bool% = WinSetKeyboardStateTable (HWNDDESKTOP,_
  108.            MakeLong(VARSEG(KeyArray(0)), VARPTR(KeyArray(0))), 0)
  109.    PRINT #1, "WinSetKeyboardStateTable:", bool%
  110.  
  111.    KeyArray(VKESC) = CHR$(&H81)     'Escape is down and toggled
  112.  
  113. '*** Set key state table to simulate escape press.
  114.    bool% = WinSetKeyboardStateTable (HWNDDESKTOP,_
  115.            MakeLong(VARSEG(KeyArray(0)), VARPTR(KeyArray(0))), 1)
  116.    PRINT #1, "WinSetKeyboardStateTable:", bool%
  117.  
  118. '*** Send message to simulate WMCHAR event.
  119.    bool%= WinSendMsg (hwndClient&, WMCHAR, 0, 0)
  120.  
  121. '**************         Message loop         ***************
  122.  
  123. WHILE WinGetMsg(hab&, MakeLong(VARSEG(aqmsg), VARPTR(aqmsg)), 0, 0, 0)
  124.   bool% = WinDispatchMsg(hab&, MakeLong(VARSEG(aqmsg), VARPTR(aqmsg)))
  125. WEND
  126.  
  127. '***********         Finalize section        ***************
  128.  
  129. CLOSE #1
  130. bool% = WinDestroyWindow   (hwndFrame&)
  131. bool% = WinDestroyMsgQueue (hmq&)
  132. bool% = WinTerminate       (hab&)
  133.  
  134. END
  135.  
  136. '***********         Window procedure        ***************
  137.  
  138. FUNCTION ClientWndProc& (hwnd&, msg%, mp1&, mp2&) STATIC
  139.      DIM ClientRect AS RECTL
  140.      ClientWndProc& = 0
  141.      SELECT CASE msg%
  142.  
  143. '*** When a character message is received (from simulation or key
  144. '    press), display virtual and physical key states. These should
  145. '    essentially match except for the simulated case.
  146.      CASE WMCHAR
  147.     IF (mp1& AND KCKEYUP)=0 THEN
  148.           VKeyState% = WinGetKeyState    (HWNDDESKTOP, VKESC)
  149.       PKeyState% = WinGetPhysKeyState(HWNDDESKTOP, &H0001) 'Esc Scan=&H0001
  150.           PRINT #1, "WinGetKeyState: ",     VKeyState%,
  151.           PRINT #1, "WinGetPhysKeyState: ", PKeyState%,
  152.     END IF
  153.  
  154. '*** On a double-click, change the keyboard focus to allow closing
  155. '    with keys (Alt+F4).
  156.      CASE WMBUTTON1DBLCLK
  157.     bool% = WinFocusChange (HWNDDESKTOP, hwnd&, FCNOSETFOCUS)
  158.         PRINT #1, "WinSetFocus:", bool%
  159.      CASE WMPAINT     'Paint the window with background color
  160.         hps&  = WinBeginPaint(hwnd&, 0,_
  161.                 MakeLong(VARSEG(ClientRect), VARPTR(ClientRect)))
  162.         bool% = WinFillRect(hps&,_
  163.                 MakeLong(VARSEG(ClientRect), VARPTR(ClientRect)),0)
  164.         bool% = WinEndPaint(hps&)
  165.      CASE ELSE        'Pass control to system for other messages
  166.         ClientWndProc& = WinDefWindowProc(hwnd&, msg%, mp1&, mp2&)
  167.      END SELECT
  168. END FUNCTION
  169.