Solved

Changing target printer from WebBrowser Control...

Posted on 2003-11-17
9
693 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
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
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.

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

Suggested Solutions

Title # Comments Views Activity
Error on moodle after upgrade 3 140
Creating Labels and Frequency list style reports in SAS code 9 105
Separate into files by filename 12 87
matchUp  challenge 9 115
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.

828 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