FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for CA-Clipper PrinterSetup()
Posts: 74
Joined: Thu Oct 20, 2005 04:30 PM
PrinterSetup()
Posted: Thu Nov 30, 2006 03:49 PM

Hi All,

Can someone tell me why PrinterSetup() always return NIL.

My logic says that if the OK button is pressed I should get something like a logic .T. or numeric 1. And when the cancel button is pressed a logic .F. or numeric 0.

When the Cancel button is pressed I want to cancel the printout. Is there a way of detecting if OK or Cancel button has been pressed.

Regards,

Gilbert Vaillancourt
turbolog@videotron.ca
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
PrinterSetup()
Posted: Thu Nov 30, 2006 05:11 PM

Gilbert,

PrinterSetup() is automatically used from Class TPrinter.

PrinterSetup() calls Windows API PrintDlg. According to Microsoft docs:

The PrintDlg function displays a Print dialog box or a Print Setup dialog box. The Print dialog box enables the user to specify the properties of a particular print job.

The Print Setup dialog box should not be used in new applications. It has been superseded by the Page Setup common dialog box created by the PageSetupDlg function.

BOOL PrintDlg(

LPPRINTDLG lppd     // address of structure with initialization data

);

Parameters

lppd

Pointer to a PRINTDLG structure that contains information used to initialize the dialog box. When PrintDlg returns, this structure contains information about the user's selections.

Return Values

If the user clicks the OK button, the return value is nonzero. The members of the PRINTDLGstructure pointed to by the lppd parameter indicate the user's selections.
If the user cancels or closes the Print or Printer Setup dialog box or an error occurs, the return value is zero. To get extended error information, use the CommDlgExtendedError function, which can return one of the following values:

CDERR_FINDRESFAILURE PDERR_CREATEICFAILURE
CDERR_INITIALIZATION PDERR_DEFAULTDIFFERENT
CDERR_LOADRESFAILURE PDERR_DNDMMISMATCH
CDERR_LOADSTRFAILURE PDERR_GETDEVMODEFAIL
CDERR_LOCKRESFAILURE PDERR_INITFAILURE
CDERR_MEMALLOCFAILURE PDERR_LOADDRVFAILURE
CDERR_MEMLOCKFAILURE PDERR_NODEFAULTPRN
CDERR_NOHINSTANCE PDERR_NODEVICES
CDERR_NOHOOK PDERR_PARSEFAILURE
CDERR_NOTEMPLATE PDERR_PRINTERNOTFOUND
CDERR_STRUCTSIZE PDERR_RETDEFFAILURE

Remarks

If the hook procedure (pointed to by the lpfnPrintHook or lpfnSetupHook member of the PRINTDLG structure) processes the WM_CTLCOLORDLG message, the hook procedure must return a handle for the brush that should be used to paint the control background.

See Also

CommDlgExtendedError, CreateDC, DOCINFO, PRINTDLG, PrintHookProc, SetupHookProc, StartDoc, WM_CTLCOLORDLG

In FW, PrinterSetup() should return the handle of the device context if successfull:

_retnl( ( LONG ) ( PrintDlg( &pd ) ? pd.hDC : 0 ) );

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 74
Joined: Thu Oct 20, 2005 04:30 PM
PrinterSetup()
Posted: Thu Nov 30, 2006 07:58 PM

Hi Antonio,

Do you mean that PrinterSetup will return a non zero value if OK button is presse and 0 value if Cancel button is pressed ?

Regards

Gilbert Vaillancourt
turbolog@videotron.ca
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
PrinterSetup()
Posted: Fri Dec 01, 2006 12:54 PM

Gilbert,

Yes

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 74
Joined: Thu Oct 20, 2005 04:30 PM
PrinterSetup()
Posted: Fri Dec 01, 2006 09:24 PM

Hi Antonio,

I sure will do some testing on this.

Thanks

Regards,

Gilbert

Gilbert Vaillancourt
turbolog@videotron.ca
Posts: 74
Joined: Thu Oct 20, 2005 04:30 PM
PrinterSetup()
Posted: Sat Dec 02, 2006 12:32 AM

Hi Antonio,

Sorry to tell you that PrinterSetup() return 0 whether I pressed OK or Cancel buttons.

Here`s the code I used for testing:

function Test()
local hDC

hDC := PrinterSetup()
MsgInfo(Str(hDC))

Return (NIL)

Regards,

Gilbert

Gilbert Vaillancourt
turbolog@videotron.ca
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
PrinterSetup()
Posted: Sat Dec 02, 2006 12:46 AM

Gilbert,

You are right. There was a missing flag at PrinterSetup() function:

pd.Flags = PD_PRINTSETUP | PD_USEDEVMODECOPIES | PD_RETURNDC;

PD_RETURNDC was missing. Now it behaves as expected: hDC, or zero if cancel is pressed. Thanks!

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 74
Joined: Thu Oct 20, 2005 04:30 PM
PrinterSetup()
Posted: Sat Dec 02, 2006 01:15 AM

Hi Antonio,

I knew there was someting about PrinterSetup(), cause I remember getting very frustrated trying to figure out why in the world was I not getting anything back.

How can I fix this function without recompiling the whole library ?
I would like to solve this problem so I can go on with the rest of my project. Right now I`m stuck...

Regards,

Gilbert Vaillancourt
turbolog@videotron.ca
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
PrinterSetup()
Posted: Sat Dec 02, 2006 09:06 AM

Gilbert,

You may download printdc.obj for 16 bits from here:

http://www.uploading.com/files/EPJWV6HS ... C.ZIP.html

Just link it to your application as another OBJ of your own.

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 74
Joined: Thu Oct 20, 2005 04:30 PM
PrinterSetup()
Posted: Sat Dec 02, 2006 05:43 PM

Hi Antonio,

Thanks. I`getting on it right anway

Regards,

Gilbert

Gilbert Vaillancourt
turbolog@videotron.ca

Continue the discussion