Je cherche à charger un Fichier RTF dans un editorgadget et à l'imprimer . J'ai le code qui fait tous çà (code de Flype).Mon fichier contient un tableau et malgré le fait que le contenu soit centré dans les cellules (créér avec OOO),lors du chargement le contenus des cellules est aligné a gauche.J'ai essayer 3 méthode pour charger le RTF mais çà ne change rien . Si vous avez une petite idée ?
voici le code de Flype retouché (très) vite fais :
Code : Tout sélectionner
;/
;/
Structure textlength
flags.w
CodePage.b
EndStructure
Structure DInfo1
cbSize.l
lpszDocName.l
lpszOutput.l
lpszDataType.l
fwType.w
EndStructure
;/
;/
Procedure EditCallBack_Lecture(dwCookie.l, *pbBuff.l, cb.l, *pcb.l)
If ReadFile_(dwCookie, *pbBuff, cb, *pcb, 0)
ProcedureReturn 0
Else
ProcedureReturn 1
EndIf
EndProcedure
Procedure RichEditPrint(Gadget.l,document.s,setup.b)
lppd.PRINTDLG
lppd\lStructSize = SizeOf(PRINTDLG)
lppd\flags = #PD_ALLPAGES|#PD_HIDEPRINTTOFILE|#PD_NOSELECTION|#PD_RETURNDC|#PD_PRINTSETUP
If setup = 0
lppd\flags | #PD_RETURNDEFAULT
EndIf
If PrintDlg_(lppd) = 0
ProcedureReturn
EndIf
If lppd\hdc = -1
ProcedureReturn
EndIf
*Pointer.DEVMODE = GlobalLock_(lppd\hDevMode)
paperlength = *Pointer\dmPaperLength
paperwidth = *Pointer\dmPaperWidth
ppmm.f = (*Pointer\dmYResolution/10)/2.54
GlobalFree_(lppd\hDevMode)
Docinfo.DInfo1
Docinfo\cbSize = SizeOf(DInfo1)
Docinfo\lpszDocName = @document.s
Result = StartDoc_(lppd\hdc,Docinfo)
leftmargin = 1
rightmargin = 1
topmargin = 1
bottommargin = 1
long.textlength
long\flags = 0
MaxLen = SendMessage_(GadgetID(Gadget),#EM_GETTEXTLENGTHEX,@long,0); à modifier
OldMapMode = GetMapMode_(lppd\hdc)
SetMapMode_(lppd\hdc,#MM_TWIPS)
OffsetX = leftmargin*ppmm.f-GetDeviceCaps_(lppd\hdc,#PHYSICALOFFSETX)
If OffsetX < GetDeviceCaps_(lppd\hdc,#PHYSICALOFFSETX)
OffsetX = GetDeviceCaps_(lppd\hdc,#PHYSICALOFFSETX)
EndIf
OffsetY=-topmargin*ppmm.f+GetDeviceCaps_(lppd\hdc,#PHYSICALOFFSETY)
If OffsetY > -GetDeviceCaps_(lppd\hdc,#PHYSICALOFFSETY)
OffsetY = -GetDeviceCaps_(lppd\hdc,#PHYSICALOFFSETY)
EndIf
HorzRes=((paperwidth/10-rightmargin))*ppmm.f
If HorzRes > GetDeviceCaps_(lppd\hdc,#HORZRES)
HorzRes = GetDeviceCaps_(lppd\hdc,#HORZRES)
EndIf
VertRes=-(paperlength/10)*ppmm.f+bottommargin*ppmm.f
If VertRes < -GetDeviceCaps_(lppd\hdc,#VERTRES)
VertRes = -GetDeviceCaps_(lppd\hdc,#VERTRES)
EndIf
cRect.RECT
SetRect_(cRect,OffsetX,OffsetY,HorzRes,VertRes)
DPtoLP_(lppd\hdc,cRect,2)
SetMapMode_(lppd\hdc,OldMapMode)
FormatRange.FORMATRANGE
FormatRange\hdc = lppd\hdc
FormatRange\hdcTarget = lppd\hdc
FormatRange\rc\left = cRect\left
FormatRange\rc\top = cRect\top
FormatRange\rc\right = cRect\right
FormatRange\rc\bottom = cRect\bottom
FormatRange\rcPage\left = cRect\left
FormatRange\rcPage\top = cRect\top
FormatRange\rcPage\right = cRect\right
FormatRange\rcPage\bottom = cRect\bottom
Repeat
Result=StartPage_(lppd\hdc)
FormatRange\chrg\cpMax = -1
LastChar = SendMessage_(GadgetID(Gadget),#EM_FORMATRANGE,#True,@FormatRange) ; à modifier
FormatRange\chrg\cpMin = LastChar
SendMessage_(GadgetID(Gadget),#EM_DISPLAYBAND,0,cRect); à modifier
EndPage_(lppd\hdc)
Until LastChar >= MaxLen Or LastChar < 0
EndDoc_(lppd\hdc)
SendMessage_(GadgetID(Gadget),#EM_FORMATRANGE,0,0)
EndProcedure
;/
;/
pw=52
ph=37
ww=pw*15+20
wh=ph*15+50
If OpenWindow(0,0,0,ww,wh,"Etiquette ( 52mm x 37mm )",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)=0:End:EndIf
If CreateGadgetList(WindowID(0))=0:End:EndIf
hBrush=CreateSolidBrush_($80D0D0)
SetClassLong_(WindowID(0),#GCL_HBRBACKGROUND,hBrush)
EditorGadget(0,10,10,pw*15,ph*15)
ButtonGadget(1,10,wh-30,80,22,"Configuration")
ButtonGadget(2,ww-90,wh-30,80,22,"Imprimer")
file$ = OpenFileRequester("Ouvrir un fichier rtf", "c:\","*.*|*.*", 0)
If file$<>""
hFile=OpenFile(1, file$)
Edit.EDITSTREAM
Edit\dwCookie=hFile
Edit\pfnCallback=@EditCallBack_Lecture()
SendMessage_(GadgetID(0),#EM_STREAMIN,#SF_RTF,Edit)
If Edit\dwError=0
Debug "La lecture s'est bien déroulée"
Else
Debug "La lecture du fichier a provoqué une erreur"
EndIf
CloseFile(1)
EndIf
;/
;/
While 1
Select WaitWindowEvent()
Case #PB_Event_CloseWindow : Break
Case #PB_Event_Gadget
Select EventGadget()
Case 1 : RichEditPrint(0,"richedit_temp",#True)
Case 2 : RichEditPrint(0,"richedit_temp",#False)
EndSelect
EndSelect
Wend