Changing target printer from WebBrowser Control...


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

I therefore have the following:

if (GetPrinterDevice(_T("MyPrinter"), &hDevNames, &hDevMode))
   const IDM_PRINT = 6;
   AfxGetApp()->SelectPrinter(hDevNames, hDevMode);        // Default to MyPrinter
   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???


James AtkinSenior Principle Software EngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Roshan DavisCommented:
Install Platform SDK or get latest winspool.h and use the APIs

in these APIs we can specify the Printer name directly

Rosh :)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
James AtkinSenior Principle Software EngineerAuthor Commented:
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...

Roshan DavisCommented:
Give your mail ID, I can send that.
OWASP Proactive Controls

Learn the most important control and control categories that every architect and developer should include in their projects.

James AtkinSenior Principle Software EngineerAuthor Commented:
I've sent it to your Hotmail account...

Thanks again,

Roshan DavisCommented:
Rosh :)
Roshan DavisCommented:
Roshan DavisCommented:
Got that file?
Rosh :)
James AtkinSenior Principle Software EngineerAuthor Commented:
That worked a treat !

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


Roshan DavisCommented:
>> Still awaiting the SDK Download from MS though  ;-)
Install FlashGet for that faster download. Get that from

All the Best
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.