Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "win32api.inc"
%IDC_ButtonA = 500
%IDC_ButtonB = 501
%IDC_ListView = 502
Global hDlg As Dword 'main dialog handle
Function PBMain() As Long
Dialog New Pixels, 0, "ListView Test",300,300,270,200,%WS_SysMenu, 0 To hDlg
Control Add Button, hDlg, %IDC_ButtonA, "Preview", 10,10,50,20
Control Add Button, hDlg, %IDC_ButtonB, "Print", 70,10,50,20
CreateListView
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
If Cb.Msg = %WM_Command And Cb.Ctl = %IDC_ButtonA Then PrintPreview
If Cb.Msg = %WM_Command And Cb.Ctl = %IDC_ButtonB Then PrintForReal
End Function
Sub CreateListView
Local i As Long
'create control
Control Add ListView, hDlg, %IDC_ListView, "", 10,40,250,150 '225
ListView Set StyleXX hDlg, %IDC_ListView, %LVS_Ex_GridLines Or %LVS_Ex_FullRowSelect
'columns hdlg, id&, col, "test", width, format
ListView Insert Column hDlg, %IDC_ListView, 1, "Col 1", 75, 0
ListView Insert Column hDlg, %IDC_ListView, 2, "Col 2", 75, 0
ListView Insert Column hDlg, %IDC_ListView, 3, "Col 3", 75, 0
For i = 1 To 150
ListView Insert Item hDlg, %IDC_ListView, i, 1, "Row" + Format$(i,"00")
ListView Set Text hDlg, %IDC_ListView, i,2, "Col2 - " + Str$(i)
ListView Set Text hDlg, %IDC_ListView, i,3, "Col3 - " + Str$(i)
Next i
End Sub
Sub PrintPreview
Local hBMP As Dword
Graphic Window New "Print Preview",%IDC_ListView,%IDC_ListView,400,600 To hBMP 'place to preview
XPrint Attach Default
XPrint Preview hBMP, 0 'attach XPrint statement to place to preview
PrintStuff(1,3,25) 'print grid stuff (can be used on hBMP or on Printer) PageCount-LineCount
XPrint Preview Close 'stop printing to preview
End Sub
Sub PrintForReal
XPrint Attach Default
PrintStuff (3,3,25) 'print grid stuff (can be used on hBMP or on Printer)
XPrint Close 'stop printing to preview
End Sub
Sub PrintStuff(PageCount As Long, MaxPages As Long, LineCount As Long)
Local i,j,h,t,iPos As Long, a$,b$,c$
h = 150 : t = 250
For i = 1 To PageCount
iPos = (i-1) * LineCount
PrintHeader(i,MaxPages)
For j = 1 To LineCount
XPrint Set Pos (100,iPos+j*h+t) : ListView Get Text hDlg, %IDC_ListView, iPos+j,1 To a$ : XPrint a$
XPrint Set Pos (1100,iPos+j*h+t) : ListView Get Text hDlg, %IDC_ListView, iPos+j,2 To b$ : XPrint b$
XPrint Set Pos (2100,iPos+j*h+t) : ListView Get Text hDlg, %IDC_ListView, iPos+j,3 To c$ : XPrint c$
Next j
PrintFooter
If (PageCount>1) And (i<>PageCount) Then XPrint FormFeed
Next i
End Sub
Sub PrintHeader(CurrentPage As Long, PageCount As Long)
XPrint "Page " + Str$(CurrentPage) + " of " + Str$(PageCount)
End Sub
Sub PrintFooter
XPrint Set Pos (1200,6000 )
XPrint "Print Preview Example for Volker"
End Sub
'gbs_01047
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm