Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Changing target printer from WebBrowser Control...

Posted on 2003-11-17
9
Medium Priority
?
698 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:James Atkin
  • 6
  • 3
9 Comments
 
LVL 23

Accepted Solution

by:
Roshan Davis earned 2000 total points
ID: 9762488
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:James Atkin
ID: 9762523
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
ID: 9762542
Give your mail ID, I can send that.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Author Comment

by:James Atkin
ID: 9762562
I've sent it to your Hotmail account...

Thanks again,

James
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9762578
Okay
Rosh :)
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9762590
Done.
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9762668
Got that file?
Rosh :)
0
 
LVL 4

Author Comment

by:James Atkin
ID: 9762690
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
ID: 9762706
>> 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

877 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