Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compile Exe
#Dim All
%Unicode = 1
#Include "Win32API.inc"
Enum Equates Singular
IDC_Graphic = 500
End Enum
Global hDlg As Dword
Global CellSizeX, CellSizeY, gX, gY As Long, Cells() As Rect
Function PBMain() As Long
Dialog New Pixels, 0, "PowerBASIC",300,300,500,300, %WS_OverlappedWindow To hDlg
Control Add Graphic, hDlg, %IDC_Graphic, "", 0,0,500,300
Graphic Attach hDlg, %IDC_Graphic, ReDraw
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case Cb.Msg
Case %WM_Size
Local w,h As Long
Dialog Get Client hDlg To w,h
Dialog Set Text hDlg, "w=" + Trim$(Str$(w)) + " h=" + Trim$(Str$(h))
Control Set Size hDlg, %IDC_Graphic, w,h
CreateAndDrawCells(6,4) 'Cols x Rows
End Select
End Function
Sub CreateAndDrawCells(Cols As Long, Rows As Long)
Local w,h,iCol,iRow,iCount As Long
ReDim Cells(Cols*Rows)
Graphic Clear : Graphic Width 2
Graphic Get Client To w,h
If h<w Then
CellSizeY = h \ Rows
CellSizeX = CellSizeY
If CellSizeX * Cols > w Then
CellSizeX = w \ Cols
CellSizeY = CellSizeX
End If
Else
CellSizeX = w \ Cols
CellSizeY = CellSizeX
If CellSizeY * Rows > h Then
CellSizeY = h \ Rows
CellSizeX = CellSizeY
End If
End If
gX = (w-Cols*CellSizeX)/2 'gx is left/right margins
gY = (h-Rows*CellSizeY)/2 'gy is top/bottom margins
For iCol = 1 To Cols
For iRow = 1 To Rows
Incr iCount
Cells(iCount).left = gX + (iCol-1) * CellSizeX
Cells(iCount).top = gY + (iRow-1) * CellSizeY
Cells(iCount).right = gX + (iCol) * CellsizeX
Cells(iCount).bottom = gY + (iRow) * CellsizeY
Graphic Box (Cells(iCount).left,Cells(iCount).top)-(Cells(iCount).right,Cells(iCount).bottom),,%Blue
Next i
Next j
Graphic ReDraw
End Sub
http://www.garybeene.com/sw/gbsnippets.htm