Declare Function BitBlt% Lib "gdi" (ByVal destDC%, ByVal x%, ByVal Y%, ByVal w%, ByVal H%, ByVal srcDC%, ByVal xSrc%, ByVal ySrc%, ByVal Rop&)
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&)

Const SRCCOPY = &HCC0020

Dim cxBorders%, cyBorders%, Flipped%(63)

Sub Form_Paint ()

'* Repaint form row by row, copying normal backgroup
'* cell bitmap to form if cell is not flipped, or the
'* corresponding Icon if the cell is flipped.

  For Row% = 0 To 4
    For Columns% = 0 To 4

    '* Determine upper left hand corner of Cell

      x% = Columns% * Picture1.Width
      Y% = Row% * Picture1.Height
      

      If Flipped%(Cell%) Then

      '* Cell is currently flipped, so copy corresponding Icon
      '* from IconBitmap to middle of "working" Picture control
      '* then Copy the bitmap of the Working picture control to
      '* the form

        Z% = BitBlt(Picture3.hdc, 18, 18, 32, 32, Picture4.hdc, Cell% * 32, 0, SRCCOPY)
        Z% = BitBlt(hdc, x%, Y%, Picture1.Width, Picture1.Height, Picture3.hdc, 0, 0, SRCCOPY)

      Else
        
      '* Cell is not flipped so display normal cell background.

        Z% = BitBlt(hdc, x%, Y%, Picture1.Width, Picture1.Height, Picture1.hdc, 0, 0, SRCCOPY)

      End If

      Cell% = Cell% + 1

    Next Columns%
  Next Row%
End Sub

Sub Form_MouseUp (Button As Integer, Shift As Integer, x As Single, Y As Single)

'* Determine what Cell was clicked and what Icon should
'* be displayed when flipped.

  IX% = x \ Picture1.Width
  IY% = Y \ Picture1.Height
  IconNum% = IX% + (IY% * 5)

'* Determine upper left hand corner of Cell within form

  IX% = IX% * Picture1.Width
  IY% = IY% * Picture1.Height

'* Copy Icon from IconsBitmap to middle of "Working"
'* Picture control in preparation for flipping.
'* If displaying the Icon, The icon is inverted horizontally
'* before flipping so when it is flipped, it appears normally

  If Button = 1 Then
    If Flipped%(IconNum%) Then
      Z% = BitBlt(Picture3.hdc, 18, 18, 32, 32, Picture4.hdc, IconNum% * 32, 0, SRCCOPY)
    Else
      Z% = StretchBlt(Picture3.hdc, 49, 18, -32, 32, Picture4.hdc, IconNum% * 32, 0, 32, 32, SRCCOPY)
    End If

    FlipWidth% = Picture1.Width

  '* Flip the Cell

    For I% = 0 To Picture1.Width Step 10
    
      Picture2.Cls

      If Flipped%(IconNum%) Then
    
      '* Flip cell horizontally
    
        If ((Not Flipped%(IconNum%)) And (I% < Picture1.Width \ 2)) Or (Flipped%(IconNum%) And (I% >= Picture1.Width \ 2)) Then
          Z% = StretchBlt(Picture2.hdc, 0, I%, Picture1.Height, FlipWidth%, Picture1.hdc, 0, 0, CInt(Picture1.Width), CInt(Picture1.Height), SRCCOPY)
        Else
          Z% = StretchBlt(Picture2.hdc, 0, I%, Picture1.Height, FlipWidth%, Picture3.hdc, 0, 0, CInt(Picture1.Width), CInt(Picture1.Height), SRCCOPY)
        End If
  
      Else
  
      '* Flip cell Vertically
  
        If ((Not Flipped%(IconNum%)) And (I% < Picture1.Width \ 2)) Or (Flipped%(IconNum%) And (I% >= Picture1.Width \ 2)) Then
          Z% = StretchBlt(Picture2.hdc, I%, 0, FlipWidth%, Picture1.Height, Picture1.hdc, 0, 0, CInt(Picture1.Width), CInt(Picture1.Height), SRCCOPY)
        Else
          Z% = StretchBlt(Picture2.hdc, I%, 0, FlipWidth%, Picture1.Height, Picture3.hdc, 0, 0, CInt(Picture1.Width), CInt(Picture1.Height), SRCCOPY)
        End If
  
      End If
  
    '* Display partially flipped Cell on Form
  
      Z% = BitBlt(hdc, IX%, IY%, Picture1.Width, Picture1.Height, Picture2.hdc, 0, 0, SRCCOPY)
      FlipWidth% = FlipWidth% - 20
    Next
    
    Flipped%(IconNum%) = Not Flipped%(IconNum%)
  
   '* Display final cell on Form, either Icon cell or
   '* or normal unflipped cell background

    If Flipped%(IconNum%) Then
      Z% = BitBlt(Picture3.hdc, 18, 18, 32, 32, Picture4.hdc, IconNum% * 32, 0, SRCCOPY)
      Z% = BitBlt(hdc, IX%, IY%, Picture1.Width, Picture1.Height, Picture3.hdc, 0, 0, SRCCOPY)
    Else
      Z% = BitBlt(hdc, IX%, IY%, Picture1.Width, Picture1.Height, Picture1.hdc, 0, 0, SRCCOPY)
    End If

  ElseIf Button = 2 Then

'* X out cell

    XWidth% = 2
    For I% = (Picture1.Width \ 2) - 2 To 0 Step -4
      Z% = StretchBlt(hdc, IX% + I%, IY% + I%, XWidth%, XWidth%, Picture5.hdc, 0, 0, CInt(Picture1.Width - 2), CInt(Picture1.Height - 2), SRCCOPY)
      XWidth% = XWidth% + 8
    Next
    Z% = BitBlt(hdc, IX%, IY%, Picture1.Width, Picture1.Height, Picture5.hdc, 0, 0, SRCCOPY)
    
  End If
End Sub

Sub Form_Load ()
   x% = MsgBox("- Left button flips cells" + Chr$(13) + "- Right button X's out Cells", 0, "Mouse buttons")
End Sub

