Printed MetaFile drops lines when screen resolution is < 1280x1024

Posted on 2003-03-21
Medium Priority
Last Modified: 2013-12-03
We are creating a TMetaFileCanvas and stretchdrawing an EMF onto it and then adding some custom text.  Once completed, that metafile is stretchdrawn onto a printer's canvas and printed.  These are our Forms.  One form we have contains a table of information on it.  

Using our original source, the grid lines (lines between the cells of the table) would not print when the Server was running a resolution at or below 1024x768.  These lines would print when the resolution was 1280x1024.  We traced this down to the creation of the TMetaFileCanvas.  It was being created with a reference device of 0 (HWndDesktop).  So, it was using a Device Context with the resolution of the screen to create the canvas.  Our theory is that the resolution of that canvas was only 96dpi at 1024x768 and therefore the grid lines, that perhaps were finer than that, were being being optimized out.  

We fixed this by using the default printer's device context to create the metafile canvas.  This consistently allows the forms to print accurately.  Obviously, the DPI of the printer was higher than that of the screen.

This would work fine on a standard application.  HOWEVER, we've made things difficult by tossing a Server and a thin client into the archetecture.  The TMetafileCanvas is being created on the Server which hosts the engine that dynamically builds and routes our forms.  The completed metafile is sent to the client along with routing information.  The client opens the appropriate device (a winprinter in this case) and plays the information out to it.  So, the problem is that the printers are on the clients and not the server.  We cannot get the correct Device Context for the destiation printer.  In fact, we are not guaranteed to even have a printer on the server which is supposed to be a closed box unit.  We've come up with a working solution that uses a printer DC if there is a non-generic printer on the server. If not falls back to the screen's DC if there is not.  And we can dictate that upgrading to the next version of our software involves installing a dummy printer onto the server but... this cannot be the right way to do this.  There has to be a better way.

We've played with using SetMapMode, SetWindowExtEx and SetViewPortExtEx but frankly we are not familiar enough with them and were just take shots in the dark.  We do not know if we would have to apply these calls on Server side, client side or both.  Our test concentrated on the client side fo things and applying the extents to the metafile canvas.  Before and after we applied the sets, the Get*Extex calls always returned (1,1).  This didn't make sense to us.

This all boils down to two questions:
  1. Can we create the MetaFileCanvas passing a reference device of 0 (HWndDesktop) and then change the resolution/DPI of the canvas?
  2. Is there an alternative we have not thought of yet?

Additional Info -
  We are using Delphi but can translate examples from any language.
  We are using CreateWithComments to create the TMetaFileCanvas.
  We are "StretchDrawing" the EMF to the MFCanvas and then to the printer canvas.  In Delphi, the StretchDraw call is filtered through a wrapper which in the end I believe boils down to a PlayEnhMetafile call - I have not completely traced this through and I could be wrong but the comments in the wrapper state that it "plays" the metafile.  Can anyone confirm or deny this?
  This one is tough but fun.  I'd add more points but this is my first posting here.  So, you get all the points I've got.  You'll probably see me more often now that I'm an official "Expert" <g>.

Question by:BLayman
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
  • 2

Accepted Solution

drnick earned 465 total points
ID: 8331835
question one:
yes you can, but if passing 0, it uses automatically the screens dc.

question two:
i would (on the server) indeed pass 0, and create an emf or wmf or whatever.
but on the clientside, maybe you can first create an compatiblebitmap
(CreateDIBSection) of the screen, but i would make it very big, let's say
2*screen's size. then strechdraw you emf on it (so the lines'll come for sure).
now stretchdraw the bitmap on you form.
i hope that the downsizing will keep the lines.

hope that helped.


Author Comment

ID: 8344956
We tried something similar but the problem is still in the initial creation of the MF.  The playing of our EMF onto it, causes the loss of the lines from then on there is nothing I can do with it.  In addition, converting it to a DIB changes it from a vector image to a raster image and that would make the printing speed unacceptable.

Thanks Though!

I posted this on newsgroups and someone suggest the solution of having the server request the initial MF from the client, doing the manipulation at the server and then sending it back to the client.  That's what I'll do unless anyone else has a suggestion.

Thanks for the reply though I appreciate it.

That really leaves the following question is there a way to adjust the Device context of a MF canvas that has already been created.


Author Comment

ID: 9927967
Hmm, I missed the fact that he said to double the size of the screen in order to increase the resolution.  If the screen is at 75 dpi, we'd have to do a lot more than double it but it was an interesting idea.  

I'll close this issue and give hime some points.

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

764 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