home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / VISUAL_B / ARQS_ZIP / VBFLIP.ZIP / FLIP.TXT < prev   
Encoding:
Text File  |  1991-09-06  |  4.7 KB  |  139 lines

  1. Declare Function BitBlt% Lib "gdi" (ByVal destDC%, ByVal x%, ByVal Y%, ByVal w%, ByVal H%, ByVal srcDC%, ByVal xSrc%, ByVal ySrc%, ByVal Rop&)
  2. Declare Function StretchBlt% Lib "gdi" (ByVal destDC%, ByVal x%, ByVal Y%, ByVal w%, ByVal H%, ByVal srcDC%, ByVal xSrc%, ByVal ySrc%, ByVal wSrc%, ByVal hSrc%, ByVal Rop&)
  3.  
  4. Const SRCCOPY = &HCC0020
  5.  
  6. Dim cxBorders%, cyBorders%, Flipped%(63)
  7.  
  8. Sub Form_Paint ()
  9.  
  10. '* Repaint form row by row, copying normal backgroup
  11. '* cell bitmap to form if cell is not flipped, or the
  12. '* corresponding Icon if the cell is flipped.
  13.  
  14.   For Row% = 0 To 4
  15.     For Columns% = 0 To 4
  16.  
  17.     '* Determine upper left hand corner of Cell
  18.  
  19.       x% = Columns% * Picture1.Width
  20.       Y% = Row% * Picture1.Height
  21.       
  22.  
  23.       If Flipped%(Cell%) Then
  24.  
  25.       '* Cell is currently flipped, so copy corresponding Icon
  26.       '* from IconBitmap to middle of "working" Picture control
  27.       '* then Copy the bitmap of the Working picture control to
  28.       '* the form
  29.  
  30.         Z% = BitBlt(Picture3.hdc, 18, 18, 32, 32, Picture4.hdc, Cell% * 32, 0, SRCCOPY)
  31.         Z% = BitBlt(hdc, x%, Y%, Picture1.Width, Picture1.Height, Picture3.hdc, 0, 0, SRCCOPY)
  32.  
  33.       Else
  34.         
  35.       '* Cell is not flipped so display normal cell background.
  36.  
  37.         Z% = BitBlt(hdc, x%, Y%, Picture1.Width, Picture1.Height, Picture1.hdc, 0, 0, SRCCOPY)
  38.  
  39.       End If
  40.  
  41.       Cell% = Cell% + 1
  42.  
  43.     Next Columns%
  44.   Next Row%
  45. End Sub
  46.  
  47. Sub Form_MouseUp (Button As Integer, Shift As Integer, x As Single, Y As Single)
  48.  
  49. '* Determine what Cell was clicked and what Icon should
  50. '* be displayed when flipped.
  51.  
  52.   IX% = x \ Picture1.Width
  53.   IY% = Y \ Picture1.Height
  54.   IconNum% = IX% + (IY% * 5)
  55.  
  56. '* Determine upper left hand corner of Cell within form
  57.  
  58.   IX% = IX% * Picture1.Width
  59.   IY% = IY% * Picture1.Height
  60.  
  61. '* Copy Icon from IconsBitmap to middle of "Working"
  62. '* Picture control in preparation for flipping.
  63. '* If displaying the Icon, The icon is inverted horizontally
  64. '* before flipping so when it is flipped, it appears normally
  65.  
  66.   If Button = 1 Then
  67.     If Flipped%(IconNum%) Then
  68.       Z% = BitBlt(Picture3.hdc, 18, 18, 32, 32, Picture4.hdc, IconNum% * 32, 0, SRCCOPY)
  69.     Else
  70.       Z% = StretchBlt(Picture3.hdc, 49, 18, -32, 32, Picture4.hdc, IconNum% * 32, 0, 32, 32, SRCCOPY)
  71.     End If
  72.  
  73.     FlipWidth% = Picture1.Width
  74.  
  75.   '* Flip the Cell
  76.  
  77.     For I% = 0 To Picture1.Width Step 10
  78.     
  79.       Picture2.Cls
  80.  
  81.       If Flipped%(IconNum%) Then
  82.     
  83.       '* Flip cell horizontally
  84.     
  85.         If ((Not Flipped%(IconNum%)) And (I% < Picture1.Width \ 2)) Or (Flipped%(IconNum%) And (I% >= Picture1.Width \ 2)) Then
  86.           Z% = StretchBlt(Picture2.hdc, 0, I%, Picture1.Height, FlipWidth%, Picture1.hdc, 0, 0, CInt(Picture1.Width), CInt(Picture1.Height), SRCCOPY)
  87.         Else
  88.           Z% = StretchBlt(Picture2.hdc, 0, I%, Picture1.Height, FlipWidth%, Picture3.hdc, 0, 0, CInt(Picture1.Width), CInt(Picture1.Height), SRCCOPY)
  89.         End If
  90.   
  91.       Else
  92.   
  93.       '* Flip cell Vertically
  94.   
  95.         If ((Not Flipped%(IconNum%)) And (I% < Picture1.Width \ 2)) Or (Flipped%(IconNum%) And (I% >= Picture1.Width \ 2)) Then
  96.           Z% = StretchBlt(Picture2.hdc, I%, 0, FlipWidth%, Picture1.Height, Picture1.hdc, 0, 0, CInt(Picture1.Width), CInt(Picture1.Height), SRCCOPY)
  97.         Else
  98.           Z% = StretchBlt(Picture2.hdc, I%, 0, FlipWidth%, Picture1.Height, Picture3.hdc, 0, 0, CInt(Picture1.Width), CInt(Picture1.Height), SRCCOPY)
  99.         End If
  100.   
  101.       End If
  102.   
  103.     '* Display partially flipped Cell on Form
  104.   
  105.       Z% = BitBlt(hdc, IX%, IY%, Picture1.Width, Picture1.Height, Picture2.hdc, 0, 0, SRCCOPY)
  106.       FlipWidth% = FlipWidth% - 20
  107.     Next
  108.     
  109.     Flipped%(IconNum%) = Not Flipped%(IconNum%)
  110.   
  111.    '* Display final cell on Form, either Icon cell or
  112.    '* or normal unflipped cell background
  113.  
  114.     If Flipped%(IconNum%) Then
  115.       Z% = BitBlt(Picture3.hdc, 18, 18, 32, 32, Picture4.hdc, IconNum% * 32, 0, SRCCOPY)
  116.       Z% = BitBlt(hdc, IX%, IY%, Picture1.Width, Picture1.Height, Picture3.hdc, 0, 0, SRCCOPY)
  117.     Else
  118.       Z% = BitBlt(hdc, IX%, IY%, Picture1.Width, Picture1.Height, Picture1.hdc, 0, 0, SRCCOPY)
  119.     End If
  120.  
  121.   ElseIf Button = 2 Then
  122.  
  123. '* X out cell
  124.  
  125.     XWidth% = 2
  126.     For I% = (Picture1.Width \ 2) - 2 To 0 Step -4
  127.       Z% = StretchBlt(hdc, IX% + I%, IY% + I%, XWidth%, XWidth%, Picture5.hdc, 0, 0, CInt(Picture1.Width - 2), CInt(Picture1.Height - 2), SRCCOPY)
  128.       XWidth% = XWidth% + 8
  129.     Next
  130.     Z% = BitBlt(hdc, IX%, IY%, Picture1.Width, Picture1.Height, Picture5.hdc, 0, 0, SRCCOPY)
  131.     
  132.   End If
  133. End Sub
  134.  
  135. Sub Form_Load ()
  136.    x% = MsgBox("- Left button flips cells" + Chr$(13) + "- Right button X's out Cells", 0, "Mouse buttons")
  137. End Sub
  138.  
  139.