Chosir l'imprimante pour l'impression en cours SANS changer l'imprimante par déf
cs_globule
Messages postés327Date d'inscriptionmardi 8 octobre 2002StatutMembreDernière intervention 6 octobre 2010
-
4 juin 2008 à 15:06
NHenry
Messages postés15113Date d'inscriptionvendredi 14 mars 2003StatutModérateurDernière intervention22 avril 2024
-
5 juin 2008 à 09:31
Bonjour,
J'ai trouvé le code suivant pour imprimer un RTF
J'ai maintenant besoin de donner la possibilité à l'utilisateur de choisir l'imprimante pour que cela affecte ma fonction " PrintRTF", mais que ca ne change pas l'imprimante par défaut de Windows.
Public Sub PrintRTF(RTF As RichTextBox, LeftMarginWidth As Long, _
TopMarginHeight, RightMarginWidth, BottomMarginHeight)
Dim LeftOffset As Long, TopOffset As Long
Dim LeftMargin As Long, TopMargin As Long
Dim RightMargin As Long, BottomMargin As Long
Dim fr As FormatRange
Dim rcDrawTo As Rect
Dim rcPage As Rect
Dim TextLength As Long
Dim NextCharPosition As Long
Dim r As Long
' Start a print job to get a valid Printer.hDC
Printer.Print Space(1)
Printer.ScaleMode = vbTwips
' Get the offsett to the printable area on the page in twips
LeftOffset = Printer.ScaleX(GetDeviceCaps(Printer.hdc, _
PHYSICALOFFSETX), vbPixels, vbTwips)
TopOffset = Printer.ScaleY(GetDeviceCaps(Printer.hdc, _
PHYSICALOFFSETY), vbPixels, vbTwips)
' Set printable area rect
rcPage.Left = 0
rcPage.Top = 0
rcPage.Right = Printer.ScaleWidth
rcPage.Bottom = Printer.ScaleHeight
' Set rect in which to print (relative to printable area)
rcDrawTo.Left = LeftMargin
rcDrawTo.Top = TopMargin
rcDrawTo.Right = RightMargin
rcDrawTo.Bottom = BottomMargin
' Set up the print instructions
fr.hdc = Printer.hdc ' Use the same DC for measuring and rendering
fr.hdcTarget = Printer.hdc ' Point at printer hDC
fr.rc = rcDrawTo ' Indicate the area on page to draw to
fr.rcPage = rcPage ' Indicate entire size of page
fr.chrg.cpMin = 0 ' Indicate start of text through
fr.chrg.cpMax = -1 ' end of the text
' Get length of text in RTF
TextLength = Len(RTF.Text)
' Loop printing each page until done
Do
' Print the page by sending EM_FORMATRANGE message
NextCharPosition = SendMessage(RTF.hWnd, EM_FORMATRANGE, True, fr)
If NextCharPosition >= TextLength Then Exit Do 'If done then exit
fr.chrg.cpMin = NextCharPosition ' Starting position for next page
Printer.NewPage ' Move on to next page
Printer.Print Space(1) ' Re-initialize hDC
fr.hdc = Printer.hdc
fr.hdcTarget = Printer.hdc
Loop
' Commit the print job
Printer.EndDoc
' Allow the RTF to free up memory
r = SendMessage(RTF.hWnd, EM_FORMATRANGE, False, ByVal CLng(0))
End Sub
J'ai essayé avec
CommonDialog1.PrinterDefault = False
Mais cela n'a aucune incidence sur l'impression suivante
cs_globule
Messages postés327Date d'inscriptionmardi 8 octobre 2002StatutMembreDernière intervention 6 octobre 2010 4 juin 2008 à 18:58
Non, aucune valeur ne donne le nom de l'imprimante sélectionnée par l'utilisateur (il y a de nombreux messages sur les forums à propos de cette aberration)
Vous n’avez pas trouvé la réponse que vous recherchez ?