473,499 Members | 1,926 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Detecting resolution for Printer object

6 New Member
I'm using the Printer object (VB6) to print graphics and need to detect the printer's resolution (in DPI). Tried

X = Printer.PrintQualiy

to no avail. Returns a zero.

It's been several years since I worked with VB, I guess I'm easily stumped...

Can it be calculated using TwipsPerPixel?

Thanks,

joe
Feb 12 '07 #1
4 3157
Killer42
8,435 Recognized Expert Expert
I'm using the Printer object (VB6) to print graphics and need to detect the printer's resolution (in DPI). Tried
X = Printer.PrintQualiy
to no avail. Returns a zero.
It's been several years since I worked with VB, I guess I'm easily stumped...
Can it be calculated using TwipsPerPixel?
Yes, twips per pixel seems as though it should (indirectly) give you what you want. A twip is 1/1440th of an inch. Or (if you live somewhere that has moved on from the Dark Ages) about 0.017639 of a millimetre.
Feb 12 '07 #2
cjreynolds
6 New Member
I think I've found a better way using GetDeviceCaps():

Expand|Select|Wrap|Line Numbers
  1. Private Declare Function GetDeviceCaps Lib "gdi32" _
  2. (ByVal hdc As Long, ByVal nIndex As Long) As Long
  3.  
  4. Private Const LOGPIXELSX = 88
  5. Private Const LOGPIXELSY = 90
  6.  
  7. Private Sub Command1_Click()
  8. Dim dpiX As Long, dpiY As Long
  9.     dpiX = GetDeviceCaps(Printer.hdc, LOGPIXELSX)
  10.     dpiY = GetDeviceCaps(Printer.hdc, LOGPIXELSY)
  11.  
  12.     MsgBox (dpiX & " " & dpiY)
  13. End Sub
I think this is working - if you can confirm/deny it's validity, please tell me.

Now that I (hopefully) have the printer resolution, how do I use that to put something on paper at, say, X = 2 inches, Y = 4 inches? I've been using this code to scale/position the image:

Expand|Select|Wrap|Line Numbers
  1. Sub SetLargePrinterScale(obj As Object, VertPosition As Single)
  2. Dim Owid As Single
  3. Dim Ohgt As Single
  4. Dim Pwid As Single
  5. Dim Phgt As Single
  6. Dim Xmid As Single
  7. Dim Ymid As Single
  8. Dim S As Single
  9. Dim ScaleFactor As Single
  10.  
  11.     ScaleFactor = (50 - frmPrint.Slider3.Value) / 10
  12.  
  13.     Owid = obj.ScaleX(obj.ScaleWidth, obj.ScaleMode, vbPixels)
  14.     Ohgt = obj.ScaleY(obj.ScaleHeight, obj.ScaleMode, vbPixels)
  15.  
  16.     Pwid = Printer.ScaleX(Printer.ScaleWidth, Printer.ScaleMode, vbPixels)
  17.     Phgt = Printer.ScaleY(Printer.ScaleHeight, Printer.ScaleMode, vbPixels)
  18.  
  19.     If Ohgt / Owid > Phgt / Pwid Then
  20.         S = Phgt / Ohgt
  21.     Else
  22.         S = Pwid / Owid
  23.     End If
  24.  
  25.     Pwid = obj.ScaleX(Pwid * ScaleFactor, vbPixels, obj.ScaleMode) / S
  26.     Phgt = obj.ScaleY(Phgt * ScaleFactor, vbPixels, obj.ScaleMode) / S
  27.  
  28.     Xmid = (obj.ScaleLeft + obj.ScaleWidth / 2) * ScaleFactor
  29.     Ymid = (obj.ScaleTop + obj.ScaleHeight / 1.6) * ScaleFactor
  30.  
  31.  
  32.     Printer.Scale (Xmid - Pwid / 2, Ymid - Phgt / 2)-(Xmid + Pwid / 2, Ymid + Phgt / 2)
  33.  
  34. End Sub
It prints the output in the middle of the page (X and Y). To move the printout away from the center, I've been adding an integer to the Xmid and Ymid equations:

Xmid = (obj.ScaleLeft + obj.ScaleWidth / 2) * ScaleFactor + 100
Ymid = (obj.ScaleTop + obj.ScaleHeight / 1.6) * ScaleFactor + 200

but for portability I need to take the current printer resolution into account.

Any suggestions?

joe
Feb 12 '07 #3
Killer42
8,435 Recognized Expert Expert
I haven't looked into this in detail yet (and it's not an area I'm really familiar with anyway). But I do know that you can produce the same results two ways...
Expand|Select|Wrap|Line Numbers
  1. dpiX = GetDeviceCaps(Printer.hdc, LOGPIXELSX)
  2. dpiY = GetDeviceCaps(Printer.hdc, LOGPIXELSY)
Expand|Select|Wrap|Line Numbers
  1. dpiX = 1440 / Printer.TwipsPerPixelX
  2. dpiY = 1440 / Printer.TwipsPerPixelY
Not a lot of difference really, except that the TwipsPerPixelX/Y are already available without any declarations. I guess it's just a matter of which way you prefer to go.
Feb 13 '07 #4
cjreynolds
6 New Member
That works - Thanks!
Feb 13 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
2717
by: Erik Bethke | last post by:
Hello All, I am trying to clean up some polish bugs with the Shanghai game I am working on and I am currently stuck on trying to get the right event for detecting when the user has changed the...
1
2843
by: Erik Bethke | last post by:
Hello All, I am trying to clean up some polish bugs with the Shanghai game I am working on and I am currently stuck on trying to get the right event for detecting when the user has changed the...
2
10791
by: Philippe | last post by:
I'm writing a vb.net application that prints jpeg pictires, and although I set the defaultpageSettings.printerResolution of my PrintDocument object to the maximum available printer resolution...
4
2115
by: CG3000 | last post by:
I create a .PNG image ( in Macromedia Fireworks ) which has an gif in it in the top left corner and a lot of empty canvas space to the right. I use about 10 text boxes on a form to populate...
1
4041
by: Chris Dunaway | last post by:
When using PrintDocument to print something, if I check the PageBounds property of the PrintPageEventArgs object, it shows the rectangle to be 850 x 1100, or 100 dpi. But when I check the value of...
2
28419
by: Steve | last post by:
I'm trying real hard to set the printer resolution for a PrintDocument. It appears that the printer is already set to 300 x 300 dpi, which is JUST what I want. But the Margins and PrintableArea...
3
4746
by: BobRoyAce | last post by:
I have an application that prints bar code labels for each new record added to the system. It uses a particular printer to do this (Brother P-Touch QL500). What I'd like to do is not send the...
6
1340
by: Lloyd Dupont | last post by:
Before printing I create an instance of PrintDocument as Follow (beware, pseudo code) //============================== PrinterResolution pr = new PrinterResolution(); pr.X= 600; pr.Y= 600;...
1
4135
by: Grzegorz Klimsa | last post by:
Hi ! I have a problem wiht detecting resolution of client web browser I prepare several files of css style for different browsers and different resolutions, (such as : Style_1024x768.css ;...
0
7180
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7225
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6901
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7392
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4605
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3105
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3101
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1429
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
307
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.