April 28, 2024, 07:44:02 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Getting a little frustrated.

Started by Jim Scott, February 21, 2007, 07:56:58 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Jim Scott

I've been spinning my wheels trying to develop the printing features of my program in EBASIC.  I'll lay out the options I've got, as I see them, and maybe someone here can help me break the log jam.

1) Rich Edit Control

All of my printing needs would be taken care of using the Rich Text Format specification.  I've gone to school on the spec, as Paul suggested and have found it to be rich in possibility.  The problem is that in EBASIC the page orientation and margin commands seem to be ignored.  This doesn't work since I can't have my users manually set the default printer's margins. They can only set the default printer properties to Landscape mode.  Not acceptable.

2) WordPad as Print Driver (and preview engine)

I could use RTF and send this to WordPad using the SYSTEM function.  I found a command line parameter to use with WordPad to print in the background. 

System("WordPad.exe","Path\\filename /p") seems to work.

The problem with this is that I would have to have my users manually set the page orientation and margin settings within WordPad.  Also not acceptable.

3) StarOffice or OpenOffice as a Print Driver (and preview engine)

System("Soffice.exe","-invisible -p path\\filename") seems to work because the page orientation and margin settings are not ignored by StarWriter, and the -invisible option allows printing in the background.  But then I need to install OpenOffice on my user's computers. Acceptable by me, but not elegant.

4) Ddoc program by Don Diciknson

I've downloaded the evaluation version and this has promise.  Although, it would require a complete rewrite of all my RTF forms into ddoc commands.  I can live with this if I can get a license. The problem is that I can't get it to print without the printer selection dialog.  In addition it appears that the ddoc product is not being sold since I've gotten no response since trying to buy it, twice.

I'll reform the two fundamental questions here.

1).  How do I set the margins and orientation of the default printer.

2).  How do I print Rich Edit Control contents without the printer dialog popup.

Am I asking too much?  Not providing enough Info?  Need cash?   Help!

Thanks,

Jim Scott

Jim Scott

mrainey

Jim,

I clipped this section out from the ddoc html help.



dpEndDoc

Declare Sub dpEndDoc Lib "ddoc32.dll" _
   ( ByVal iHandle%, ByVal iOptions% )

This routine tells the display engine that you are done creating your document. The iOptions% parameter lets the engine know what you want to do with the document. You can:

   1. display it on the screen in a preview window
   2. print it directly to the printer
   3. store it in a file without displaying or printing it
   4. e-mail the document via mapi mail
   5. fax the document via mapi fax

Also, the DDOC_END_DELETE flag may be set. This tells the viewer to delete the document after the viewer closes. To abort a document (if the user presses your "cancel" button) pass DDOC_END_DELETE + DDOC_END_CLOSE. This tells the display engine not to print or view the document and to delete it immediately.

Parameter Description
iHandle% Handle to the document as returned by dpStartDoc
iOptions One of the following constants:

    * DDOC_END_PRINT
    * DDOC_END_VIEW
    * DDOC_END_CLOSE
    * DDOC_END_EMAIL
    * DDOC_END_FAX
    * DDOC_END_PRINT_NODIALOG
    * DDOC_END_SPECIFIC_PRINTER

Optionally, add in DDOC_END_DELETE to kill the document after viewing, printing, e-mailing, faxing, or closing




I tried this as the last line in my printing sub, it printed directly to my default printer with no preview and no printer dialog.

dpEndDoc(ThreadPrint,DDOC_END_PRINT_NODIALOG + DDOC_END_DELETE)


Software For Metalworking
http://closetolerancesoftware.com

Doc

Hello Jim,

I obviously don't know how much data you are trying to print, but have you considered sending the output to a new window with an embedded browser attached? Several possibilities exist with this approach if you mix in some CSS styling to control the margins as you wish.

A. Output both the CSS rules and data directly to the browser from within your program.
B. Add a stylesheet as a resource file and let the browser read it directly from the exectuable
C. Various combinations of the above.

As a side benefit, the browser works well as a preview screen and depending on the CSS rules you use, it can even be used to add zoom in / zoom out features, complete with a built in popup menu for printing.

...may not exactly be appropriate for what you are trying to do, but it is another option at least. ;)

-Doc-

Ionic Wind Support Team

Quote
1).  How do I set the margins and orientation of the default printer.

The command @RTPRINT has an optional parameter to set the margin size.  See Users Guide -> Windows Programming -> Controls -> Using Rich Edit controls

Quote
CONTROLCMD window | dialog, ID, @RTPRINT {, margin}
Opens the standard print dialog and prints the contents of the rich edit control. Optional margin value specifies the printer margin in twips. 1440 twips = 1 inch. Default margin is 1/2 inch.

At least it will let you control the overall margin

Quote
How do I print Rich Edit Control contents without the printer dialog popup.

You can't, at least not in the current implementation.  You see printing in Windows is one of the most perverse and backwards programming you will ever do.  It works but requires gobs of code to get anything to look quite right.  It is probably the biggest stumbling block programmers face when writing applications for Windows and we all hate to do it.  Even someone like me that has been slinging Microsoft code since 1992.

Here is the actual subroutine used to print the contents of a Rich Edit control.  Since there really isn't anything built in by Microsoft except for the EM_FORMATRANGE message...


SUB RTPrint(hControl as UINT,margin as INT)
DEF pd as PRINTDLG
DEF fr as FORMATRANGE
DEF di as DOCINFO
ZeroMemory(pd,LEN(PRINTDLG))
ZeroMemory(fr,LEN(FORMATRANGE))
ZeroMemory(di, LEN(DOCINFO))

pd.lStructSize = LEN(PRINTDLG)
pd.Flags = PD_ALLPAGES | PD_USEDEVMODECOPIES | PD_HIDEPRINTTOFILE | PD_NOSELECTION | PD_RETURNDC
pd.hwndOwner = hControl
IF PrintDlg(pd) <> 0
_fpreset()
nHorizRes = GetDeviceCaps(pd.hdc, HORZRES)
nVertRes = GetDeviceCaps(pd.hdc, VERTRES)
nLogPixelsX = GetDeviceCaps(pd.hdc, LOGPIXELSX)
nLogPixelsY = GetDeviceCaps(pd.hdc, LOGPIXELSY)
lTextLength = 0
lTextPrinted = 0

SetMapMode ( pd.hdc, MM_TEXT )

  '// Rendering to the same DC we are measuring.
fr.hdc = pd.hdc
fr.hdcTarget = pd.hdc

  '// Set up the page.
fr.rcPage.left = 0
fr.rcPage.top = 0
fr.rcPage.right    = (nHorizRes/nLogPixelsX) * 1440
fr.rcPage.bottom   = (nVertRes/nLogPixelsY) * 1440

  '// Set up margins all around.
fr.rc.left   = fr.rcPage.left + margin
fr.rc.top    = fr.rcPage.top + margin
fr.rc.right  = fr.rcPage.right - margin
fr.rc.bottom = fr.rcPage.bottom - margin

  '// Default the range of text to print as the entire document.
fr.chrg.cpMin = 0
fr.chrg.cpMax = -1

  '// Set up the print job (standard printing stuff here).
di.cbSize = LEN(DOCINFO)
di.lpszDocName = "(Untitled)"

'// Do not print to file.
di.lpszOutput = NULL
'//}

'// Start the document.
StartDoc(pd.hdc, di)

'// Find out real size of document in characters.
lTextLength = SendMessage(hControl, WM_GETTEXTLENGTH, 0, 0 )
do
'// Start the page.
StartPage(pd.hdc)

'// Print as much text as can fit on a page. The return value is
'// the index of the first character on the next page. Using TRUE
'// for the wParam parameter causes the text to be printed.
lTextPrinted = SendMessage(hControl,EM_FORMATRANGE, TRUE, fr)
'// Print last page.
EndPageA(pd.hdc)

'// If there is more text to print, adjust the range of characters
'// to start printing at the first character of the next page.
if (lTextPrinted < lTextLength)

fr.chrg.cpMin = lTextPrinted
fr.chrg.cpMax = -1
endif

'while (lTextPrinted < lTextLength)
until lTextPrinted >= lTextLength
'// Tell the control to release cached information.
SendMessage(hControl, EM_FORMATRANGE, 0, NULL)

EndDoc (pd.hdc)

DeleteDC(pd.hdc)
ENDIF
RETURN
ENDSUB


Windows uses device contexts for everything.  Printing to a screen or printer or plotter, it's all the same.  And it is supposed to make things less complicated.  The problem is the printer dialog is needed to get a handle to a printer device context.  You can get a handle of a device context to the default printer without the printer dialog, but that in itself has some issues and requires a lot more coding to get the context set up correctly.  Which is why almost every program in the world just tosses up the dialog whether it needs it or not.

Then there are mapping modes to contend with.  I tend to use MM_TEXT for everything and just do the calculations of the ratio between screen units and device units myself.  Technically if you wanted to be correct you would use a mapping mode on screen, or in the control, that matches the mapping mode of the printer. 

So as you can see even printing the contents of an edit control is not as simple as just telling it to print to some device.  You have to do everything yourself.

Paul.
Ionic Wind Support Team

Jim Scott

To MRainey,

Thanks, That seems to have done it for ddoc printing in the background.  Only problem, I can't seem to buy this product.  Care to send me your password?  send it to jrscott@hughes.net.  I promise I'll pay Don if he ever comes around.  Actually, I've already tried to pay him, twice.

To Paul,

Ok, so what do you suggest I do?  What would it cost me to get from you the code to modify orientation, margins (left, right, upper, and lower) and print a wordpad doc in the background.  And to be cool, let's put the settings back to the way they were.  How much?

To Doc

No, I haven't tried directing output to a browser.  But if I have to....

Thanks to all.
Jim Scott

mrainey

QuoteI promise I'll pay Don if he ever comes around.

If you don't, I will.  Password sent.
Software For Metalworking
http://closetolerancesoftware.com

Jim Scott

Thanks Mr Rainiey,

This gives me a platform from which to continue development.  I promise, you won't pay a dime for me.  I'll be happy to pay Don if he comes around.

Man, you just don't know what I've been through the last couple of weeks with this.

Thanks again.

Jim Scott
Jim Scott

Ionic Wind Support Team

Jim,
I do have to ask why you are so insistant on not having the printer dialog come up?  People expect the interaction with the standard print dialog, at least I expect it since I like to have the control of where the output goes to.  I routinely print to files, two different printers (a laser and an inkjet) or to the PDF driver to create PDF documents on the fly. 

A program that only prints to the default printer would force me to change my default printer in the control panel for different jobs and is not very intuitve.

In any event modifying the @RTPRINT code to set the margins individually is trivial.  However the rest of your request would require some time, and I wouldn't even touch wordpad.  All wordpad really is internally is just the Rich Edit control.  The same that Emergence uses.

I am available for freelance work like this.  But it might be more cost effective for you to find another alternative for ddoc, or to delve into GDI device context stuff yourself.  Depends on whether you just want it done, or want to learn something along the way.  If it is the former contact me privately please.  The only real advantage of having me do it, instead of using a library like ddoc is it would be self contained and you wouldn't need to use a file.

Paul.
Ionic Wind Support Team

Jim Scott

The reason I can't have the printer dialog come up for every print job is that my program needs to print about 120 forms per session.  A normal day has my users printing the entire list once a day.  I also need to be able to print a subset of the list on the fly.  Each form has a simple format with different names, dates etc.  I can't have my users hitting the OK button 120 times to get the job done. 
Jim Scott

Ionic Wind Support Team

Ok I understand a bit better now ;).  Let me know if you still need help. 

Paul.
Ionic Wind Support Team

Dennisc

I sent a personal email to Don but have not yet received a reply. The email did not bounce though so I suspect it still exists and that someone is receiving it somewhere. Will keep everyone posted.
Failure is only the opportunity to begin again more intelligently
www.denniscomninos.com

Dennisc

OK, good news. Don responded to my email to him. ddoc is alive and well. He recently changed IP address and this may have caused problems. His website at www.greatwebdivide.com is working. I have informed him about Jim's payment with no receipt of keys problem and have asked his permission to pass on his email address to Jim. Will keep everybody posted. I am sure he would be prepared to make changes to ddoc if needed.
Failure is only the opportunity to begin again more intelligently
www.denniscomninos.com

Dennisc

BTW, I also use another printing system which is far more sophisticated - RPV Reports. Go to website www.rpvsoftware.com.
Failure is only the opportunity to begin again more intelligently
www.denniscomninos.com

Jim Scott

February 22, 2007, 07:20:38 PM #13 Last Edit: February 22, 2007, 07:28:57 PM by Jim Scott
Thanks Dennis, I'll take a look at RPV Reports.  I'm real happy with ddoc though.  It's a great package for what I'm doing right now.  Got most of my stuff redone in ddoc in just one day's work. 

BTY: Congratulations on your promotion to "Full Member".  I just made Jr. Member myself.  Am quite proud.
Jim Scott

Dennisc

Jim, I have sent you a personal message (PM) with Don's personal email address via this forum as your email address is hidden.

To the rest of you folks, Don Dickonson of ddoc fame is alive and well and still in business.  8)

Regards
Dennis
Failure is only the opportunity to begin again more intelligently
www.denniscomninos.com

mrainey

Dennis,

Would you please send me his email address?  I haven't been able to communicate with him for a couple of years.


                                                     Mike
Software For Metalworking
http://closetolerancesoftware.com

Dennisc

Mike, have sent by email.... 

Dennis
Failure is only the opportunity to begin again more intelligently
www.denniscomninos.com

Jim Scott

Thanks Dennis,  I'll send him an email right away.
Jim Scott

Jim Scott

Just wanted to follow up on this thread.  I did connect with Don and paid him for ddoc.  I had a couple of questions for him, after using ddoc for a few days, which he answered promptly.  ddoc, while being a bit dated is a great product for what I'm doing right now.  It would be real nice if I had an RTF to ddoc interpreter.  I just might write one since that would be real handy.  If I do, I'll post it here for all you ddoc'ers.  My way of giving back for all the help I've gotten here.

By the way Paul, I'm still very impressed and happy with Emergence Basic and may have another customer for you soon.  He may have already signed up for all I know.  Just wanted to say thanks.

Jim Scott
Jim Scott