[R] Imprimer une listview
Posté : jeu. 06 juin 2019 12:22
Bonjour,
Je souhaiterai pouvoir imprimer une listview générée dans une GUI.
Pour l'instant, je peux imprimer la GUI mais la ligne _ScreenCapture_CaptureWnd($sFilePrint, $g_hListview) ne fonctionne pas.
De plus lorsque l'aperçu de l'impression apparaît, la GUI apparaît sur toute la page.
En recherchant, je suis tombé sur différents scripts :
Printing using UDF and a dll : https://www.autoitscript.com/forum/topi ... and-a-dll/
PrintWinAPI.au3 : https://www.autoitscript.com/forum/topi ... om-autoit/
Print Preview : https://www.autoitscript.com/forum/topi ... t-preview/
mais ils sont anciens ou ne fonctionnent pas.
Dans l'idéal, je souhaiterais imprimer la liste dans une taille de caractère normale et de façon automatique (sans aperçu) de manière à ce que cela ne s'imprime pas sur toute la feuille A4.
Je peux aussi créer un fichier texte à partir de la liste et l'imprimer mais si vous avez une autre idée.
Je souhaiterai pouvoir imprimer une listview générée dans une GUI.
Pour l'instant, je peux imprimer la GUI mais la ligne _ScreenCapture_CaptureWnd($sFilePrint, $g_hListview) ne fonctionne pas.
De plus lorsque l'aperçu de l'impression apparaît, la GUI apparaît sur toute la page.
En recherchant, je suis tombé sur différents scripts :
Printing using UDF and a dll : https://www.autoitscript.com/forum/topi ... and-a-dll/
PrintWinAPI.au3 : https://www.autoitscript.com/forum/topi ... om-autoit/
Print Preview : https://www.autoitscript.com/forum/topi ... t-preview/
mais ils sont anciens ou ne fonctionnent pas.
Dans l'idéal, je souhaiterais imprimer la liste dans une taille de caractère normale et de façon automatique (sans aperçu) de manière à ce que cela ne s'imprime pas sur toute la feuille A4.
Je peux aussi créer un fichier texte à partir de la liste et l'imprimer mais si vous avez une autre idée.
#Region Includes
#include <ColorConstants.au3>
#include <File.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>
#include <MsgBoxConstants.au3>
#include <ScreenCapture.au3>
#include <WindowsConstants.au3>
#EndRegion Includes
#Region Variables
Global Const $g_sTitleApp = "TEST"
Global $g_hGUI = 0, $g_hListview = 0, $g_idButton_Print = 0
Global Const $g_iWitdhGUI = 300, $g_iMarge = 15, $g_iHeightButton = 25
Global $g_iHeightListview = 0, $g_iHeightListviewGroup = 22, $g_iHeightListviewLine = 18
#EndRegion Variables
Go()
Func Go()
Local $iTotalPrinter = 0, $iHeightGUI = 0
Local $sFilePrint = @TempDir & '\Alertes Conso Matabiau.jpg'
CreateGUI()
$iHeightGUI = 42 + $g_iHeightButton + $g_iMarge + $g_iHeightListview + 2 * $g_iMarge
WinMove($g_hGUI, '', (@DesktopWidth - $g_iWitdhGUI) / 2, (@DesktopHeight - $iHeightGUI) / 2, $g_iWitdhGUI + 10, $iHeightGUI)
Sleep(1000)
ProgressOff()
GUISetState(@SW_SHOW)
While 1
$nGUIMsg = GUIGetMsg()
Switch $nGUIMsg
Case $GUI_EVENT_CLOSE
Exit
Case $g_idButton_Print
_ScreenCapture_CaptureWnd($sFilePrint, $g_hGUI)
;~ _ScreenCapture_CaptureWnd($sFilePrint, $g_hListview)
_FilePrint($sFilePrint)
;~ FileDelete($sFilePrint)
EndSwitch
WEnd
EndFunc ;==>Go
Func CreateGUI()
Local $iHeightGUI = 800
Local $iIndex = 0
$g_hGUI = GUICreate($g_sTitleApp, $g_iWitdhGUI, $iHeightGUI, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_MAXIMIZEBOX, $WS_SIZEBOX))
GUISetBkColor($COLOR_WHITE, $g_hGUI)
$g_idButton_Print = GUICtrlCreateButton("Imprimer", $g_iMarge, $g_iMarge, $g_iWitdhGUI - 2 * $g_iMarge, $g_iHeightButton)
$g_hListview = _GUICtrlListView_Create($g_hGUI, "", $g_iMarge, 2 * $g_iMarge + $g_iHeightButton, $g_iWitdhGUI - 2 * $g_iMarge, 800, BitOR($LVS_NOCOLUMNHEADER, $LVS_REPORT))
_GUICtrlListView_AddColumn($g_hListview, "", $g_iWitdhGUI - 2 * $g_iMarge - 40)
_GUICtrlListView_AddColumn($g_hListview, "", 40)
_GUICtrlListView_EnableGroupView($g_hListview)
For $iGroup = 1 To 5
$bFirstLine = True
_GUICtrlListView_InsertGroup($g_hListview, -1, $iGroup, 'Group ' & $iGroup)
For $iLine = 1 To Random(1, 4, 1)
$iIndex = _GUICtrlListView_AddItem($g_hListview, 'Line ' & $iLine)
_GUICtrlListView_SetItemGroupID($g_hListview, $iIndex, $iGroup)
_GUICtrlListView_AddSubItem($g_hListview, $iIndex, Random(1, 99, 1) & ' %', 1)
If $bFirstLine Then
$g_iHeightListview += $g_iHeightListviewGroup
$bFirstLine = False
EndIf
$g_iHeightListview += $g_iHeightListviewLine
Next
Next
EndFunc ;==>CreateGUI
#include <ColorConstants.au3>
#include <File.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>
#include <MsgBoxConstants.au3>
#include <ScreenCapture.au3>
#include <WindowsConstants.au3>
#EndRegion Includes
#Region Variables
Global Const $g_sTitleApp = "TEST"
Global $g_hGUI = 0, $g_hListview = 0, $g_idButton_Print = 0
Global Const $g_iWitdhGUI = 300, $g_iMarge = 15, $g_iHeightButton = 25
Global $g_iHeightListview = 0, $g_iHeightListviewGroup = 22, $g_iHeightListviewLine = 18
#EndRegion Variables
Go()
Func Go()
Local $iTotalPrinter = 0, $iHeightGUI = 0
Local $sFilePrint = @TempDir & '\Alertes Conso Matabiau.jpg'
CreateGUI()
$iHeightGUI = 42 + $g_iHeightButton + $g_iMarge + $g_iHeightListview + 2 * $g_iMarge
WinMove($g_hGUI, '', (@DesktopWidth - $g_iWitdhGUI) / 2, (@DesktopHeight - $iHeightGUI) / 2, $g_iWitdhGUI + 10, $iHeightGUI)
Sleep(1000)
ProgressOff()
GUISetState(@SW_SHOW)
While 1
$nGUIMsg = GUIGetMsg()
Switch $nGUIMsg
Case $GUI_EVENT_CLOSE
Exit
Case $g_idButton_Print
_ScreenCapture_CaptureWnd($sFilePrint, $g_hGUI)
;~ _ScreenCapture_CaptureWnd($sFilePrint, $g_hListview)
_FilePrint($sFilePrint)
;~ FileDelete($sFilePrint)
EndSwitch
WEnd
EndFunc ;==>Go
Func CreateGUI()
Local $iHeightGUI = 800
Local $iIndex = 0
$g_hGUI = GUICreate($g_sTitleApp, $g_iWitdhGUI, $iHeightGUI, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_MAXIMIZEBOX, $WS_SIZEBOX))
GUISetBkColor($COLOR_WHITE, $g_hGUI)
$g_idButton_Print = GUICtrlCreateButton("Imprimer", $g_iMarge, $g_iMarge, $g_iWitdhGUI - 2 * $g_iMarge, $g_iHeightButton)
$g_hListview = _GUICtrlListView_Create($g_hGUI, "", $g_iMarge, 2 * $g_iMarge + $g_iHeightButton, $g_iWitdhGUI - 2 * $g_iMarge, 800, BitOR($LVS_NOCOLUMNHEADER, $LVS_REPORT))
_GUICtrlListView_AddColumn($g_hListview, "", $g_iWitdhGUI - 2 * $g_iMarge - 40)
_GUICtrlListView_AddColumn($g_hListview, "", 40)
_GUICtrlListView_EnableGroupView($g_hListview)
For $iGroup = 1 To 5
$bFirstLine = True
_GUICtrlListView_InsertGroup($g_hListview, -1, $iGroup, 'Group ' & $iGroup)
For $iLine = 1 To Random(1, 4, 1)
$iIndex = _GUICtrlListView_AddItem($g_hListview, 'Line ' & $iLine)
_GUICtrlListView_SetItemGroupID($g_hListview, $iIndex, $iGroup)
_GUICtrlListView_AddSubItem($g_hListview, $iIndex, Random(1, 99, 1) & ' %', 1)
If $bFirstLine Then
$g_iHeightListview += $g_iHeightListviewGroup
$bFirstLine = False
EndIf
$g_iHeightListview += $g_iHeightListviewLine
Next
Next
EndFunc ;==>CreateGUI