home *** CD-ROM | disk | FTP | other *** search
/ Dan Appleman's Visual Bas…s Guide to the Win32 API / Dan.Applmans.Visual.Basic.5.0.Programmers.Guide.To.The.Win32.API.1997.Ziff-Davis.Press.CD / VB5PG32.mdf / vbpg32 / samples4 / ch06 / ex6a.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-11-20  |  12.7 KB  |  370 lines

  1. VERSION 4.00
  2. Begin VB.Form frmCh6 
  3.    Caption         =   "Ch.6 Extra Function Examples"
  4.    ClientHeight    =   3420
  5.    ClientLeft      =   2625
  6.    ClientTop       =   1680
  7.    ClientWidth     =   4575
  8.    Height          =   3825
  9.    Left            =   2565
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   228
  12.    ScaleMode       =   3  'Pixel
  13.    ScaleWidth      =   305
  14.    Top             =   1335
  15.    Width           =   4695
  16.    Begin VB.PictureBox picHolder 
  17.       Height          =   315
  18.       Index           =   2
  19.       Left            =   3240
  20.       Picture         =   "EX6A.frx":0000
  21.       ScaleHeight     =   285
  22.       ScaleWidth      =   405
  23.       TabIndex        =   16
  24.       Top             =   3060
  25.       Visible         =   0   'False
  26.       Width           =   435
  27.    End
  28.    Begin VB.PictureBox picHolder 
  29.       Height          =   315
  30.       Index           =   1
  31.       Left            =   2880
  32.       Picture         =   "EX6A.frx":0442
  33.       ScaleHeight     =   285
  34.       ScaleWidth      =   405
  35.       TabIndex        =   15
  36.       Top             =   3060
  37.       Visible         =   0   'False
  38.       Width           =   435
  39.    End
  40.    Begin VB.PictureBox picHolder 
  41.       Height          =   315
  42.       Index           =   0
  43.       Left            =   2580
  44.       Picture         =   "EX6A.frx":0884
  45.       ScaleHeight     =   285
  46.       ScaleWidth      =   405
  47.       TabIndex        =   14
  48.       Top             =   3060
  49.       Visible         =   0   'False
  50.       Width           =   435
  51.    End
  52.    Begin VB.Frame fraControlPanel 
  53.       Caption         =   "Control Panel:"
  54.       Height          =   1095
  55.       Left            =   60
  56.       TabIndex        =   7
  57.       Top             =   2100
  58.       Width           =   4395
  59.       Begin VB.HScrollBar scrDoubleClick 
  60.          Height          =   255
  61.          LargeChange     =   15
  62.          Left            =   840
  63.          Max             =   0
  64.          Min             =   -100
  65.          TabIndex        =   11
  66.          Top             =   480
  67.          Width           =   2415
  68.       End
  69.       Begin VB.PictureBox pctDoubleClick 
  70.          AutoSize        =   -1  'True
  71.          Height          =   510
  72.          Left            =   3360
  73.          Picture         =   "EX6A.frx":0CC6
  74.          ScaleHeight     =   480
  75.          ScaleWidth      =   480
  76.          TabIndex        =   10
  77.          Top             =   300
  78.          Width           =   510
  79.       End
  80.       Begin VB.Label lblDC1 
  81.          Caption         =   "Slow"
  82.          Height          =   195
  83.          Index           =   1
  84.          Left            =   840
  85.          TabIndex        =   13
  86.          Top             =   720
  87.          Width           =   375
  88.       End
  89.       Begin VB.Label lblDC1 
  90.          Caption         =   "Fast"
  91.          Height          =   195
  92.          Index           =   0
  93.          Left            =   2940
  94.          TabIndex        =   12
  95.          Top             =   720
  96.          Width           =   375
  97.       End
  98.       Begin VB.Label lblDoubleClick 
  99.          Caption         =   "0.75 ms"
  100.          Height          =   255
  101.          Left            =   180
  102.          TabIndex        =   9
  103.          Top             =   480
  104.          Width           =   615
  105.       End
  106.       Begin VB.Label Label1 
  107.          Caption         =   "Double Click Time:"
  108.          Height          =   195
  109.          Left            =   120
  110.          TabIndex        =   8
  111.          Top             =   240
  112.          Width           =   1515
  113.       End
  114.    End
  115.    Begin VB.Frame fraCursor 
  116.       Caption         =   "Cursor Options:"
  117.       Height          =   1935
  118.       Left            =   60
  119.       TabIndex        =   0
  120.       Top             =   60
  121.       Width           =   4395
  122.       Begin VB.PictureBox pctCursor 
  123.          ForeColor       =   &H000000FF&
  124.          Height          =   1575
  125.          Left            =   180
  126.          ScaleHeight     =   103
  127.          ScaleMode       =   3  'Pixel
  128.          ScaleWidth      =   155
  129.          TabIndex        =   4
  130.          Top             =   240
  131.          Width           =   2355
  132.          Begin VB.TextBox txtCaret 
  133.             Height          =   315
  134.             Left            =   60
  135.             TabIndex        =   5
  136.             Text            =   "Type in this text box"
  137.             Top             =   420
  138.             Width           =   2115
  139.          End
  140.          Begin VB.Label lblClipInfo 
  141.             Caption         =   "Click the picturebox to stop  cursor clipping."
  142.             Height          =   375
  143.             Left            =   60
  144.             TabIndex        =   6
  145.             Top             =   1080
  146.             Visible         =   0   'False
  147.             Width           =   2175
  148.          End
  149.       End
  150.       Begin VB.CommandButton cmdClip 
  151.          Caption         =   "&Clip Cursor"
  152.          Height          =   495
  153.          Left            =   2640
  154.          TabIndex        =   3
  155.          Top             =   1320
  156.          Width           =   1575
  157.       End
  158.       Begin VB.CommandButton cmdSetPos 
  159.          Caption         =   "Set Cursor &Position"
  160.          Height          =   495
  161.          Left            =   2640
  162.          TabIndex        =   2
  163.          Top             =   780
  164.          Width           =   1575
  165.       End
  166.       Begin VB.CommandButton cmdHide 
  167.          Caption         =   "&Hide Cursor"
  168.          Height          =   495
  169.          Left            =   2640
  170.          TabIndex        =   1
  171.          Top             =   240
  172.          Width           =   1575
  173.       End
  174.    End
  175. Attribute VB_Name = "frmCh6"
  176. Attribute VB_Creatable = False
  177. Attribute VB_Exposed = False
  178. Option Explicit
  179. Dim dl&, fCHidden&, fCClipped&, fTxtHidIt&
  180. '**********************************
  181. '**  Constant Definitions:
  182. #If Win32 Then
  183. Const EWX_LOGOFF = 0
  184. Const EWX_SHUTDOWN = 1
  185. Const EWX_REBOOT = 2
  186. Const EWX_FORCE = 4
  187. Const EWX_POWEROFF = 8
  188. Const VK_NUMLOCK = 90
  189. Const VK_SCROLL = 91
  190. Const VK_CAPITAL = 14
  191. Private Const VER_PLATFORM_WIN32_NT& = 2
  192. Private Const VER_PLATFORM_WIN32_WINDOWS& = 1
  193. Private Const SPIF_UPDATEINIFILE& = &H1
  194. Private Const SPIF_SENDWININICHANGE& = &H2
  195. #End If 'WIN32
  196. '**********************************
  197. '**  Type Definitions:
  198. #If Win32 Then
  199. Private Type POINTAPI
  200.     x As Long
  201.     Y As Long
  202. End Type
  203. Private Type RECT
  204.     Left As Long
  205.     Top As Long
  206.     Right As Long
  207.     Bottom As Long
  208. End Type
  209. 'Private Type SYSTEM_INFO
  210. '        dwOemID As Long
  211. '        dwPageSize As Long
  212. '        lpMinimumApplicationAddress As Long
  213. '        lpMaximumApplicationAddress As Long
  214. '        dwActiveProcessorMask As Long
  215. '        dwNumberOrfProcessors As Long
  216. '        dwProcessorType As Long
  217. '        dwAllocationGranularity As Long
  218. '        dwReserved As Long
  219. 'End Type
  220. Private Type SYSTEM_INFO
  221.         dwOemID As Long
  222.         dwPageSize As Long
  223.         lpMinimumApplicationAddress As Long
  224.         lpMaximumApplicationAddress As Long
  225.         dwActiveProcessorMask As Long
  226.         dwNumberOfProcessors As Long
  227.         dwProcessorType As Long
  228.         dwAllocationGranularity As Long
  229.         wProcessorLevel As Integer
  230.         wProcessorRevision As Integer
  231. End Type
  232. Private Type OSVERSIONINFO ' 148 bytes
  233.         dwOSVersionInfoSize As Long
  234.         dwMajorVersion As Long
  235.         dwMinorVersion As Long
  236.         dwBuildNumber As Long
  237.         dwPlatformId As Long
  238.         szCSDVersion As String * 128
  239. End Type
  240. #End If 'WIN32 Types
  241. '**********************************
  242. '**  Function Declarations:
  243. #If Win32 Then
  244. Private Declare Function ClientToScreen& Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI)
  245. Private Declare Function ClipCursor& Lib "user32" (lpRect As RECT)
  246. Private Declare Function ClipCursorBynum& Lib "user32" Alias "ClipCursor" (ByVal lpRect As Long)
  247. Private Declare Function apiBeep& Lib "kernel32" Alias "Beep" (ByVal dwFreq As Long, ByVal dwDuration As Long)
  248. Private Declare Function ExitWindowsEx& Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long)
  249. Private Declare Function GetComputerName& Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long)
  250. Private Declare Function GetDoubleClickTime& Lib "user32" ()
  251. Private Declare Function GetKeyboardState& Lib "user32" (pbKeyState As Byte)
  252. Private Declare Function GetKeyState% Lib "user32" (ByVal nVirtKey As Long)
  253. Private Declare Function GetVersionEx& Lib "kernel32" Alias "GetVersionExA" _
  254.                         (lpVersionInformation As OSVERSIONINFO)
  255. Private Declare Sub GetSystemInfo Lib "kernel32" (lpSystemInfo As SYSTEM_INFO)
  256. Private Declare Function SetCaretBlinkTime& Lib "user32" (ByVal wMSeconds As Long)
  257. Private Declare Function SetKeyboardState& Lib "user32" (lppbKeyState As Byte)
  258. Private Declare Function SetCursorPos& Lib "user32" (ByVal x As Long, ByVal Y As Long)
  259. Private Declare Function SetDoubleClickTime& Lib "user32" (ByVal wCount As Long)
  260. Private Declare Function ShowCursor& Lib "user32" (ByVal bShow As Long)
  261. Private Declare Function ShowCaret& Lib "user32" (ByVal hwnd As Long)
  262. Private Declare Function HideCaret& Lib "user32" (ByVal hwnd As Long)
  263. Private Declare Function SystemParametersInfo& Lib "user32" Alias "SystemParametersInfoA" _
  264.     (ByVal fAction As Long, ByVal uiParam As Long, ByVal pvParam As Long, ByVal fWinIni As Long)
  265. #End If 'WIN32
  266. Private Sub cmdClip_Click()
  267.     Dim myRect As RECT, myPoint As POINTAPI
  268.     Select Case fCClipped&
  269.         Case True:
  270.             dl& = ClipCursorBynum&(0)
  271.             cmdClip.Caption = "&Clip Cursor"
  272.             lblClipInfo.Visible = False
  273.             fCClipped& = False
  274.             pctCursor.Refresh
  275.         Case False:
  276.             cmdSetPos_Click
  277.             myPoint.x = 0
  278.             myPoint.Y = 0
  279.             dl& = ClientToScreen&(pctCursor.hwnd, myPoint)
  280.             myRect.Top = myPoint.Y
  281.             myRect.Left = myPoint.x
  282.             myRect.Right = myRect.Left + pctCursor.ScaleWidth
  283.             myRect.Bottom = myRect.Top + pctCursor.ScaleHeight
  284.             dl& = ClipCursor&(myRect)
  285.             cmdClip.Caption = "Un-&Clip Cursor"
  286.             lblClipInfo.Visible = True
  287.             fCClipped& = True
  288.             pctCursor.DrawWidth = 2
  289.             pctCursor.Line (1, 1)-(pctCursor.ScaleWidth - 1, pctCursor.ScaleHeight - 1), , B
  290.             pctCursor.DrawWidth = 1
  291.     End Select
  292. End Sub
  293. Private Sub cmdHide_Click()
  294.     If cmdHide.Caption = "&Hide Cursor" Then
  295.         cmdHide.Caption = "&Show Cursor"
  296.         fCHidden& = ShowCursor&(0)
  297.     Else
  298.         cmdHide.Caption = "&Hide Cursor"
  299.         fCHidden& = ShowCursor&(1)
  300.     End If
  301. End Sub
  302. Public Sub cmdSetPos_Click()
  303.     Dim myPoint As POINTAPI
  304.     myPoint.x = 12
  305.     myPoint.Y = 12
  306.     dl& = ClientToScreen&(pctCursor.hwnd, myPoint)
  307.     dl& = SetCursorPos&(myPoint.x, myPoint.Y)
  308. End Sub
  309. Private Sub Form_Load()
  310.     Dim x&
  311.     x& = GetDoubleClickTime&()
  312.     lblDoubleClick = x& & " ms"
  313.     scrDoubleClick.Value = x& / -10
  314. End Sub
  315. Private Sub lblClipInfo_Click()
  316.     pctCursor_Click
  317. End Sub
  318. Private Sub pctCursor_Click()
  319.     If fCClipped& = True Then
  320.         dl& = ClipCursorBynum&(0)
  321.         cmdClip.Caption = "&Clip Cursor"
  322.         fCClipped& = False
  323.         pctCursor.Refresh
  324.         lblClipInfo.Visible = False
  325.     End If
  326. End Sub
  327. Private Sub pctCursor_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single)
  328.     If fCHidden& = -1 And fTxtHidIt& Then 'Cursor is now hidden
  329.         fCHidden& = ShowCursor&(1)
  330.         fTxtHidIt& = False
  331.     End If
  332. End Sub
  333. Private Sub pctCursor_Paint()
  334.     pctCursor.Line (5, 5)-(20, 20)
  335.     pctCursor.Line (5, 20)-(20, 5)
  336.     If fCClipped& = True Then
  337.         With pctCursor
  338.             .DrawWidth = 2
  339.             pctCursor.Line (1, 1)-(.ScaleWidth - 1, .ScaleHeight - 1), , B
  340.             .DrawWidth = 1
  341.         End With
  342.     End If
  343. End Sub
  344. Private Sub pctDoubleClick_DblClick()
  345.     Static whichLight%
  346.     whichLight = whichLight + 1
  347.     If whichLight = 3 Then whichLight = 0
  348.     pctDoubleClick = picHolder(whichLight).Picture
  349. End Sub
  350. Private Sub scrDoubleClick_Change()
  351.     dl& = SetDoubleClickTime&(-1 * scrDoubleClick * 10)
  352.     lblDoubleClick = (-1 * scrDoubleClick * 10) & " ms"
  353. End Sub
  354. Private Sub scrDoubleClick_Scroll()
  355.     dl& = SetDoubleClickTime&(-1 * scrDoubleClick * 10)
  356.     lblDoubleClick = (-1 * scrDoubleClick * 10) & " ms"
  357. End Sub
  358. Private Sub txtCaret_KeyDown(KeyCode As Integer, Shift As Integer)
  359.     If fCHidden& = 0 Then 'Cursor is now shown
  360.         fTxtHidIt& = True
  361.         fCHidden& = ShowCursor&(0)
  362.     End If
  363. End Sub
  364. Private Sub txtCaret_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single)
  365.     If fCHidden& = -1 And fTxtHidIt& Then 'Cursor is now hidden
  366.         fCHidden& = ShowCursor&(1)
  367.         fTxtHidIt& = False
  368.     End If
  369. End Sub
  370.