Solved

Changing target printer from WebBrowser Control...

Posted on 2003-11-17
9
692 Views
Last Modified: 2013-11-20
Hi,

I have an MFC app that has a Dialog containing the Microsoft WebBrowser control.

Once I have navigated to the appropriate URL, I wish to initiate a 'Print' however, I wish to change the target printer programmatically beforehand and set it back afterwards.

I loacated some source on Microsoft's MSDN for a function called 'GetPrinterDevice' that returns the appropriate hDevMode and hDevNames to the required printer; see
http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/Q166/1/29.asp&NoWebContent=1

I therefore have the following:

HGLOBAL hDevMode = NULL;
HGLOBAL hDevNames = NULL;
if (GetPrinterDevice(_T("MyPrinter"), &hDevNames, &hDevMode))
{
   const LECMDEXECOPT_DONTPROMPTUSER = 2;
   const IDM_PRINT = 6;
   AfxGetApp()->SelectPrinter(hDevNames, hDevMode);        // Default to MyPrinter
   TheDocument->ExecWB(IDM_PRINT, LECMDEXECOPT_DONTPROMPTUSER, 0, 0);
}
else
{
   AfxMessageBox(_T("Failed to select 'MyPrinter'."));
}

If I misspell the required printer, the AfxMessageBox pops up, so the function appears to be <almost> working, however, ExecWB still prints to the normal Windows Default printer!!!

Can anyone tell me where I'm going wrong???

Thanks,

James
0
Comment
Question by:jatkin
  • 6
  • 3
9 Comments
 
LVL 23

Accepted Solution

by:
Roshan Davis earned 500 total points
Comment Utility
Install Platform SDK or get latest winspool.h and use the APIs

   SetDefaultPrinter
   GetDefaultPrinter
in these APIs we can specify the Printer name directly

Rosh :)
0
 
LVL 4

Author Comment

by:jatkin
Comment Utility
Now that's the sort of solution I like!

I'm currently downloading the SDK!  Umm, good old microsoft - almost 200MB !

Do you have a copy of the latest winspool.h file you could send me, or copy the relavant lines in a comment ?

Thanks for the help...

James
0
 
LVL 23

Expert Comment

by:Roshan Davis
Comment Utility
Give your mail ID, I can send that.
0
 
LVL 4

Author Comment

by:jatkin
Comment Utility
I've sent it to your Hotmail account...

Thanks again,

James
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 23

Expert Comment

by:Roshan Davis
Comment Utility
Okay
Rosh :)
0
 
LVL 23

Expert Comment

by:Roshan Davis
Comment Utility
Done.
0
 
LVL 23

Expert Comment

by:Roshan Davis
Comment Utility
Got that file?
Rosh :)
0
 
LVL 4

Author Comment

by:jatkin
Comment Utility
That worked a treat !

I always like the simple solutions...  Still awaiting the SDK Download from MS though  ;-)

Thanks

James
0
 
LVL 23

Expert Comment

by:Roshan Davis
Comment Utility
>> Still awaiting the SDK Download from MS though  ;-)
Install FlashGet for that faster download. Get that from download.com

All the Best
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Generic progress indicator 6 109
if loop in java 3 113
countEvens challenge 2 55
sum13 challenge 24 77
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now