home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 March / VPR9703A.ISO / MS_DEV / VBCCE / SAMPLES / AxGrafix / AXGrafix.EXE / RCDATA / CABINET / AXGrafix.ctl < prev    next >
Text File  |  1996-10-25  |  17KB  |  657 lines

  1. VERSION 5.00
  2. Begin VB.UserControl AXGraphic 
  3.    Appearance      =   0  'Flat
  4.    BackColor       =   &H80000004&
  5.    BorderStyle     =   1  'Fixed Single
  6.    CanGetFocus     =   0   'False
  7.    ClientHeight    =   870
  8.    ClientLeft      =   0
  9.    ClientTop       =   0
  10.    ClientWidth     =   5325
  11.    ClipControls    =   0   'False
  12.    PropertyPages   =   "AXGrafix.ctx":0000
  13.    ScaleHeight     =   58
  14.    ScaleMode       =   3  'Pixel
  15.    ScaleWidth      =   355
  16. End
  17. Attribute VB_Name = "AXGraphic"
  18. Attribute VB_GlobalNameSpace = False
  19. Attribute VB_Creatable = True
  20. Attribute VB_PredeclaredId = False
  21. Attribute VB_Exposed = True
  22. Option Explicit
  23.  
  24. Dim m_pPct As StdPicture        'Holds a refernce in memory to the original copy
  25.                                 'of the image
  26.  
  27. Dim m_bFlagOn As Byte           'Generally used as a state machine to determine
  28.                                 'which methods to trigger based on the client's
  29.                                 'selection of properties.
  30.  
  31. Dim m_strURL As String          'This string holds a URL reference to the displayed
  32.                                 'picture if the URLPicture property is set
  33.  
  34. Dim m_DVal As Long              'Identifies the number of milliseconds to delay
  35.                                 'between iterations
  36.                                 
  37. Dim m_iIterate As Integer       'Identifies the number of iterations to process
  38.                                 'the image with
  39.  
  40. Dim m_iRESWAV As Integer        'Identifies the wave to play from the res file
  41. Dim m_iType As Integer          'Identifies the image process type
  42. Dim m_iDir As Integer           'Used to specify the direction the control
  43.                                 'should scroll
  44.                                 
  45. Dim m_ROP1 As Long              'Used to specify the Raster Option used
  46. Dim m_ROP2 As Long              'scrolling
  47.  
  48. Dim ClearURLOnly As Boolean     'Used to coordinate between setting the picture as
  49. Dim ClearPictureOnly As Boolean 'a URL or standard picture
  50.  
  51. 'These Enums are read by the client to determine which values to put in the VB
  52. 'property window list boxes
  53. Public Enum FXType
  54.   FX_SCROLL
  55.   FX_SLATS
  56.   FX_RNDSQUARE
  57.   FX_NONE
  58. End Enum
  59.  
  60. Public Enum Direction
  61.   DIR_RIGHT
  62.   DIR_LEFT
  63.   DIR_UP
  64.   DIR_DOWN
  65. End Enum
  66.  
  67. Public Enum RasterType
  68.   RO_NORMAL
  69.   RO_INVERT
  70.   RO_COMBINE
  71. End Enum
  72.  
  73. Public Enum RESWAVE
  74.   W_BLIP = 1
  75.   W_CLICK = 2
  76.   W_WHOOSH = 3
  77.   W_MIX1 = 4
  78. End Enum
  79.  
  80. 'For sound index property validation
  81. Private Const MAX_SND = 8
  82. Private Const MIN_SND = 1
  83.  
  84. 'Used to set m_bFlagOn for custom properties
  85. Private Const GO_SND As Byte = &H2
  86.  
  87. Private Const ERR_INVALID = 100
  88.  
  89. Public Event Click()
  90.  
  91. Private Sub UserControl_Initialize()
  92.  
  93. 'Hardcoded presets for selected custom properties
  94. m_DVal = 50
  95. m_iIterate = 1
  96. m_bFlagOn = (m_bFlagOn Or GO_SND)
  97. m_iRESWAV = 1
  98.  
  99. End Sub
  100.  
  101. Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
  102. 'make sure these properties persist between run, design, and control copy
  103. Dim URL As String
  104. Dim Pic As StdPicture
  105.  
  106. On Error GoTo RP_ERROR
  107. With PropBag
  108.     
  109.     BackColor = .ReadProperty("BackColor", UserControl.BackColor)
  110.     BorderStyle = .ReadProperty("BorderStyle", UserControl.BorderStyle)
  111.     EnableSound = .ReadProperty("EnableSound", False)
  112.     DelayValue = .ReadProperty("DelayValue", 50)
  113.     Iterations = .ReadProperty("Iterations", 5)
  114.     ProcessType = .ReadProperty("ProcessType", 1)
  115.     ScrollDirection = .ReadProperty("ScrollDirection", 1)
  116.     ScrollROP1 = .ReadProperty("ScrollROP1", m_ROP1)
  117.     ScrollROP2 = .ReadProperty("ScrollROP2", m_ROP2)
  118.     SoundIndex = .ReadProperty("SoundIndex", m_iRESWAV)
  119.     
  120.     'This code is used from the AXButton Sample to implement the control's
  121.     'picture as either a standard picture or a URL reference to a standard picture
  122.     URLPicture = .ReadProperty("URLPicture", m_strURL)
  123.     URL = .ReadProperty("URLPicture", "")       ' Read URLPicture property value
  124.     If (URL <> "") Then                         ' If a URL has been entered...
  125.         URLPicture = URL                        ' Attempt to download it now, URL may be unabailable at this time
  126.     Else
  127.         Set Pic = .ReadProperty("Picture", Nothing) ' Read Picture property value
  128.         If Not (Pic Is Nothing) Then            ' URL is not available
  129.             Set Picture = Pic                   ' Use existing picture (This is used only if URL is empty)
  130.         End If
  131.     End If
  132.     
  133. End With
  134.  
  135. RP_ERROR:
  136. Resume Next
  137. 'Silent failure
  138.  
  139. End Sub
  140.  
  141. Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
  142. 'Make sure these properties persist between run, design, and control copy
  143.  
  144. On Error GoTo WP_ERROR
  145. With PropBag
  146.     .WriteProperty "BackColor", UserControl.BackColor
  147.     .WriteProperty "BorderStyle", UserControl.BorderStyle
  148.     .WriteProperty "EnableSound", EnableSound, False
  149.     .WriteProperty "DelayValue", 50
  150.     .WriteProperty "Iterations", m_iIterate
  151.     .WriteProperty "Picture", m_pPct, False
  152.     .WriteProperty "ProcessType", m_iType, 1
  153.     .WriteProperty "ScrollDirection", m_iDir, 1
  154.     .WriteProperty "ScrollROP1", ScrollROP1, vbSrcCopy
  155.     .WriteProperty "ScrollROP2", ScrollROP2, vbNotSrcCopy
  156.     .WriteProperty "SoundIndex", m_iRESWAV, 1
  157.     .WriteProperty "URLPicture", m_strURL, ""
  158. End With
  159.  
  160. WP_ERROR:
  161. Resume Next
  162. 'Silent Failure
  163.  
  164. End Sub
  165.  
  166. Private Sub RndSquares()
  167.  
  168. Dim xBuff As Single
  169. Dim yBuff As Single
  170. Dim ScaledW As Single
  171. Dim ScaledH As Single
  172. Dim iScale As Integer
  173. Dim iNumBlock As Integer
  174. Dim sPercent As Single
  175. Dim pPct As StdPicture
  176.  
  177. Dim lOPCode As Long
  178.  
  179. lOPCode = vbSrcInvert
  180.  
  181.   Set pPct = UserControl.Image
  182.   For iNumBlock = 2 To 4
  183.     DoEvents
  184.     For iScale = iNumBlock To 1 Step -1
  185.       sPercent = iScale / iNumBlock
  186.       ScaledW = UserControl.ScaleWidth * sPercent
  187.       ScaledH = UserControl.ScaleHeight * sPercent
  188.       xBuff = (UserControl.ScaleWidth - ScaledW - 1 + 1) * Rnd + 1
  189.       yBuff = (UserControl.ScaleHeight - ScaledH - 1 + 1) * Rnd + 1
  190.       PaintPicture pPct, xBuff, yBuff, ScaledW, ScaledH, 0, 0, ScaledW, _
  191.       ScaledH, lOPCode
  192.       DoEvents
  193.       Delay m_DVal
  194.       If lOPCode = vbSrcCopy Then
  195.         lOPCode = vbNotSrcCopy
  196.       Else
  197.         lOPCode = vbSrcCopy
  198.       End If
  199.     Next
  200.   Next
  201.  
  202. Set pPct = Nothing
  203.  
  204. End Sub
  205.  
  206. Private Sub Scroll(iDirection As Integer, OP1 As Long, OP2 As Long)
  207.  
  208. Dim iPos As Long, iStep As Long, w As Long, h As Long
  209. Dim w2 As Long, h2 As Long
  210.  
  211. Dim pPct As StdPicture
  212.     
  213.     With UserControl
  214.       w = .ScaleWidth
  215.       h = .ScaleHeight
  216.       iStep = w / 10
  217.       Set pPct = UserControl.Image
  218.         Select Case iDirection
  219.           Case DIR_RIGHT
  220.             For iPos = iStep To w - iStep Step iStep
  221.                 .PaintPicture pPct, 0, 0, iPos, h, w - iPos, 0, iPos, h, OP1
  222.                 .PaintPicture pPct, iPos, 0, w - iPos, h, 0, 0, w - iPos, h, OP2
  223.                 DoEvents
  224.                 Delay m_DVal
  225.             Next
  226.           Case DIR_LEFT
  227.             For iPos = iStep To w - iStep Step iStep
  228.                 w2 = w - iPos
  229.                 .PaintPicture pPct, w2, 0, iPos, h, 0, 0, iPos, h, OP1
  230.                 .PaintPicture pPct, 0, 0, w2, h, iPos, 0, w2, h, OP2
  231.                 DoEvents
  232.                 Delay m_DVal
  233.             Next
  234.           Case DIR_DOWN
  235.             For iPos = iStep To h - iStep Step iStep
  236.                 .PaintPicture pPct, 0, 0, w, iPos, 0, h - iPos, w, iPos, OP1
  237.                 .PaintPicture pPct, 0, iPos, w, h - iPos, 0, 0, w, h - iPos, OP2
  238.                 DoEvents
  239.                 Delay m_DVal
  240.             Next
  241.           Case DIR_UP
  242.             For iPos = iStep To h - iStep Step iStep
  243.                 h2 = h - iPos
  244.                 .PaintPicture pPct, 0, h2, w, iPos, 0, 0, w, iPos, OP1
  245.                 .PaintPicture pPct, 0, 0, w, h2, 0, iPos, w, h2, OP2
  246.                 DoEvents
  247.                 Delay m_DVal
  248.             Next
  249.         End Select
  250.     End With
  251.   
  252.   Set pPct = Nothing
  253.  
  254. End Sub
  255.  
  256. Private Sub HorizSlats()
  257.  
  258. Dim pPct As StdPicture
  259. Dim lRet As Long
  260. Dim SlatHeight As Single
  261. Dim Slats As Single
  262. Dim lStep As Single
  263. Dim Px As Single
  264. Dim Py As Single
  265. Dim sSlatCnt As Single
  266. Dim sPosCnt As Single
  267.  
  268. With UserControl
  269.   Set pPct = .Image
  270.   Slats = 10
  271.   lStep = CLng(.ScaleHeight / 50)
  272.   SlatHeight = .ScaleHeight / Slats
  273.   Px = .ScaleWidth
  274.   
  275.   .PaintPicture pPct, 0, 0, Px, .ScaleHeight, 0, 0, Px, .ScaleHeight, vbBlackness
  276.   
  277.   For sSlatCnt = lStep To SlatHeight + lStep Step lStep
  278.     For sPosCnt = 0 To Slats - 1
  279.         Py = SlatHeight * sPosCnt
  280.         .PaintPicture pPct, 0, Py, Px, sSlatCnt, 0, Py, Px, sSlatCnt, vbSrcCopy
  281.         Delay m_DVal
  282.     Next
  283.   Next
  284. End With
  285.  
  286. 'Clean up a bit
  287. Set pPct = Nothing
  288.  
  289. End Sub
  290.  
  291. Private Sub StretchInit()
  292.  
  293. Dim Bmp As BITMAP
  294. Dim lRet As Long
  295. Dim pDc As Long
  296.  
  297. 'IMPORTANT!!! This allows the loaded picture to be persistant
  298. AutoRedraw = True
  299.  
  300. UserControl.Cls
  301.  
  302. 'Create a valid hdc to load the picture into temporarily
  303. pDc = CreateCompatibleDC(UserControl.hdc)
  304.  
  305. 'SelectObject uses pPct's handle to make m_lPict the active picture for the hdc
  306. lRet = SelectObject(pDc, m_pPct.Handle)
  307.  
  308. 'We are going to need the picture's boundaries for StretchBlt
  309. lRet = GetObject(m_pPct.Handle, Len(Bmp), Bmp)
  310.  
  311. 'Transfer the picture in the temporary hdc over to the *real* hdc (UserControl.hdc)
  312. lRet = StretchBlt(UserControl.hdc, 0, 0, UserControl.ScaleWidth, (UserControl.ScaleHeight), pDc, _
  313.            0, 0, Bmp.bmWidth, (Bmp.bmHeight), SRCCOPY)
  314.  
  315. UserControl.Refresh
  316.  
  317. 'IMPORTANT!!! This allows the image processing procedures to blt to the usercontrol's
  318. 'hDc quickly.  The processed images are not persistent after AutoRedraw is changed.
  319. AutoRedraw = False
  320.  
  321. 'IMPORTANT!!! Since we are using API calls, VB does not know to clean up the
  322. 'compatible hDc that we have created.  Clean up a bit so that we don't consume
  323. 'more memory than is necessary.
  324. Call DeleteDC(pDc)
  325.  
  326. End Sub
  327.  
  328. Private Sub PlayWave()
  329. 'The module handle cannot be accessed in design mode for this control's source so...
  330. 'do not be suprised if you do not hear anything.  Compile and then load in host app.
  331. Dim hModl As Long
  332. Dim lRes As Long
  333.  
  334. If (m_bFlagOn And GO_SND) > 0 Then
  335.     lRes = PlaySound("#" & m_iRESWAV, App.hInstance, SND_RESOURCE Or SND_ASYNC)
  336. End If
  337.  
  338. End Sub
  339.  
  340. Private Sub Delay(lVal As Long)
  341. Dim lStart As Long
  342.  
  343. lStart = GetTickCount
  344.  
  345. Do Until lStart + lVal < GetTickCount
  346. Loop
  347.  
  348. End Sub
  349.  
  350. Public Property Get DelayValue() As Long
  351.  
  352. DelayValue = m_DVal
  353.  
  354. End Property
  355.  
  356. Public Property Let DelayValue(ByVal lNew As Long)
  357.  
  358. m_DVal = lNew
  359.  
  360. End Property
  361.  
  362.  
  363. Private Sub MouseInRange()
  364. Dim lRet As Long
  365.  
  366.   RunGraphic
  367.  
  368. End Sub
  369.  
  370.  
  371. Private Sub UserControl_Click()
  372.  
  373. RaiseEvent Click
  374.  
  375. RunGraphic
  376.  
  377. End Sub
  378.  
  379. Private Sub UserControl_Resize()
  380.  
  381. If Not m_pPct Is Nothing Then StretchInit
  382.  
  383. End Sub
  384.  
  385. Private Sub UserControl_Show()
  386.  
  387. If m_pPct Is Nothing Then
  388.     Set m_pPct = LoadResPicture(9, vbResBitmap)
  389.     StretchInit
  390. End If
  391.     
  392. End Sub
  393.  
  394. Private Sub UserControl_Terminate()
  395.  
  396. Set m_pPct = Nothing
  397.  
  398. End Sub
  399.  
  400. Private Sub RunGraphic()
  401.     
  402. Dim iCnt As Integer
  403.     
  404. If Not m_pPct Is Nothing Then
  405.     
  406.     PlayWave
  407.     
  408.     Select Case m_iType
  409.     Case FX_SCROLL
  410.         Dim lOPCode As Long
  411.         Dim lNotOp As Long
  412.         For iCnt = 1 To m_iIterate
  413.         If lOPCode = m_ROP1 Then
  414.           lOPCode = m_ROP2
  415.           lNotOp = m_ROP1
  416.         Else
  417.           lOPCode = m_ROP1
  418.           lNotOp = m_ROP2
  419.         End If
  420.         Scroll m_iDir, lOPCode, lNotOp
  421.         Next
  422.     Case FX_RNDSQUARE
  423.         For iCnt = 1 To m_iIterate
  424.             RndSquares
  425.         Next
  426.     Case FX_SLATS
  427.         For iCnt = 1 To m_iIterate
  428.             HorizSlats
  429.         Next
  430.     End Select
  431.  
  432. End If
  433.  
  434. Cls
  435.  
  436. End Sub
  437.  
  438. Public Property Get Iterations() As Integer
  439.  
  440. Iterations = m_iIterate
  441.  
  442. End Property
  443.  
  444. Public Property Let Iterations(ByVal iNew As Integer)
  445.  
  446. m_iIterate = iNew
  447.  
  448. PropertyChanged Iterations
  449.  
  450. End Property
  451.  
  452. Public Property Get ProcessType() As FXType
  453.  
  454. ProcessType = m_iType
  455.  
  456. End Property
  457.  
  458. Public Property Let ProcessType(ByVal iNew As FXType)
  459.  
  460. m_iType = iNew
  461.  
  462. PropertyChanged ProcessType
  463.  
  464. End Property
  465.  
  466. Public Property Get ScrollROP1() As RasterType
  467.  
  468. Select Case m_ROP1
  469.     Case vbSrcCopy
  470.         ScrollROP1 = RO_NORMAL
  471.     Case vbNotSrcCopy
  472.         ScrollROP1 = RO_INVERT
  473.     Case vbSrcAnd
  474.         ScrollROP1 = RO_COMBINE
  475. End Select
  476.  
  477. End Property
  478.  
  479. Public Property Let ScrollROP1(ByVal iNew As RasterType)
  480.  
  481. Select Case iNew
  482.     Case RO_NORMAL
  483.         m_ROP1 = vbSrcCopy
  484.     Case RO_INVERT
  485.         m_ROP1 = vbNotSrcCopy
  486.     Case RO_COMBINE
  487.         m_ROP1 = vbSrcAnd
  488. End Select
  489.  
  490. PropertyChanged ScrollROP1
  491.  
  492. End Property
  493.  
  494. Public Property Get ScrollROP2() As RasterType
  495.  
  496. Select Case m_ROP2
  497.     Case vbSrcCopy
  498.         ScrollROP2 = RO_NORMAL
  499.     Case vbNotSrcCopy
  500.         ScrollROP2 = RO_INVERT
  501.     Case vbSrcAnd
  502.         ScrollROP2 = RO_COMBINE
  503. End Select
  504.  
  505. End Property
  506.  
  507. Public Property Let ScrollROP2(ByVal iNew As RasterType)
  508.  
  509. Select Case iNew
  510.     Case RO_NORMAL
  511.         m_ROP2 = vbSrcCopy
  512.     Case RO_INVERT
  513.         m_ROP2 = vbNotSrcCopy
  514.     Case RO_COMBINE
  515.         m_ROP2 = vbSrcAnd
  516. End Select
  517.  
  518. PropertyChanged ScrollROP2
  519.  
  520. End Property
  521.  
  522. Public Property Get ScrollDirection() As Direction
  523.  
  524. ScrollDirection = m_iDir
  525.  
  526. End Property
  527.  
  528. Public Property Let ScrollDirection(ByVal iNew As Direction)
  529.  
  530. m_iDir = iNew
  531.  
  532. PropertyChanged ScrollDirection
  533.  
  534. End Property
  535.  
  536. Public Property Get Picture() As Picture
  537. Attribute Picture.VB_ProcData.VB_Invoke_Property = "StandardPicture;Appearance"
  538. Attribute Picture.VB_UserMemId = 0
  539.  
  540. Set Picture = m_pPct
  541.  
  542. End Property
  543.  
  544. Public Property Set Picture(ByVal pPicture As Picture)
  545.  
  546. If (Not pPicture Is Nothing) Then
  547.  
  548.   If Not ClearPictureOnly Then
  549.       ClearURLOnly = True                         ' If Picture property is not being set by the URLPicture
  550.       URLPicture = ""                             ' property then clear the URLPicture value...
  551.       ClearURLOnly = False                        ' If Picture property is not being set by the URLPicture
  552.   End If
  553.   
  554.   If (pPicture.Handle = 0) Then Set pPicture = Nothing
  555.   
  556.   Set m_pPct = pPicture                           ' Store image to global variable
  557.   
  558.   With UserControl
  559.       If Not pPicture Is Nothing Then             ' Check for Null picture value
  560.       On Error Resume Next
  561.         If Err = 0 Then StretchInit
  562.       End If
  563.   End With
  564.   
  565.   PropertyChanged Picture                         ' Notify property bag of property change
  566.  
  567. End If
  568.  
  569. End Property
  570.  
  571. Public Property Get EnableSound() As Boolean
  572.  
  573. If (m_bFlagOn And GO_SND) > 0 Then
  574.     EnableSound = True
  575. Else
  576.     EnableSound = False
  577. End If
  578.  
  579. End Property
  580.  
  581. Public Property Let EnableSound(ByVal bNewValue As Boolean)
  582.  
  583. If bNewValue Then
  584.     m_bFlagOn = (m_bFlagOn Or GO_SND)
  585. Else
  586.     m_bFlagOn = Not ((Not m_bFlagOn) Or GO_SND)
  587. End If
  588.  
  589. PropertyChanged EnableSound
  590.  
  591. End Property
  592.  
  593. Public Property Get SoundIndex() As RESWAVE
  594.  
  595. SoundIndex = m_iRESWAV
  596.  
  597. End Property
  598.  
  599. Public Property Let SoundIndex(ByVal iNewValue As RESWAVE)
  600.  
  601. If iNewValue > MIN_SND - 1 And iNewValue < MAX_SND + 1 Then
  602.     
  603.     m_iRESWAV = iNewValue
  604.     PropertyChanged SoundIndex
  605.  
  606. Else
  607.     
  608.     If UserControl.Ambient.UserMode = True Then
  609.         MsgBox "Invalid index value provided for property", vbExclamation, App.EXEName
  610.     Else
  611.         Err.Raise vbObjectError + ERR_INVALID, App.EXEName, "Invalid index value provided for property"
  612.     End If
  613.  
  614. End If
  615.  
  616. End Property
  617.  
  618. Public Property Let URLPicture(URL As String)
  619.     
  620.     If (m_strURL <> URL) Then                     ' Do only if value has changed...
  621.         ClearPictureOnly = Not ClearURLOnly       ' If Picture property is not being set by the URLPicture _
  622.                                                   ' property then clear the URLPicture value...
  623.         m_strURL = URL                            ' Save url string value to global variable
  624.         PropertyChanged "URLPicture"              ' Notify property bag of property change
  625.             
  626.         If Not ClearURLOnly Then
  627.             On Error GoTo ErrorHandler            ' Handle Error if URL is unavailable or Invalid...
  628.             UserControl.AsyncRead URL, vbAsyncTypePicture, "Picture" ' Begin async download of bitmap
  629.         End If
  630.     End If
  631.  
  632.     Exit Property
  633.  
  634. ErrorHandler:
  635. 'This handles error cases and, if the URL is empty it puts the default bmp from the res file
  636. 'into the control.
  637. Set m_pPct = LoadResPicture(9, vbResBitmap)
  638. StretchInit
  639. ClearPictureOnly = False
  640.  
  641. End Property
  642.  
  643. Public Property Get URLPicture() As String
  644.     URLPicture = m_strURL                        ' Return URL string value
  645. End Property
  646.  
  647. Private Sub UserControl_AsyncReadComplete(AsyncProp As AsyncProperty)
  648.     
  649.     If (AsyncProp.PropertyName = "Picture") Then  ' Picture download is complete
  650.         ClearPictureOnly = True
  651.         Set Picture = AsyncProp.Value             ' Store picture data to property...
  652.         ClearPictureOnly = False
  653.     End If
  654.  
  655. End Sub
  656.  
  657.