Distinguishing between 'Print' from 'Print Preview', and 'Print' from a menu or tool bar command. | CodeGuru

Distinguishing between ‘Print’ from ‘Print Preview’, and ‘Print’ from a menu or tool bar command.

If your print and print preview works with user defined options it may be required for you to distinguish the print call from a Print Preview screen against that from menu or toolbar. That way you can avoid asking the user for options again in the case of a Print from Print Preview. Here is […]

Written By
CodeGuru Staff
CodeGuru Staff
Aug 1, 1999
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

If your print and print preview works with user defined options it may be required for you to
distinguish the print call from a Print Preview screen against that from menu or toolbar. That
way you can avoid asking the user for options again in the case of a Print from Print Preview.

Here is a simple solution. When you hit the Print button from a preview screen, MFC generates
a message ID – ID_FILE_PRINT which will be mapped to CView OnFilePrint() in your message map when
you autogenerate the project. If you go into your resource menu (provided you have an auto generated
menu resource) and check the ID of the menu item Print (under File menu) you will see it also has
an ID – ID_FILE_PRINT. You need to change this to something else say ID_FILE_PRINTX, then go into
Print menu item and change it to ID_FILE_PRINTX too. Overload both messages in your view as

ON_COMMAND(ID_FILE_PRINT, OnFilePrint)
ON_COMMAND(ID_FILE_PRINTX, OnFilePrintFromMenuOrToolBar)

Now you know which is which.

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.