home *** CD-ROM | disk | FTP | other *** search
- Attribute VB_Name = "basQuadrants"
- '*********************************************************************
- ' QUADRANT.BAS - This is a special rectangle module that performs
- ' several rectangle functions.
- '*********************************************************************
- Option Explicit
- '*********************************************************************
- ' Expose a new rectangle data type.
- '*********************************************************************
- #If Win32 Then
- Public Type RECT
- rL As Long 'Left
- rT As Long 'Top
- rR As Long 'Right (This is NOT equal to Width)
- rB As Long 'Bottom (This is NOT equal to Height)
- End Type
- Public Type PointAPI
- X As Long
- Y As Long
- End Type
- #Else
- Public Type RECT
- rL As Integer 'Left
- rT As Integer 'Top
- rR As Integer 'Right (This is NOT equal to Width)
- rB As Integer 'Bottom (This is NOT equal to Height)
- End Type
- Public Type PointAPI
- X As Integer
- Y As Integer
- End Type
- #End If
- '*********************************************************************
- ' API Declarations.
- '*********************************************************************
- #If Win32 Then
- Public Declare Sub GetClientRect Lib "user32" (ByVal hWnd As Long, _
- lpRect As RECT)
- Public Declare Sub InflateRect Lib "user32" (lpRect As RECT, _
- ByVal X As Long, ByVal Y As Long)
- Public Declare Function PtInRect Lib "user32" (lpRect As RECT, _
- ByVal ptScreenX As Long, ByVal ptScreenY As Long) As Long
- Public Declare Function ClientToScreen Lib "user32" (ByVal hWnd&, _
- lpPoint As PointAPI) As Long
- #Else
- Public Declare Sub GetClientRect Lib "User" (ByVal hWnd%, _
- lpRect As RECT)
- Public Declare Sub InflateRect Lib "User" (lpRect As RECT, _
- ByVal iX%, ByVal iY%)
- Public Declare Sub ClientToScreen Lib "User" (ByVal hWnd%, _
- lpPoint As PointAPI)
- Public Declare Function PtInRect Lib "User" (lpRect As RECT, _
- ByVal ptScreenY As Integer, ByVal ptScreenX As Integer) As Integer
- ' ptRect As PointAPI) As Integer
- #End If
- '*********************************************************************
- ' Private Module Variables
- '*********************************************************************
- Private Quad1 As RECT, Quad2 As RECT, Quad3 As RECT, Quad4 As RECT
- '*********************************************************************
- ' Divides a form into 4 quadrants, starting with the upper left
- ' corner (Q1), and continuing clockwise.
- '*********************************************************************
- Public Sub GetQuadrants(FormName As Form, Q1 As RECT, Q2 As RECT, _
- Q3 As RECT, Q4 As RECT)
- Dim FormWidth%, FormHeight%
- '*****************************************************************
- ' The form ScaleMode MUST be in pixels!
- '*****************************************************************
- FormName.ScaleMode = vbPixels
- '*****************************************************************
- ' Determine the height & width of the forms client area.
- '*****************************************************************
- FormWidth = FormName.ScaleWidth
- FormHeight = FormName.ScaleHeight
- '*****************************************************************
- ' Set the 4 quad arguments and the module level quads.
- '*****************************************************************
- With Quad1
- .rL = 0
- .rT = 0
- .rR = FormWidth / 2
- .rB = FormHeight / 2
- End With
-
- Q1 = Quad1
-
- With Quad2
- .rL = FormWidth / 2
- .rT = 0
- .rR = FormWidth - 1
- .rB = FormHeight / 2
- End With
-
- Q2 = Quad2
-
- With Quad3
- .rL = 0
- .rT = FormHeight / 2
- .rR = FormWidth / 2
- .rB = FormHeight - 1
- End With
-
- Q3 = Quad3
-
- With Quad4
- .rL = FormWidth / 2
- .rT = FormHeight / 2
- .rR = FormWidth - 1
- .rB = FormHeight - 1
- End With
-
- Q4 = Quad4
- End Sub
- '*********************************************************************
- ' Draw either a solid or hollow rectangle on a form.
- '*********************************************************************
- Public Sub DrawRect(FormName As Form, rRect As RECT, _
- Solid As Boolean, Optional RectColor)
- '*****************************************************************
- ' If no color is provided, then use black.
- '*****************************************************************
- RectColor = IIf(IsMissing(RectColor), RGB(0, 0, 0), RectColor)
- '*****************************************************************
- ' Draw the rectangle on the form.
- '*****************************************************************
- If Solid Then
- FormName.Line (rRect.rL, rRect.rT)-(rRect.rR, rRect.rB), _
- RectColor, BF
- Else
- FormName.Line (rRect.rL, rRect.rT)-(rRect.rR, rRect.rB), _
- RectColor, B
- End If
- End Sub
- '*********************************************************************
- ' Draw a hollow 3D rectangle. (Similar to the SSPanel3D control.)
- '*********************************************************************
- Public Sub Draw3DRect(FormName As Form, rRect As RECT, Inset As Boolean)
- Dim LT&, BR&
- '*****************************************************************
- ' Set the L(eft)T(op) and B(ottom)R(ight) line colors.
- '*****************************************************************
- LT = IIf(Inset, vb3DShadow, vb3DHighlight)
- BR = IIf(Inset, vb3DHighlight, vb3DShadow)
- '*****************************************************************
- ' Draw the 4 lines.
- '*****************************************************************
- FormName.Line (rRect.rL, rRect.rT)-(rRect.rL, rRect.rB), LT
- FormName.Line (rRect.rL, rRect.rT)-(rRect.rR, rRect.rT), LT
- FormName.Line (rRect.rR, rRect.rT)-(rRect.rR, rRect.rB), BR
- FormName.Line (rRect.rL, rRect.rB)-(rRect.rR + 1, rRect.rB), BR
- End Sub
- '*********************************************************************
- ' Draw a hollow 3D rectangle. (Similar to the SSPanel3D control.)
- '*********************************************************************
- Public Sub Draw3DPBRect(pBox As PictureBox, rRect As RECT, Inset As Boolean)
- Dim LT&, BR&
- '*****************************************************************
- ' Set the L(eft)T(op) and B(ottom)R(ight) line colors.
- '*****************************************************************
- LT = IIf(Inset, vb3DShadow, vb3DHighlight)
- BR = IIf(Inset, vb3DHighlight, vb3DShadow)
- '*****************************************************************
- ' Draw the 4 lines.
- '*****************************************************************
- pBox.Line (rRect.rL, rRect.rT)-(rRect.rL, rRect.rB), LT
- pBox.Line (rRect.rL, rRect.rT)-(rRect.rR, rRect.rT), LT
- pBox.Line (rRect.rR, rRect.rT)-(rRect.rR, rRect.rB), BR
- pBox.Line (rRect.rL, rRect.rB)-(rRect.rR + 1, rRect.rB), BR
- End Sub
- '*********************************************************************
- ' Draw a hollow 3D rectangle around the edge of the picture box.
- '*********************************************************************
- Public Sub Draw3DPicBorder(pBox As PictureBox, Inset As Boolean)
- Dim rRect As RECT
- '*****************************************************************
- ' Get the client rect of the form.
- '*****************************************************************
- GetClientRect pBox.hWnd, rRect
- '*****************************************************************
- ' Deflate the right & bottom of the rect by 1 pixel.
- '*****************************************************************
- ResizeRect rRect, -1, -1, True
- '*****************************************************************
- ' Draw the 3D rect, and repeat again.
- '*****************************************************************
- Draw3DPBRect pBox, rRect, Inset
- ResizeRect rRect, -1, -1, False
- Draw3DPBRect pBox, rRect, Inset
- End Sub
- '*********************************************************************
- ' Draw a hollow 3D rectangle around the edge of the form.
- '*********************************************************************
- Public Sub Draw3DFormRect(FormName As Form, Inset As Boolean)
- Dim rRect As RECT
- '*****************************************************************
- ' Get the client rect of the form.
- '*****************************************************************
- GetClientRect FormName.hWnd, rRect
- '*****************************************************************
- ' Deflate the right & bottom of the rect by 1 pixel.
- '*****************************************************************
- ResizeRect rRect, -1, -1, True
- '*****************************************************************
- ' Draw the 3D rect.
- '*****************************************************************
- Draw3DRect FormName, rRect, Inset
- End Sub
- '*********************************************************************
- ' Inflates or Deflates a rectangle from all sides or the bottom.
- '*********************************************************************
- Public Sub ResizeRect(rRect As RECT, iX%, iY%, KeepSameLT As Boolean)
- '*****************************************************************
- ' If KeepSameL(eft)T(op), then only operate on .rR & .rB.
- '*****************************************************************
- If KeepSameLT Then
- rRect.rR = rRect.rR + iX
- rRect.rB = rRect.rB + iY
- '*****************************************************************
- ' Otherwise inflate or deflate all 4 sides.
- '*****************************************************************
- Else
- InflateRect rRect, iX, iY
- End If
- End Sub
- '*********************************************************************
- ' Changes the left & top values of a rectangle.
- '*********************************************************************
- Public Sub MoveRect(rRect As RECT, ByVal iX%, ByVal iY%)
- rRect.rL = rRect.rL + iX
- rRect.rT = rRect.rT + iY
- End Sub
- '*********************************************************************
- ' Draws a 3D grid on a form with 4 child quadrants.
- '*********************************************************************
- Public Sub Draw3DGrid(FormName As Form, Inset As Boolean, _
- Optional ByVal Offset)
- Dim InsideOffset%, OutsideOffset%
- '*****************************************************************
- ' Set the offset values.
- '*****************************************************************
- On Error Resume Next
- Offset = IIf(IsMissing(Offset), 10, Offset)
- InsideOffset = Offset
- OutsideOffset = Abs(IIf(IsMissing(Offset), 5, (Offset / 2)) - 1)
- '*****************************************************************
- ' This is a bit redundant, but its necessary.
- '*****************************************************************
- GetQuadrants FormName, Quad1, Quad2, Quad3, Quad4
- '*****************************************************************
- ' Draw the 4 3D quadrants.
- '*****************************************************************
- MoveRect Quad1, InsideOffset + 1, InsideOffset + 1
- ResizeRect Quad1, -InsideOffset, -InsideOffset, True
- Draw3DRect FormName, Quad1, Inset
-
- MoveRect Quad2, OutsideOffset, InsideOffset + 1
- ResizeRect Quad2, -InsideOffset - 1, -InsideOffset, True
- Draw3DRect FormName, Quad2, Inset
-
- MoveRect Quad3, InsideOffset + 1, OutsideOffset
- ResizeRect Quad3, -InsideOffset, -InsideOffset, True
- Draw3DRect FormName, Quad3, Inset
-
- MoveRect Quad4, OutsideOffset, OutsideOffset
- ResizeRect Quad4, -InsideOffset - 1, -InsideOffset, True
- Draw3DRect FormName, Quad4, Inset
- '*****************************************************************
- ' Draw a 3D border around the form.
- '*****************************************************************
- Draw3DFormRect FormName, False
- End Sub
- '*********************************************************************
- ' Set a given RECT (Quad) to the value of a quadrant.
- '*********************************************************************
- Public Sub GetQuad(Quadrant%, Quad As RECT)
- Select Case Quadrant
- Case 1
- Quad = Quad1
- Case 2
- Quad = Quad2
- Case 3
- Quad = Quad3
- Case 4
- Quad = Quad4
- End Select
- End Sub
- '*********************************************************************
- ' Get the Width & Height of a rectangle.
- '*********************************************************************
- Public Function GetRectWidth(rRect As RECT) As Integer
- GetRectWidth = rRect.rR - rRect.rL
- End Function
-
- Public Function GetRectHeight(rRect As RECT) As Integer
- GetRectHeight = rRect.rB - rRect.rT
- End Function
- '*********************************************************************
- ' Size a control into the client area of a rectangle.
- '*********************************************************************
- Public Sub SizeToRectClient(Cntl As Control, rSourceRect As RECT)
- Dim rRect As RECT
- rRect = rSourceRect
- ResizeRect rRect, -1, -1, False
- Cntl.Move rRect.rL, rRect.rT, GetRectWidth(rRect), _
- GetRectHeight(rRect)
- End Sub
- '*********************************************************************
- ' Check to see if a control is equal to the client area of a rect.
- '*********************************************************************
- Public Function EqualToQuadClient(Cntl As Control, _
- rSourceRect As RECT) As Boolean
- Dim rRect As RECT
- '*****************************************************************
- ' Since you can't pass rects by value, then create a new copy.
- '*****************************************************************
- rRect = rSourceRect
- '*****************************************************************
- ' Resize the copy.
- '*****************************************************************
- ResizeRect rRect, -1, -1, False
- '*****************************************************************
- ' If any are true, then return false.
- '*****************************************************************
- If Cntl.left <> rRect.rL Then GoSub ReturnFalse
- If Cntl.top <> rRect.rT Then GoSub ReturnFalse
- If Cntl.Width <> GetRectWidth(rRect) Then GoSub ReturnFalse
- If Cntl.Height <> GetRectHeight(rRect) Then GoSub ReturnFalse
- '*****************************************************************
- ' If you got this far, then they are indeed equal.
- '*****************************************************************
- EqualToQuadClient = True
- Exit Function
- '*********************************************************************
- ' Save yourself some typing by using a GoSub to here.
- '*********************************************************************
- ReturnFalse:
- EqualToQuadClient = False
- Exit Function
- End Function
- '*********************************************************************
- ' Converts a rectangle to screen coordinates.
- '*********************************************************************
- Public Sub ConvertRectToScreen(FormName As Form, rSourceRect As RECT)
- Dim ptLT As PointAPI, ptRB As PointAPI
- ptLT.X = rSourceRect.rL
- ptLT.Y = rSourceRect.rT
- ptRB.X = rSourceRect.rR
- ptRB.Y = rSourceRect.rB
- ClientToScreen FormName.hWnd, ptLT
- ClientToScreen FormName.hWnd, ptRB
- End Sub
-