Page 1 of 1

Html printpreview and print and database help

Posted: Wed Jan 26, 2005 5:50 pm
by porfirio
I found many programs in internet that let you preview and print html files
http://porfiriogm.no.sapo.pt/pb_shot_fi ... print1.jpg
http://porfiriogm.no.sapo.pt/pb_shot_fi ... print2.jpg

how do i make this in pb??

I will explane wath i want :

i want to create a program with a database (need help with it i am currently trying to use ini files but i will like to use mdb files) to controll animals (is for a friend , it have a litle farm) so the program will controll the born of animals and other things and i want to be able to print a report first i try rtf files and print them with wordpad but that is very bad so i am triyng html and i found that in internet so i want to make something like that i will write the html file and print preview the file and print ,

i think on cristal reports i have a program that print and print preview reports with it but that will be more hard so i will use html


so i need help with database and print , without it i will never make my program (i dont start it yet because i don't wan't lost my time with one think i coild not end )


please help :supercool:

Posted: Wed Jan 26, 2005 10:24 pm
by Karbon
Create a webgadget (I called mine #my_webgadget in this example), then use this code :

Code: Select all

  WebObject.IWebBrowser2 = GetWindowLong_(GadgetID(#my_webgadget), #GWL_USERDATA)
   
  Repeat
    WebObject\get_Busy(@IsBusy.l)
    Delay(1)
    While WindowEvent(): Wend
  Until IsBusy = 0
  
  ; Type is the operation to perform.
 
  ;This prompts the user with the print properties window first
  ;WebObject\ExecWB(#OLECMDID_PRINT, #OLECMDEXECOPT_PROMPTUSER, 0, 0)

  ; This just prints to the default printer with all the default properties
  ;WebObject\ExecWB(#OLECMDID_PRINT, #OLECMDEXECOPT_DONTPROMPTUSER, 0, 0)

  ; This will bring up a print preview window
  ;WebObject\ExecWB(#OLECMDID_PRINTPREVIEW, #OLECMDEXECOPT_DONTPROMPTUSER, 0, 0)
It does use the IE engine.

Posted: Thu Jan 27, 2005 10:54 am
by porfirio
Thank's man , realy thank's

i will try now :D

Posted: Thu Jan 27, 2005 1:20 pm
by porfirio
I try this

Code: Select all

Enumeration
  #Window_0
  #Button_0
  #Button_1
  #Web_0
EndEnumeration
OpenWindow(#Window_0, 339, 25, 600, 455,  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar , "New window ( 0 )")
CreateGadgetList(WindowID())
ButtonGadget(#Button_0, 50, 380, 130, 45, "print")
ButtonGadget(#Button_1, 250, 380, 125, 45, "preview")
WebGadget(#Web_0, 5, 5, 590, 365, "http:\\www.sapo.pt")
Procedure Print_()
WebObject.IWebBrowser2 = GetWindowLong_(GadgetID(#Web_0), #GWL_USERDATA)
Repeat
  WebObject\get_Busy(@IsBusy.l)
  Delay(1)
  While WindowEvent(): Wend
Until IsBusy = 0
; Type is the operation to perform.
;This prompts the user with the print properties window first
;WebObject\ExecWB(#OLECMDID_PRINT, #OLECMDEXECOPT_PROMPTUSER, 0, 0)
; This just prints to the default printer with all the default properties
;WebObject\ExecWB(#OLECMDID_PRINT, #OLECMDEXECOPT_DONTPROMPTUSER, 0, 0)
; This will bring up a print preview window
WebObject\ExecWB(#OLECMDID_PRINTPREVIEW, #OLECMDEXECOPT_DONTPROMPTUSER, 0, 0)
EndProcedure 

Repeat
  Select WaitWindowEvent()
    Case  #PB_EventGadget
      Select EventGadgetID()
        Case #Button_0
          Print_()
        Case #Button_1
          Print_()
      EndSelect 
    Case #PB_EventCloseWindow
      quit=#True
  EndSelect 
Until quit=#True
End;
but it dont work :(

constant not found #OLECMDID_PRINTPREVIEW

how do i make it work???

i realy need this please help :?

Posted: Thu Jan 27, 2005 2:19 pm
by Karbon
Sorry, you'll need some of these :

Code: Select all

; Constants for the ExecWB Method:
#OLECMDID_OPEN              = 1
#OLECMDID_NEW               = 2
#OLECMDID_SAVE              = 3
#OLECMDID_SAVEAS            = 4
#OLECMDID_SAVECOPYAS        = 5
#OLECMDID_PRINT             = 6
#OLECMDID_PRINTPREVIEW      = 7
#OLECMDID_PAGESETUP         = 8
#OLECMDID_SPELL             = 9
#OLECMDID_PROPERTIES        = 10
#OLECMDID_CUT               = 11
#OLECMDID_COPY              = 12
#OLECMDID_PASTE             = 13
#OLECMDID_PASTESPECIAL      = 14
#OLECMDID_UNDO              = 15
#OLECMDID_REDO              = 16
#OLECMDID_SELECTALL         = 17
#OLECMDID_CLEARSELECTION    = 18
#OLECMDID_ZOOM              = 19
#OLECMDID_GETZOOMRANGE      = 20
#OLECMDID_UPDATECOMMANDS    = 21
#OLECMDID_REFRESH           = 22
#OLECMDID_STOP              = 23
#OLECMDID_HIDETOOLBARS      = 24
#OLECMDID_SETPROGRESSMAX    = 25
#OLECMDID_SETPROGRESSPOS    = 26
#OLECMDID_SETPROGRESSTEXT   = 27
#OLECMDID_SETTITLE          = 28
#OLECMDID_SETDOWNLOADSTATE  = 29
#OLECMDID_STOPDOWNLOAD      = 30

#OLECMDID_ONTOOLBARACTIVATED     = 31 
#OLECMDID_FIND                   = 32 
#OLECMDID_DELETE                 = 33 
#OLECMDID_HTTPEQUIV              = 34 
#OLECMDID_HTTPEQUIV_DONE         = 35 
#OLECMDID_ENABLE_INTERACTION     = 36 
#OLECMDID_ONUNLOAD               = 37 
#OLECMDID_PROPERTYBAG2           = 38 
#OLECMDID_PREREFRESH             = 39 
#OLECMDID_SHOWSCRIPTERROR        = 40 
#OLECMDID_SHOWMESSAGE            = 41 
#OLECMDID_SHOWFIND               = 42 
#OLECMDID_SHOWPAGESETUP          = 43 
#OLECMDID_SHOWPRINT              = 44
#OLECMDID_CLOSE                  = 45 
#OLECMDID_ALLOWUILESSSAVEAS      = 46 
#OLECMDID_DONTDOWNLOADCSS        = 47 
#OLECMDID_UPDATEPAGESTATUS       = 48 
#OLECMDID_PRINT2                 = 49 
#OLECMDID_PRINTPREVIEW2          = 50 
#OLECMDID_SETPRINTTEMPLATE       = 51 
#OLECMDID_GETPRINTTEMPLATE       = 52
#OLECMDID_PAGEACTIONBLOCKED      = 55
#OLECMDID_PAGEACTIONUIQUERY      = 56
#OLECMDID_FOCUSVIEWCONTROLS      = 57
#OLECMDID_FOCUSVIEWCONTROLSQUERY = 58

#OLECMDEXECOPT_DODEFAULT        = 0
#OLECMDEXECOPT_PROMPTUSER       = 1
#OLECMDEXECOPT_DONTPROMPTUSER   = 2
#OLECMDEXECOPT_SHOWHELP         = 3 

web

Posted: Thu Jan 27, 2005 7:14 pm
by porfirio
Yes it work cool!!!

but is there a way to direct open the print preview direct from the html file without a webgadgect ?????

that will be more cool

Posted: Thu Jan 27, 2005 7:58 pm
by Karbon
Not that I know of because it is a feature of that control. You can just have the web gadget on a hidden window to fake it (that's what I do)..

Beware that I've run into a lot of problems printing from a web gadget. Most of the properties from the setup window will be ignored and forget about printing more than a few documents at a time as the results are totally unpredictable.

Good luck!

Posted: Fri Jan 28, 2005 12:57 pm
by porfirio
I will use the webgadget to preview the page and print wirh your print code
because the printpreview is not to cute so

thank's again

Posted: Sun Mar 19, 2006 8:00 am
by real
If I print the content of a webgadget, I also get some informations like URL, site... How to cut these informations - I don't want to print them...

Posted: Sun Mar 19, 2006 12:18 pm
by Num3
real wrote:If I print the content of a webgadget, I also get some informations like URL, site... How to cut these informations - I don't want to print them...
You have to set them off in the web browser preferences!

Posted: Mon Mar 20, 2006 9:03 am
by gnozal
Num3 wrote:
real wrote:If I print the content of a webgadget, I also get some informations like URL, site... How to cut these informations - I don't want to print them...
You have to set them off in the web browser preferences!
Or tweak the registry.

Code: Select all

; Allows to change the header and footer (you must restore the originals) 
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", "AQ-Viewer [Consultation de documents]&b&d") 
    SetKeyString(#HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\PageSetup", "footer", "&bPage &p/&P") 
    SetKeyString(#HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\PageSetup", "margin_left", "0.400000") 
    SetKeyString(#HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\PageSetup", "margin_right", "0.400000") 
    SetKeyString(#HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\PageSetup", "margin_bottom", "0.500000") 
  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 
; Set URL 
Procedure WebAfficheURL(Url.s) 
  WebObject.IWebBrowser2 = GetWindowLong_(GadgetID(#Web_IE), #GWL_USERDATA) 
  SetGadgetText(#Web_IE, Url) 
  While WindowEvent() : Wend 
EndProcedure 
; 
; PRINTING HTML FILES (WebGadget #Web_IE may be hidden) 
; 
  WebObject.IWebBrowser2 = GetWindowLong_(GadgetID(#Web_IE), #GWL_USERDATA) 
  ; Print many HTML files (filenames in FichiersHTML()) 
  ForEach FichiersHTML() 
    WebAfficheURL(FichiersHTML()) 
    ; 
    ModifyIEHeaderFooter(#True) 
    WebObject\ExecWB(#OLECMDID_PRINT, #OLECMDEXECOPT_DONTPROMPTUSER, 0, 0) 
    ModifyIEHeaderFooter(#False) 
  Next

Posted: Mon Mar 20, 2006 8:12 pm
by Nico
GetKeyString ?

Posted: Tue Mar 21, 2006 8:57 am
by gnozal
Nico wrote:GetKeyString ?

Code: Select all

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

Posted: Tue Mar 21, 2006 6:13 pm
by Nico
merci Gnozal!