Avec XP, je n'ai pas de différence.
Code : Tout sélectionner
;COMMANDES
;Tous les placements de texte sont en millimètres ( sauf chiffres négatif)
;MLD_impFont(nomfont$,grd.l,opt1.l,opt2.l,opt3.l,coul.l)
;MLD_impDrawText(mmhz ,mmvert,"txt") écrit une ligne
; si mmhz = -1 imprime aprés le dernier texte
; si mmhz = -2 centre le texte
; si mmvert = -1 garde la même ligne de texte
; si mmvert = -2 met un interligne (calcul automatique en fonction de la police)
;MLD_impcadre(X.l,Y.l,L.l,H.l,coul) trace un cadre, indiquez des millimètres
;MLD_impline(X.l,Y.l,L.l,H.l,coul) trace une ligne horizontale, indiquez des millimètres
;MLD_implinevert(X.l,Y.l,X2.l,Y2.l,coul) trace une ligne verticale Y2 en mm = destination
;MLD_impFormatmonnaie(X.l,Y.l,valeur$,syb$,masque$)
; si X.l = -1 imprime après le dernier texte
; masque$ peut s'écrire comme ceci "### ### ###,##" pas plus de 2 chiffres après la virgule
Declare nbDPI()
Declare mmlH(nbmm.l)
Declare mmlV(nbmm.l)
Declare MLD_impFont(nomfont$,grd.l,opt1.l,opt2.l,opt3.l,coul.l)
Declare Intlig()
Declare MLD_impDrawText(hz.l,ht.l,txt$)
Declare MLD_impcadre(X.l,Y.l,L.l,H.l,coul)
Declare MLD_impline(X.l,Y.l,L.l,H.l,coul)
Declare MLD_implinevert(X.l,Y.l,Y2.l,coul)
Declare MLD_impFormatmonnaie(X.l,Y.l,valeur$,syb$,masque$)
Declare imp()
Global FontID1
Global DPIHZ.l,MGH.l,Lgmax.l
Global DPIVT.l,MGV.l,Htmax.l
Global Ecrdpihz.l,Ecrdpivt.l
Global largtxt.l,lig.l,poshz.l
Procedure nbDPI();initialisation
hdc = GetDC_(GetDesktopWindow_())
If hdc :Ecrdpihz.l = GetDeviceCaps_(hdc, #LOGPIXELSX) :EndIf
If hdc :Ecrdpivt.l = GetDeviceCaps_(hdc, #LOGPIXELSY) : ReleaseDC_(GetDesktopWindow_(), hdc) : EndIf
If DefaultPrinter() <> 0
printer_DC.l = StartDrawing(PrinterOutput())
DPIHZ.l = GetDeviceCaps_(printer_DC,#LOGPIXELSX)
DPIVT.l = GetDeviceCaps_(printer_DC,#LOGPIXELSY)
MGH.l = GetDeviceCaps_(printer_DC,#PHYSICALOFFSETX)
MGV.l = GetDeviceCaps_(printer_DC,#PHYSICALOFFSETY)
;MGV.l = 40
; =================2 Fois les marges===========================
Lgmax.l = GetDeviceCaps_(printer_DC,#PHYSICALWIDTH) - 2*MGH.l
Htmax.l = GetDeviceCaps_(printer_DC,#PHYSICALHEIGHT) - 2*MGV.l
;==============================================================
PhysW.l=GetDeviceCaps_(printer_DC,#PHYSICALWIDTH)
PhysH.l=GetDeviceCaps_(printer_DC,#PHYSICALHEIGHT)
StopDrawing()
; Debug Ecrdpihz
; Debug Ecrdpivt
Debug "DPI"
Debug DPIHZ
Debug DPIVT
Debug ""
Debug "PHYSIC en point imprimante"
;2.54cm=1pouce
Debug PhysW ;(21cm/2.54)*DPI
Debug PhysH ;(29.7cm/2.54)*DPI
Debug "PHYSIC en cm"
;2.54cm=1pouce
Debug PhysW*2.54/DPIHZ ;(21cm/2.54)*DPI
Debug PhysH*2.54/DPIVT ;(29.7cm/2.54)*DPI
Debug ""
Debug "MARGE MATERIEL en point imprimante"
Debug MGH ;(marge cm/2.54)*DPI
Debug MGV ;(marge cm/2.54)*DPI
Debug "MARGE MATERIEL en cm"
Debug MGH*2.54/DPIHZ
Debug MGV*2.54/DPIVT
Debug ""
Debug "zone imprimable: PHYSIC - 2*MARGE MATERIEL en point imprimante"
Debug Lgmax
Debug Htmax
Debug "zone imprimable:PHYSIC - 2*MARGE MATERIEL en cm"
Debug Lgmax*2.54/DPIHZ
Debug Htmax *2.54/DPIVT
Debug ""
Debug "PB zone d'impression en pixels."
Debug PrinterPageWidth()
Debug PrinterPageHeight()
EndIf
EndProcedure
nbDPI()
Procedure MLD_impFont(nomfont$,grd.l,opt1.l,opt2.l,opt3.l,coul.l)
StopDrawing()
K.l = DPIHZ.l/Ecrdpihz.l
FontID1 = LoadFont(1,nomfont$,grd * K,opt1.l | opt2.l | opt3.l)
StartDrawing(PrinterOutput())
DrawingMode(#PB_2DDrawing_Transparent)
FrontColor(coul.l)
DrawingFont(FontID(1))
EndProcedure
Procedure mmlH(nbmm.l)
res.l = ((DPIHZ.l * nbmm.l) / 25.4) - MGH.l
If res.l <= MGH.l ;pour ne pas être < a la marge imposée
res.l = MGH.l
EndIf
If res.l => Lgmax.l
res.l = Lgmax.l ;pour ne pas être > a la marge imposée a droite de la feuille
EndIf
poshz.l = res.l + largtxt.l;* 25.4 /DPIHZ.l
ProcedureReturn res
EndProcedure
Procedure mmlV(nbmm.l)
res.l = ((DPIVT.l * nbmm.l) / 25.4) - MGV.l
If res.l <= MGV.l ;pour ne pas être < a la marge imposée en haut
res.l = MGV.l
EndIf
If res.l => Htmax.l
res.l = Htmax.l ;pour ne pas être > a la marge imposée en bas de la feuille
EndIf
lig.l = res.l ;en pixels
ProcedureReturn res
EndProcedure
Procedure Intlig()
If TextHeight("AW") <= 43;en pixel
kintlig.l = 1.3
Else
kintlig.l = 1.4
EndIf
Interlig.l = TextHeight("AW")/kintlig.l
res.l = lig.l + Interlig.l
lig.l = res;en pixel
ProcedureReturn res.l
EndProcedure
Procedure MLD_cadre(X.l,Y.l,L.l,H.l,coul)
DrawingMode(#PB_2DDrawing_Transparent)
DrawingMode(#PB_2DDrawing_Outlined)
larg .l = (DPIHZ.l * L.l) / 25.4
haut.l = (DPIVT.l * H.l) / 25.4
Box(mmlH(X.l),mmlV(Y.l),larg .l,haut.l,coul)
EndProcedure
Procedure MLD_line(X.l,Y.l,L.l,H.l,coul)
DrawingMode(#PB_2DDrawing_Transparent)
larg .l = (DPIHZ.l * L.l) / 25.4
haut.l = (DPIVT.l * H.l) / 25.4
Line(mmlH(X.l),mmlV(Y.l),larg .l,haut.l,coul)
EndProcedure
Procedure MLD_linevert(X.l,Y.l,Y2.l,coul)
DrawingMode(#PB_2DDrawing_Transparent)
hz2 .l = (DPIVT.l * X.l) / 25.4
haut2.l = (DPIVT.l * Y2.l) / 25.4
LineXY(mmlH(X.l),mmlV(Y.l),mmlH(X2.l),mmlV(Y2.l),coul)
EndProcedure
Procedure MLD_impFormatmonnaie(X.l,Y.l,valeur$,syb$,masque$)
If X.l = -1
X.l = (poshz.l + MGH.l) * 25.4/DPIHZ.l
EndIf
If masque$ <> ""
masque$ = masque$ + "." + syb$
xmax.l = X.l + (TextWidth(masque$) * 25.4/DPIHZ.l)
EndIf
ind = 0
ReplaceString(valeur$, ".", ",", #PB_String_InPlace, 1)
For zz.w = Len(valeur$) To 1 Step -1
ind = ind + 1
valeur2$ = valeur2$ + Mid(valeur$,zz,1)
If Mid(valeur$,zz,1) = "," : ind = 0 :EndIf
If ind = 3
ind = 0
If Mid(valeur$,zz,1) <> ","
valeur2$ = valeur2$ + " "
EndIf
EndIf
Next
txt$ = ReverseString(valeur2$) + "." + syb$
If masque$ <> ""
posd.l = xmax.l - (TextWidth(ReverseString(valeur2$) + "." + syb$) * 25.4/DPIHZ.l)
If posd.l < X.l:posd.l = X.l:EndIf
Else
posd.l = X.l
EndIf
MLD_impDrawText(posd.l,Y.l,txt$)
EndProcedure
Procedure MLD_impDrawText(hz.l,ht.l,txt$)
DrawingMode(#PB_2DDrawing_Transparent)
largtxt.l = TextWidth(txt$);en pixel
Select hz.l
Case -1 ;écrit a la fin du dernier texte
chz.l = poshz.l
Case -2 ;centre
chz.l = ((Lgmax - MGH.l) - TextWidth(txt$))/2
Default
chz.l = mmlH(hz.l);déplacement horizontal
EndSelect
Select ht.l
Case -1 ; reste sur la même ligne
cht.l = lig.l
Case -2 ;interligne
cht.l = Intlig()
Default
cht.l = mmlV(ht.l); déplacement vertical
EndSelect
DrawText(chz.l,cht.l,txt$)
EndProcedure
;¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ DEMO ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
Procedure imp1()
L1$ = "Marcel BAVARD"
L2$ = "AVOCAT AU BARREAU DE PARIS"
L3$ = "15 rue du Rire 75001 Paris"
L4$ = "Tel : 01 01 01 01 10 FAX : 01 01 01 01 11 Mail : bavardavocat@wanadoo.fr"
L5$ = "n° siret : 12345671547645 n° TVA intracom FR89439376"
L6$ = "Membre d’une Association Agréée. Le règlement des honoraires par chèque est accepté."
L7$ = "Spécialiste du droit des affaires"
If DefaultPrinter() <> 0
If StartPrinting("Mic")
StartDrawing(PrinterOutput())
MLD_impFont("Times New Roman",20,#PB_Font_HighQuality,#PB_Font_Bold,0,$0)
MLD_impDrawText(15,20,L1$)
MLD_impDrawText(0,-2,"")
MLD_impFont("Times New Roman",14,#PB_Font_HighQuality,0,0,$0)
MLD_impDrawText(15,-2,L2$)
MLD_impDrawText(0,-2,"")
MLD_impFont("Times New Roman",10,#PB_Font_HighQuality,0,0,$0)
MLD_impDrawText(15,-2,L7$)
MLD_impFont("Times New Roman",14,#PB_Font_HighQuality,0,0,$0)
MLD_impDrawText(-2,265,L3$)
MLD_impDrawText(-2,-2,L4$)
MLD_impDrawText(0,-2,"")
MLD_impFont("Times New Roman",8,#PB_Font_HighQuality,0,0,$0)
MLD_impDrawText(-2,-2,L5$)
MLD_impDrawText(-2,-2,L6$)
StopDrawing()
StopPrinting()
EndIf
EndIf
EndProcedure
Procedure imp2()
L1$ = "Michel DUCHIEN Amélie LECHAT"
L2$ = " Docteur vétérinaire diplomés de l'école d'Alfort"
L3$ = "Rennes le :" + FormatDate("%dd / %mm / %yyyy", Date())
L4$ = "Madame, Monsieur"
L5$ = " Nous vous informons que la date de vaccination de votre chien MEDOR arrive."
L6$ = " Pour une parfaite santé de votre animal, il serait souhaitable de prendre rendez vous"
L7$ = " auprés de la clinique sous quinzaine."
L8$ = " Nous praticons un tarif forfaitaire de vaccination de TTC : "
L9$ = "45.35"
L10$ = "Restant a votre entière disposition."
L11$ = "Les Vétérinaires"
L12$ = "Clinique vétérinaire du Bison futé 7 rue du Grand singe 35000 Rennes"
L13$ = " Ouverture du lundi au samedi de 9H a 18H Tel : 01 01 01 01 10 FAX : 01 01 01 01 11 "
L14$ = "n° siret : 12345671547645 n° TVA intracom FR89439376"
L15$ = "Membre d’une Association Agréée. Le règlement des honoraires par chèque est accepté."
If DefaultPrinter() <> 0
If StartPrinting("Mic")
StartDrawing(PrinterOutput())
MLD_impFont("Georgia",18,#PB_Font_HighQuality,#PB_Font_Bold,0,$8B453B)
MLD_impDrawText(-2,20,L1$)
MLD_impDrawText(0,-2,"")
MLD_impFont("Georgia",14,#PB_Font_HighQuality,0,0,$8B453B)
MLD_impDrawText(-2,-2,L2$)
MLD_impFont("Times New Roman",14,#PB_Font_HighQuality,0,0,$0)
MLD_impDrawText(130,80,L3$)
MLD_impDrawText(30,110,L4$)
MLD_impDrawText(20,125,L5$)
MLD_impDrawText(0,-2,"")
MLD_impDrawText(20,-2,L6$)
MLD_impDrawText(20,-2,L7$)
MLD_impDrawText(0,-2,"")
MLD_impDrawText(20,-2,L8$):MLD_impFormatmonnaie(-1,-1,L9$,"€","")
MLD_impDrawText(0,-2,"")
MLD_impDrawText(20,-2,L10$)
MLD_impDrawText(130,190,L11$)
MLD_impFont("Times New Roman",10,#PB_Font_HighQuality,0,0,$0)
MLD_impDrawText(-2,265,L12$)
MLD_impDrawText(-2,-2,L13$)
MLD_impDrawText(0,-2,"")
MLD_impFont("Times New Roman",8,#PB_Font_HighQuality,0,0,$0)
MLD_impDrawText(-2,-2,L14$)
MLD_impDrawText(-2,-2,L15$)
StopDrawing()
StopPrinting()
EndIf
EndIf
EndProcedure
Enumeration
#btess1
#btess2
EndEnumeration
OpenWindow(1, 0, 0, 300, 200, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget)
ButtonGadget(#btess1, 80, 50,150,30,"Test Imprimante 1")
ButtonGadget(#btess2, 80, 100,150,30,"Test Imprimante 2")
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
Select EventGadget() ; Gadgets
Case #btess1
imp1()
Case #btess2
imp2()
EndSelect
EndSelect
Until Event = #PB_Event_CloseWindow
End
M.