Date: 02-16-2022
Return to Index
created by gbSnippets
'I thought to use Graphic Set WordWrap to wrap printed text in
'the visible area of a graphic control that is in virtual mode.
'But Graphic Set WordWrap wraps words at the virtual width, not
'the visible width. Here's a work around using Graphic Split.
'This approach also takes into account whether the vertical scrollbar
'is visible.
'Compilable Example: (Jose Includes)
#Compiler PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg,hFont As Dword, VirtualX, VirtualY As Long
%IDC_Graphic = 500
Function PBMain() As Long
Dialog New Pixels, 0, "WordWrap Test",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Graphic, hDlg, %IDC_Graphic, "",0,0,200,200, %WS_Border
Graphic Attach hDlg, %IDC_Graphic
VirtualX = 400 : VirtualY = 400
Graphic Set Virtual VirtualX, VirtualY
Graphic Color %Black, %White
Graphic Clear
Font New "Consolas", 14,1 To hFont
Graphic Set Font hFont
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local w,h As Long
Select Case Cb.Msg
Case %WM_Size
Dialog Get Client hDlg To w,h
Control Set Size hDlg, %IDC_Graphic, w,h
Wrap "Now is the time for all good men to come to the aid of their country"
End Select
End Function
Sub Wrap(temp As String)
Local Part1, Part2 As String, w As Long
If Graphic(Client.Y) < Graphic(Canvas.Y) Then w = 20
Graphic Clear
Graphic Split Word temp, Graphic(Client.X) - w To Part1, Part2
While Len(Part2)
Graphic Print Part1
Graphic Split Word Trim$(Part2), Graphic(Client.X) - w To Part1, Part2
Wend
Graphic Print Part1
End Sub
'gbs_00579
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm