Solved

printer device context resolution

Posted on 2003-11-14
12
550 Views
Last Modified: 2013-11-20
hello, i have an application that renders an openlg context to a dibsection, and this is in turn printed on a printer from a dib. everything works great but the problem is that i want to specify 300 dpi as the output resolution on the printer's device context. there must be a way to set this, i have done it in other applications (printes out at 300 dpi that is, but i did not write the code). can anyone tell me how to set the resolution? i know i can get the current resolution with GetDeviceCaps and LOGPIXELSY, and LOGPIXELX. what i want to be able to do is set these values to 300, or by some other way set the output resolution of the device context. i want to be able to create my image such that it will always print out at 300 dpi. the only thing i cannot figure out how to do after researching is how i can explicitly set the output resolution of the printed page, provided of course the printer can handle it.

thanks,
james
0
Comment
Question by:gandalf3373
  • 5
  • 4
  • 2
12 Comments
 
LVL 30

Expert Comment

by:Zoppo
ID: 9749941
Hi gandalf3373,

I'm not sure (since I didn't use this up to now), but I think you can do this
with OpenPrinter() and DocumentProperties() ... see MSDN about their usage.

Hope this helps,

ZOPPO

BTW, just for interest: What do you want to do if the used printer doesn't support 300 DPI?
0
 

Author Comment

by:gandalf3373
ID: 9750154
zoppo,

i have narrowed it down to the DEVMODE structure that returns with the PRINTDLG structure. perhaps i should not be posting this in MFC but rather in the windows programming section, since the routine is mostly sdk code. but anyways, i have tried changing the fields before printing it out but it is not working. i am still stuck at the user defined resolution. as far as the printer not supporting 300 dpi, i have a backup that will print it out at the resolution which is less than 300, whatever that is depending upon the return value of GetDeviceCaps. so still if anyone knows how to properly change the DEVMODE structure returned when the printdlg returns let me know. that would solve my problem very easily. the only two fields i want to set are dmPrintQuality and dmYResolution.

i have tried this

DEVMODE* customDeviceMode = (DEVMODE*)GlobalLock(pd.hDevMode);
            customDeviceMode->dmPrintQuality = 300;
            customDeviceMode->dmYResolution  = 300;

i do not get any errors, but it does not print out at 300 dpi either. i am testing this on a printer that defaults to 600.

james
0
 
LVL 11

Expert Comment

by:KurtVon
ID: 9750570
300 is not a print quality setting.  The constants for dmPrintQuality are

#define DMRES_DRAFT         (-1)
#define DMRES_LOW           (-2)
#define DMRES_MEDIUM        (-3)
#define DMRES_HIGH          (-4)
0
 
LVL 11

Expert Comment

by:KurtVon
ID: 9750683
Er, as I was trying to say before my computer rebooted, you also need to set the dmFields to with the flags for DM_PRINTQUALITY (not really needed since the default is horz and vert being the same) and DM_YRESOLUTION.

Hope this helps.
0
 

Author Comment

by:gandalf3373
ID: 9750687
dmPrintQuality
Specifies the printer resolution. There are four predefined device-independent values:
DMRES_HIGH
DMRES_MEDIUM
DMRES_LOW
DMRES_DRAFT

If a positive value is given, it specifies the number of dots per inch (DPI) and is therefore device dependent.
---------------------------------------------------------------------------------------------------------------------------------

that is from the docs. i was wondering if that meant that by specifying a non-negative value, i would be explicitly be setting the dpi. i have tried the constants and those are not working either, so maybe it is the way i am setting it? i do not know.

james
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 11

Expert Comment

by:KurtVon
ID: 9751058
Well, if setting dmFlags didn't work, are you sure you are fllwoing all the steps properly: http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/q167/3/45.asp&NoWebContent=1

If you really are doing all those steps and it still doesn't work, I don't know what would be doing it.
0
 
LVL 11

Expert Comment

by:KurtVon
ID: 9751065
Whoops, I mean if setting *dmFields with the flags* didn't work.
0
 
LVL 30

Assisted Solution

by:Zoppo
Zoppo earned 25 total points
ID: 9753440
Hm ... I read something in MSDN about it: maybe you need to call SetPrinter() to modify the DEVMODE structure of a printer.
----------------------
MSDN: ... If you use SetPrinter to modify the default DEVMODE structure for a printer (globally setting the printer defaults),
you must first call the DocumentProperties function to validate the DEVMODE structure. ...
----------------------

here are two samples from MSDN how to change printer settings (samples don't change resolution but should be similar):
http://support.microsoft.com/default.aspx?scid=kb;en-us;167345
http://support.microsoft.com/default.aspx?scid=kb;EN-US;140285

Hope this helps,

ZOPPO
0
 
LVL 11

Accepted Solution

by:
KurtVon earned 25 total points
ID: 9763727
Yup, that would be step 2 in the article I linked to.  The step is not skippable.  Printer drivers can be very persnickety when you are dealing with low-level stuff like this.
0
 

Author Comment

by:gandalf3373
ID: 9763844
thanks guys. i have not gotten anything to work yet but i am working on it today, i implemented the last link that KurtVon posted on friday afternoon but that is not working either. i will let u guys know when i get it working. again though with everything i have tried, i have my image printing out, i just cannot get it to print out at code-specified resolution.

james
0
 

Author Comment

by:gandalf3373
ID: 9770803
i have tried all of the suggestions and it is just not working. maybe i would be better off trying postscript in the future. anyways, after all of the trouble i have just decided to match the image to the resolution that the user selects from the print dialog or the default. which works good and i had to do that anyways if the printer did not suppoort 300 dpi. i would have rathered kept it at 300dpi max though since that was all that was really necessary to get a nice quality image, which could save some processing and memory.

i did however get everything i tried to work in the code i guess, i was not getting any errors, the resolution was simply just not changing. it could have been the printers i was testing on anyways, because the testing with the dmFlags never even allowed the changing of the dmYResolution.


thanks,
james
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
function returning CString in a regular win32 DLL 8 150
Perl Awk Need Help 3 94
either24  challenge 19 84
Problem to event 3 50
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

762 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now