tiblay
Messages postés
60
Date d'inscription
mercredi 9 novembre 2005
Statut
Membre
Dernière intervention
6 janvier 2009
15 nov. 2007 à 15:01
Bonjour Renfield,
Merci de repondre a mes questions. Je vais essayer d'expliquer mon besoin plus precisement.
J'ai une Form MdiChild(Sum_Graph) qui contient :
J'ai 1 PictureBox (picFrame) qui s'ajuste a la taille de ma Form
J'ai 1 PictureBox (picGraph) a l'interieur de picFrame qui a une dimension fixe de la taille d'une feuille 8.5 X 11.
J'ai 2 ScrollBar qui me permet de deplacer le (picGraph) a l'interieur de picFrame si la taille de ma Form est trop petite
Dans picGraph il y a 1 Grid, 2 MsChart (pour le moment)
Ce que je recherche est de pouvoir imprimer le picGraph, meme si il est en partie cache.
Je ne controle pas bien SendMessage, il semble que c'est cette methode qui donne le plus de resultats, mais les MsGraph ne sont pas affiches correctement, ils sont gris. Je cherche de ce cote pour le moment
Mon but est d'imprimer picGraph correctement. Je vais essayer de vous expliquer mes echecs
Merci de bien vouloir me donner une ou des pistes, je sais ce que je veux mais je ne connais pas les API qui le font
Essai 1:
Resultat : Impression du GRID
Impression de MsChart, juste le rectangle de la bonne taille, mais gris, rien dedans
Meme si picGraph n'est pas visible au complet, il s'imprime correctement
--------- CODE ----------
With picGraph
'Save ReDraw value
ar = .AutoRedraw
'Set persistance
.AutoRedraw = True
Printer.Orientation = 2
'Wake up printer
Printer.Print
'Draw controls to picture box
rv = SendMessage(.hWnd, WM_PAINT, .hDC, 0)
rv = SendMessage(.hWnd, WM_PRINT, .hDC, PRF_CHILDREN Or PRF_CLIENT Or PRF_OWNED)
'Refresh image to picture property
.Picture = .Image
'Assign Picture
Picture10.Picture = .Picture
'Copy picture to Printer
Printer.PaintPicture .Picture, 0, 0
'End Print
Printer.EndDoc
'Restore ReDraw
.AutoRedraw = ar
End With
Essai 2 :
Resultat : Impression du GRID, rien
Impression de MsChart, rien
Meme si picGraph n'est pas visible au complet, il s'imprime la bonne taille avec ce que l'on voie a l'ecran mais picGraph est tout en gris
--------- CODE ----------
Call CopyEntirePicture(picGraph)
Printer.Orientation = 2
'Copy picture to Printer
Printer.PaintPicture picGraph.Picture, 0, 0
'End Printing
Printer.EndDoc
----------
Public Function CopyEntirePicture(ByRef objFrom As Object) As Boolean
Dim lhDC As Long
Dim lhBMP As Long
Dim lhBMPOld As Long
Dim lWidthPixels As Long
Dim lHeightPixels As Long
' Create a DC compatible with the object we're copying
' from:
lhDC = CreateCompatibleDC(objFrom.hDC)
If (lhDC <> 0) Then
' Create a bitmap compatible with the object we're
' copying from:
lWidthPixels = objFrom.ScaleX( _
objFrom.ScaleWidth, _
objFrom.ScaleMode, _
vbPixels)
lHeightPixels = objFrom.ScaleY( _
objFrom.ScaleHeight, _
objFrom.ScaleMode, _
vbPixels)
lhBMP = CreateCompatibleBitmap(objFrom.hDC, _
lWidthPixels, lHeightPixels)
If (lhBMP <> 0) Then
' Select the bitmap into the DC we have created,
' and store the old bitmap that was there:
lhBMPOld = SelectObject(lhDC, lhBMP)
' Copy the contents of objFrom to the bitmap:
BitBlt lhDC, 0, 0, lWidthPixels, lHeightPixels, _
objFrom.hDC, 0, 0, SRCCOPY
' Remove the bitmap from the DC:
SelectObject lhDC, lhBMPOld
' Now set the clipboard to the bitmap:
OpenClipboard 0
EmptyClipboard
SetClipboardData CF_BITMAP, lhBMP
CloseClipboard
' We don't delete the Bitmap here - it is now owned
' by the clipboard and Windows will delete it for us
' when the clipboard changes or the program exits.
End If
' Clear up the device context we created:
DeleteObject lhDC
End If
End Function
Essai 3:
Resultat : Impression du GRID, rien
Impression de MsChart, rien
Meme si picGraph n'est pas visible au complet, il s'imprime la bonne taille avec ce que l'on voie a l'ecran mais picGraph est tout en gris
With picGraph
.AutoRedraw = True
BitBlt .hDC, 0, 0, .Width, .Height, .hWnd, 0, 0, vbSrcCopy
.Picture = .Image
Printer.Orientation = 2
'Copy picture to Printer
Printer.PaintPicture .Picture, 0, 0
'End Printing
Printer.EndDoc
End With