Chosir l'imprimante pour l'impression en cours SANS changer l'imprimante par déf

cs_globule Messages postés 327 Date d'inscription mardi 8 octobre 2002 Statut Membre Dernière intervention 6 octobre 2010 - 4 juin 2008 à 15:06
NHenry Messages postés 15113 Date d'inscription vendredi 14 mars 2003 Statut Modérateur Dernière intervention 22 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)


   ' Calculate the Left, Top, Right, and Bottom margins
   LeftMargin = LeftMarginWidth - LeftOffset
   TopMargin = TopMarginHeight - TopOffset
   RightMargin = (Printer.Width - RightMarginWidth) - LeftOffset
   BottomMargin = (Printer.Height - BottomMarginHeight) - TopOffset


   ' 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

5 réponses

NHenry Messages postés 15113 Date d'inscription vendredi 14 mars 2003 Statut Modérateur Dernière intervention 22 avril 2024 159
4 juin 2008 à 15:18
Bonjour

Tu as unbe collection "Printers" qui liste les imprimante installées.

Le fer à souder a besoin d'une panne pour fonctionner.
VB (6, .NET1&2), C++, C#.Net1
Mon site
0
cs_globule Messages postés 327 Date d'inscription mardi 8 octobre 2002 Statut Membre Dernière intervention 6 octobre 2010
4 juin 2008 à 15:26
Merci, mais je voudrais passer par un commonDialog,. Quel est l'interet d'un tel composant si on ne peux pas recuperer les valeurs de retour ?

Je reponse donc ma question
Comment recuperer l'imprimante selectionnée par dans un commonDialog
0
NHenry Messages postés 15113 Date d'inscription vendredi 14 mars 2003 Statut Modérateur Dernière intervention 22 avril 2024 159
4 juin 2008 à 15:40
Bonjour

Les valeurs résultantes sont disponibles dans les propriétés du CommonDialog.

Le fer à souder a besoin d'une panne pour fonctionner.
VB (6, .NET1&2), C++, C#.Net1
Mon site
0
cs_globule Messages postés 327 Date d'inscription mardi 8 octobre 2002 Statut Membre Derniè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)
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
NHenry Messages postés 15113 Date d'inscription vendredi 14 mars 2003 Statut Modérateur Dernière intervention 22 avril 2024 159
5 juin 2008 à 09:31
Bonjour

Peut être pas le nom, mais le HdC (si mes souvenirs sont bons).

Le fer à souder a besoin d'une panne pour fonctionner.
VB (6, .NET1&2), C++, C#.Net1
Mon site
0
Rejoignez-nous