I'm writing a MFC app that shall be able to print to file (especially 'virtual' printers). As the printout consists of a series of jobs (each one with StartDoc/EndDoc) I can't open the file dialog to ask for each filename. So I used DOCINFO to set the file names.

That works fine but has one problem: I don't know the file extension that's needed for the printer the user has selected. That might be pdf, xps, mdi or something else depending on the printer. Is there a safe way to determine the file extension

I have some ideas, but none of them safe enough:

* Scanning the printer driver description for known strings - unsafe, no future!

* Let MFC open the filename dialog for the first job, hide it and try to get the default file name/extension - maybe working, but at least I'll get some flickering dialog.

Some other ideas


Re: General Windows Vista Development Issues Printing to file via DOCINFO - Where to get the file extension from?


Hi again,

I just found out that the second method would not work. If I check 'print to file' in the print dialog always the filename 'output.prn' is proposed - independent of the native extension of the driver's file format.

If I set DOCINFO.lpszOutput to NULL before StartDoc a SaveAs dialog opens with a correct proposed filename (in this case composed of DOCINFO.lpszDocName plus the RIGHT extension). But then I can neither set the path or name part of the full name nor can I query the full name afterwards. I can't force hiding the SaveAs dialog and I suspect this behavior is driver specific.

I just need a way to query the driver for it's specific default file extension...