Link to home
Start Free TrialLog in
Avatar of shitallj
shitallj

asked on

programatically closing app

Hi,
I have SDI (CRichEditView) app. I want to do following:
On command line I want to send some parameter, load and print the document file and close the app. Right now I am able to print the file (by calling OnFilePrint) but I get the regular printer select dialog. I don't want this dialog and want to print on default printer. Also after printing I want to close the app. I am trying to send WM_CLOSE message to main window. It closes the app but gives debug error after closing. Also before closing, it asks if I want to save the file. I don't want this prompt (I don't want to save it) and want to smoothly close the app without error.

How can I achieve it?
Please help.
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

i've encountered Dan Pilat's article on codeproject.com regarding printing features.

u might won't need all the functionalities that the print classes provides but there is a solution for your select print dialog.
check http://www.codeproject.com/printing/printingmadeeasy.asp

"Don't need a print dialog -
Printing some reports requires either your own custom dialog, or no dialog at all. This can be a problem, because the standard CPrintDialog typically creates the device context for you. In these non-standard situations, you can use the GPrintJob::UseDefaults() function to create a default device context for you.
"

for closing the application try ExitInstance() or send ID_APP_EXIT to your app instance.
ASKER CERTIFIED SOLUTION
Avatar of Melange
Melange
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Note: /p and /pt are built-in to MFC's standard command line processing. /p says to "print and exit" using the current default printer. /pt specifies which printer to use (via 3 following parameters for printer device driver).

These are also invoked by the shell if you drag the associated document for your app to a printer icon. The settings for this are set in the registry under MFC's default registry settings for your application.
Avatar of shitallj
shitallj

ASKER

Hi Melange,
your solution is partlyl working for me. Yes, I want to print and close the document but I am not going to load the document from a file. Instead, I am going to create it from the parameters sent on command line. So I added your suggestion pInfo->m_bDirect = TRUE; before calling OnFilePrint and it is printing without showing up printer dialog. Now my problem is, after printing I want to close it but don't want to show up the prompt for saving it. (don't want to save it). I think there must be some member variable like m_bDirty which I should set to FALSE before sending ID_APP_EXIT or WM_CLOSE command. Any suggestion?
In the document class the function SetModifiedFlag controls whether or not the document is dirty.