问题
Setting header and footer works for print using the following command where I add header and footer as parameters.
ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_DODEFAULT, ¶meters, NULL);
But I don't know how to do it for print preview and I don't seem to find relevant document about that. It seems header and footer can be set manually via OLECMDID_PAGESETUP, but first I don't want to bring up the UI during runtime (and OLECMDEXECOPT_DONTPROMPTUSER doesn't work somehow), and second I don't know how to set the parameters when calling OLECMDID_PAGESETUP.
Someone also suggests to set print template (https://groups.google.com/forum/#!topic/microsoft.public.windows.inetexplorer.ie5.programming.components.webbrowser_ctl/54f5-aQsk6A) without any detail and the reference link is broken.
来源:https://stackoverflow.com/questions/60419546/mfc-how-to-set-header-and-footer-for-print-preview-programmatically