Code : Tout sélectionner
;{- Enumerations / DataSections
;{ Windows
Enumeration
#Window_0
EndEnumeration
;}
;{ Gadgets
Enumeration
#Button_Preview
#Button_Print
#CheckBox
#Editor
#Web
EndEnumeration
;}
Define.l Event, EventWindow, EventGadget, EventType, EventMenu
;}
; Constants for the ExecWB Method:
#OLECMDID_PRINT = 6
#OLECMDID_PRINTPREVIEW = 7
#OLECMDEXECOPT_PROMPTUSER = 1
#OLECMDEXECOPT_DONTPROMPTUSER = 2
Procedure.s GetKeyString(HKEY_Folder.l, key.s, Subkey.s)
Protected OpenKey.l, Type.l, cbData.l, *lpbData, ReturnValue.s
cbData = (#MAX_PATH * 2) + 2
*lpbData = AllocateMemory(cbData)
If RegOpenKeyEx_(HKEY_Folder, key, 0, #KEY_ALL_ACCESS, @OpenKey) = #ERROR_SUCCESS
If RegQueryValueEx_(OpenKey, Subkey, 0, @Type, *lpbData, @cbData) = #ERROR_SUCCESS
If Type = #REG_SZ
ReturnValue = PeekS(*lpbData)
EndIf
EndIf
RegCloseKey_(OpenKey)
EndIf
FreeMemory(*lpbData)
ProcedureReturn ReturnValue
EndProcedure
Procedure.l SetKeyString(HKEY_Folder.l, key.s, Subkey.s, Value.s)
Protected OpenKey.l, ReturnValue.l
If RegOpenKeyEx_(HKEY_Folder, key, 0, #KEY_ALL_ACCESS, @OpenKey) = #ERROR_SUCCESS
If RegSetValueEx_(OpenKey, Subkey, 0, #REG_SZ, @Value, Len(Value) + 1) = #ERROR_SUCCESS
ReturnValue = #True
EndIf
RegCloseKey_(OpenKey)
EndIf
ProcedureReturn ReturnValue
EndProcedure
Procedure ModifyIEHeaderFooter(State.l) ; #TRUE : modify , #FALSE : reverse to original
Static FirstTime.l, IEHeader.s, IEFooter.s, IELeft.s, IERight.s, IEBottom.s
If FirstTime = 0
IEHeader = GetKeyString(#HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\PageSetup", "header") ; default : "&w&bPage &p de &P"
IEFooter = GetKeyString(#HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\PageSetup", "footer") ; default : "&u&b&d"
IELeft = GetKeyString(#HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\PageSetup", "margin_left") ; default : "0.750000"
IERight = GetKeyString(#HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\PageSetup", "margin_right") ; default : "0.750000"
IEBottom = GetKeyString(#HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\PageSetup", "margin_bottom") ; default : "0.750000"
FirstTime = 1
EndIf
If State = #True
SetKeyString(#HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\PageSetup", "header", "")
SetKeyString(#HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\PageSetup", "footer", "")
SetKeyString(#HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\PageSetup", "margin_left", IELeft)
SetKeyString(#HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\PageSetup", "margin_right", IERight)
SetKeyString(#HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\PageSetup", "margin_bottom", IEBottom)
Else
SetKeyString(#HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\PageSetup", "header", IEHeader)
SetKeyString(#HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\PageSetup", "footer", IEFooter)
SetKeyString(#HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\PageSetup", "margin_left", IELeft)
SetKeyString(#HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\PageSetup", "margin_right", IERight)
SetKeyString(#HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\PageSetup", "margin_bottom", IEBottom)
EndIf
EndProcedure
Procedure Print_HTML(mode.i = 1)
WebObject.IWebBrowser2 = GetWindowLong_(GadgetID(#Web), #GWL_USERDATA)
Repeat
WebObject\get_Busy(@IsBusy.l)
Delay(1)
While WindowEvent(): Wend
Until IsBusy = 0
Select mode
Case 1
; Ouverture de PrintDlg pour impression
WebObject\ExecWB(#OLECMDID_PRINT, #OLECMDEXECOPT_PROMPTUSER, 0, 0)
Case 2
; Impression directe
WebObject\ExecWB(#OLECMDID_PRINT, #OLECMDEXECOPT_DONTPROMPTUSER, 0, 0)
Case 3
; Aperçu avant impression
WebObject\ExecWB(#OLECMDID_PRINTPREVIEW, #OLECMDEXECOPT_DONTPROMPTUSER, 0, 0)
EndSelect
EndProcedure
Procedure OpenWindow_Window_0()
If OpenWindow(#Window_0, 520, 166, 344, 298, "HTML Print", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_TitleBar|#PB_Window_ScreenCentered|#PB_Window_MaximizeGadget|#PB_Window_MinimizeGadget)
ButtonGadget(#Button_Preview, 15, 255, 90, 30, "Aperçu")
ButtonGadget(#Button_Print, 120, 255, 90, 30, "Imprimer")
CheckBoxGadget(#CheckBox, 225, 255, 105, 30, "Afficher PrintDlg")
EditorGadget(#Editor, 15, 15, 315, 225)
WebGadget(#Web, 0, 0, 10, 10, "")
SetGadgetState(#CheckBox,#PB_Checkbox_Checked)
EndIf
EndProcedure
style$ = "<style>.Break { page-Break-after: always; }</style>" + #CRLF$
html$ = style$ + "<h1>Page 1</h1>" + #CRLF$ + "<div class='Break'></div>" + #CRLF$ + "<h1>Page 2</h1>"
OpenWindow_Window_0()
SetGadgetText(#Editor,html$)
;{- Event loop
Repeat
Event = WaitWindowEvent()
Select Event
; ///////////////////
Case #PB_Event_Gadget
EventGadget = EventGadget()
EventType = EventType()
If EventGadget = #Button_Preview
txt$=GetGadgetText(#Editor)
SetGadgetItemText(#Web,#PB_Web_HtmlCode,txt$)
Print_HTML(3)
ElseIf EventGadget = #Button_Print
txt$=GetGadgetText(#Editor)
SetGadgetItemText(#Web,#PB_Web_HtmlCode,txt$)
If GetGadgetState(#CheckBox)
Print_HTML(1)
Else
Print_HTML(2)
EndIf
EndIf
; ////////////////////////
Case #PB_Event_CloseWindow
EventWindow = EventWindow()
If EventWindow = #Window_0
CloseWindow(#Window_0)
Break
EndIf
EndSelect
ForEver
;
;}
J'ai plus qu'à faire mon modèle en html avec mes variables à remplacer et le tour est joué
depuis le temps que je voulais faire un truc comme çà . En tous cas merci de vos réponses ...