Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Changing target printer from WebBrowser Control...

Posted on 2003-11-17
9
Medium Priority
?
696 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
[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 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
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 
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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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 brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses

730 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