Solved

Changing target printer from WebBrowser Control...

Posted on 2003-11-17
9
694 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
[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
  • 6
  • 3
9 Comments
 
LVL 23

Accepted Solution

by:
Roshan Davis earned 500 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:jatkin
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
Technology Partners: 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:jatkin
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:jatkin
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

Title # Comments Views Activity
Include multiple hostnames in this command? 3 56
wordmultiple challenge 12 170
Making an alias 7 122
Adjust the codes 3 66
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
In this post we will learn different types of Android Layout and some basics of an Android App.
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.

710 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