home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / easyx / data1.cab / Example_Files / EX_3 / Form1.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-11-03  |  4.6 KB  |  160 lines

  1. VERSION 5.00
  2. Object = "{5A65A9C0-089F-11D2-88AD-0000B45C4CF6}#1.2#0"; "EASYX.OCX"
  3. Begin VB.Form Form1 
  4.    Caption         =   "Form1"
  5.    ClientHeight    =   3195
  6.    ClientLeft      =   60
  7.    ClientTop       =   345
  8.    ClientWidth     =   4680
  9.    Icon            =   "Form1.frx":0000
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   3195
  12.    ScaleWidth      =   4680
  13.    StartUpPosition =   3  'Windows Default
  14.    Begin PROJECTEXLibCtl.EasyX EasyX 
  15.       Left            =   960
  16.       OleObjectBlob   =   "Form1.frx":014A
  17.       Top             =   120
  18.    End
  19. Attribute VB_Name = "Form1"
  20. Attribute VB_GlobalNameSpace = False
  21. Attribute VB_Creatable = False
  22. Attribute VB_PredeclaredId = True
  23. Attribute VB_Exposed = False
  24. Option Explicit
  25. Dim CursorSprite As Long
  26. Dim ButtonSprite(1) As Long
  27. Dim CursorSurface As Long
  28. Dim ButtonSurface As Long
  29. Const ButtonWidth As Long = 100
  30. Const ButtonHeight As Long = 50
  31. Const ButtonUpperX As Long = 150
  32. Const ButtonUpperY As Long = 120
  33. Const CursorWidth As Long = 25
  34. Const CursorHeight As Long = 25
  35. Private Sub RunMain()
  36. Static ButtonState As Long
  37. Static PointX As Long
  38. Static PointY As Long
  39. Dim rt As Long
  40. Dim X As Long, Y As Long, Button As Long
  41. Dim SpriteFrame As Long
  42. Dim Hit As Boolean
  43. Static WasClicked As Boolean
  44.     'reset values
  45.     X = 0
  46.     Y = 0
  47.     Button = 0
  48.     Hit = False
  49.     'Get the mouse positions
  50.     rt = EasyX.GetMouseState(X, Y, Button)
  51.     If rt = EX_DEVICENOTACQUIRED Then
  52.         EasyX.AcquireMouse
  53.     End If
  54.         
  55.     PointX = PointX + X
  56.     PointY = PointY + Y
  57.     'end on right click
  58.     If Button = EX_RIGHTBUTTON Then
  59.         EasyX.EndDirectX
  60.         Unload Me
  61.         Exit Do
  62.     End If
  63.     'Check the borders, so the mouse will stay on screen
  64.     If PointX < 0 Then
  65.         PointX = 0
  66.     ElseIf (PointX + CursorWidth) > 640 Then
  67.         PointX = 640 - CursorWidth
  68.     End If
  69.     If PointY < 0 Then
  70.         PointY = 0
  71.     ElseIf (PointY + CursorHeight) > 400 Then
  72.         PointY = 400 - CursorHeight
  73.     End If
  74.         
  75.     'check if the mouse is over the button
  76.     If (PointX + CursorWidth) > ButtonUpperX And PointX < (ButtonUpperX + ButtonWidth) _
  77.        And (PointY + CursorHeight) > ButtonUpperY And PointY < (ButtonUpperY + ButtonHeight) Then 'it
  78. s a hit
  79.         Hit = True
  80.         SpriteFrame = 1
  81.     Else
  82.         SpriteFrame = 0
  83.         WasClicked = False
  84.     End If
  85.         
  86.     'check for click
  87.     If Button <> ButtonState Then
  88.         ButtonState = Button
  89.         WasClicked = False
  90.     End If
  91.     'beep if hit and left button is clicked
  92.     If Hit And ButtonState = EX_LEFTBUTTON And (Not WasClicked) Then
  93.         Beep
  94.         WasClicked = True
  95.     End If
  96.     'Now draw it all
  97.     'fill the surfac first with black
  98.     EasyX.FillSurface 25, -1
  99.     'the button first
  100.     EasyX.DrawSprite ButtonUpperX, ButtonUpperY, ButtonWidth, ButtonHeight, ButtonSprite(SpriteFrame)
  101.     'the cursor
  102.     EasyX.DrawSprite PointX, PointY, CursorWidth, CursorHeight, CursorSprite
  103.     'flip it
  104.     EasyX.FlipSurface
  105.     DoEvents
  106. End Sub
  107. Private Sub Form_Load()
  108. Dim rt As Long
  109. Dim AppPath As String
  110. t forget this
  111. EasyX.Window = Me.hWnd
  112. '''''''''''''''''''''
  113. AppPath = App.Path & "\"
  114. 'Set the direct draw screen
  115. rt = EasyX.InitDirectDraw(640, 400, 8)
  116. If rt <> EX_OK Then 'it didn
  117. t work try an otheer mode
  118.     EasyX.EndDirectX
  119.     MsgBox "Direct draw could not initialize", vbOKOnly, "Failure"
  120.     Exit Sub
  121. End If
  122. 'Set the mouse
  123. rt = EasyX.InitDirectInput()
  124. If rt <> EX_OK Then
  125.     EasyX.EndDirectX
  126.     MsgBox "Direct input could not initialize", vbOKOnly, "Failure"
  127.     Exit Sub
  128. End If
  129. 'Create the mouse
  130. rt = EasyX.CreateMouse()
  131. If rt <> EX_OK Then
  132.     EasyX.EndDirectX
  133.     MsgBox "Mouse could not be created", vbOKOnly, "Failure"
  134.     Exit Sub
  135. End If
  136. 'acquire it
  137. EasyX.AcquireMouse
  138. CursorSurface = EasyX.LoadBitmapFile(AppPath & "cursor.bmp", 0)
  139. 'first surface so it must be 0
  140. If CursorSurface <> 0 Then
  141.     EasyX.EndDirectX
  142.     MsgBox "Graphics could not be loaded", vbOKOnly, "Failure"
  143.     Exit Sub
  144. End If
  145. ButtonSurface = EasyX.LoadBitmapFile(AppPath & "buttons.bmp", RGB(255, 255, 255))
  146. 'Second surface so it must be 1
  147. If ButtonSurface <> 1 Then
  148.     EasyX.EndDirectX
  149.     MsgBox "Graphics could not be loaded", vbOKOnly, "Failure"
  150.     Exit Sub
  151. End If
  152. 'make the sprites
  153. 'first the buttons
  154. ButtonSprite(0) = EasyX.MakeSprite(0, 0, 100, 50, ButtonSurface)
  155. ButtonSprite(1) = EasyX.MakeSprite(0, 50, 100, 100, ButtonSurface)
  156. 'and then the cursor
  157. CursorSprite = EasyX.MakeSprite(0, 0, 25, 25, CursorSurface)
  158. RunMain
  159. End Sub
  160.