Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

printing a postscript file to a printer from within MFC application

Posted on 1999-07-13
3
Medium Priority
?
275 Views
Last Modified: 2013-11-20
Assume I already had a postscript file, now I need to print it to a printer from my MFC application. How can I do it?   Normally I do this on UNIX:
        sprintf(printstr, "lpr %s   %s", filename, printer);
        system(printstr);

I have tried the below on NT 4.0, however, the DOS box always shows up, and I did not want that.
        sprintf(printstr, "copy %s  %s", filename, printer);
        system(printstr);
Thank you,
0
Comment
Question by:tpnguyen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 400 total points
ID: 1309842
If your main problem is not to show the DOS box, use

char acCmdLine [256];
LPCTSTR pszWorkDir = NULL;

BOOL bRes;

STARTUPINFO si;
PROCESS_INFORMATION pi;

ZeroMemory ( &si, sizeof ( STARTUPINFO));
ZeroMemory ( &pi, sizeof ( PROCESS_INFORMATION));

si.cb = sizeof ( STARTUPINFO);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;

sprintf ( acCmdLine, "cmd.exe -c copy %s  %s", filename, printer);

bRes = CreateProcess ( NULL, acCmdLine, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS | CREATE_NEW_CONSOLE, GetEnvironmentStrings(), lpszWorkDir, &si, &pi);

if ( bRes)
{
 CloseHandle ( pi.hThread);
 WaitForSingleObject ( pi.hProcess, INFINITE);
}
else printf ( "\n\tERROR creating process: %d\n\n", GetLastError ());

Feel free to ask if you need more information!
0
 

Author Comment

by:tpnguyen
ID: 1309843
Thank you very much for the details.   It is very helpful.
-Thang
0
 
LVL 86

Expert Comment

by:jkr
ID: 1309844
One other thing - if you have installed an application which is already registered as the default application for handling PS files (you can see it when the explorer refers to them as 'PostScript File' rather than 'PS-File'), it might be easier to use

ShellExecute ( NULL, "print", "<path to file>.ps", NULL, NULL, SW_HIDE);
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question