regards
Ian
** invalid email address, change dk to denmark
homepage http://www.kingsoft-denmark.com/
Tips & Tricks page http://tips.kingsoft-denmark.com/
"John Contract" <jcon...@bloomberg.net> wrote in message
news:3add89cc$0$99...@wodc7nh7.news.uu.net...
Ian Williams <adv...@kingsoft-dk.com> wrote in message
news:#xwAwXAyAHA.1340@tkmsftngp04...
Public Sub GetTwipsPerPixel()
Dim hdc As Long, lResult As Long
hdc = GetDC(0)
TwipsPerPixelX = 1440 / GetDeviceCaps(hdc, LOGPIXELSX)
TwipsPerPixelY = 1440 / GetDeviceCaps(hdc, LOGPIXELSY)
ReleaseDC 0, hdc
End Sub
regards
Ian
** invalid email address, change dk to denmark
homepage http://www.kingsoft-denmark.com/
Tips & Tricks page http://tips.kingsoft-denmark.com/
"John Contract" <jcon...@bloomberg.net> wrote in message
news:3add8e98$0$74...@wodc7nh1.news.uu.net...
Use the screen object:
(Form1.Width \ Screen.TwipsPerPixelX) & ", " & _
(Form1.Height \ Screen.TwipsPerPixelY)
Hope this helps,
Mike
-- EDais --
WWW: Http://Members.xoom.com/EDais/
Work E-Mail: ED...@btclick.com
Other E-Mail: Mike....@btclick.com
Does it support the ScaleX() and ScaleY() functions?
If so then:
'***
FormWidth = ScaleX(Form1.Width, vbTwips, vbPixels)
FormHeight = ScaleX(Form1.Height, vbTwips, vbPixels)
'***
Otherwise take it as 15, I've never seen it as anything different. I think
there are API calls to do the conversion though, but I don't remember any
offhand. Maybe a quick search through the MSDN would be in order?
Go to Control Panel / Display / Settings and select Large Fonts.
> Does it support the ScaleX() and ScaleY() functions?
Please find the below functions which I wrote to emulate VB's ScaleX and
ScaleY functions. Hope they help.
+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+
Monte Hansen
http://KillerVB.com
+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+
Private Const LOGPIXELSX As Long = 88
Private Const LOGPIXELSY As Long = 90
Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal
nIndex As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal
hdc As Long) As Long
Public Function LogicalToDeviceX(ByVal Width As Single, ByVal ScaleFrom As
ScaleModeConstants, Optional ByVal hdc As Long) As Single
'===========================================================================
====
' LogicalToDeviceX - Converts the supplied horizontal logical unit to
pixels.
'
' Width The value to convert to pixels.
' ScaleFrom The unit of measurement to scale from.
' hDC Optional. The device context that Width relates to.
'
' RETURNS The value scaled to pixels.
'===========================================================================
====
Dim LOGPIXELS As Long
' No error handler
On Error GoTo 0
' Use current meta device as a basic for the scale, if any,
' otherwise use the screen device.
If IsValidHandle(hdc) Then
' Get # of pixels per logical inch
LOGPIXELS = GetDeviceCaps(hdc, LOGPIXELSX)
Else
' Get the screen device
hdc = GetDC(0&)
' Get # of pixels per logical inch
LOGPIXELS = GetDeviceCaps(hdc, LOGPIXELSX)
' Release the screen
ReleaseDC 0, hdc
End If
' Now for perform the conversion
Select Case ScaleFrom
Case vbCentimeters
' Convert from metric; 2540 = himetric units per inch
LogicalToDeviceX = (Width * LOGPIXELS) / 2.54
Case vbMillimeters
' Convert from metric; 2540 = himetric units per inch
LogicalToDeviceX = (Width * LOGPIXELS) / 25.4
Case vbHimetric
' Convert from himetric; 2540 = himetric units per inch
LogicalToDeviceX = (Width * LOGPIXELS) / 2540
Case vbTwips
' Convert to twips; 1440 = twips per inch
LogicalToDeviceX = (Width * LOGPIXELS) / 1440
Case vbCharacters
' Convert to twips; 1 horizontal character = 120 twips per unit;
vertical = 240 twips per unit
LogicalToDeviceX = ((Width * LOGPIXELS) * 120) / 1440
Case vbInches
' Convert to inches; 1440 = twips per inch
LogicalToDeviceX = Width * LOGPIXELS
Case vbPoints
' Convert to points; 72 = points per inch
LogicalToDeviceX = ((Width * LOGPIXELS) * 20) / 1440
Case vbPixels
' No conversion needed for pixels
LogicalToDeviceX = Width
Case Else
Err.Raise 5, Module
End Select
ExitLabel:
Exit Function
End Function
Public Function LogicalToDeviceY(ByVal Height As Single, ByVal ScaleFrom As
ScaleModeConstants, Optional ByVal hdc As Long) As Single
'===========================================================================
====
' LogicalToDeviceY - Converts the supplied vertical logical unit to
pixels.
'
' Height The value to convert to pixels.
' ScaleFrom The unit of measurement to scale from.
' hDC Optional. The device context that Width relates to.
'
' RETURNS The value scaled to pixels.
'===========================================================================
====
Dim LOGPIXELS As Long
' No error handler
On Error GoTo 0
' Use current meta device as a basic for the scale, if any,
' otherwise use the screen device.
If IsValidHandle(hdc) Then
' Get # of pixels per logical inch
LOGPIXELS = GetDeviceCaps(hdc, LOGPIXELSY)
Else
' Get the screen device
hdc = GetDC(0&)
' Get # of pixels per logical inch
LOGPIXELS = GetDeviceCaps(hdc, LOGPIXELSY)
' Release the screen
ReleaseDC 0, hdc
End If
' Now for perform the conversion
Select Case ScaleFrom
Case vbCentimeters
' Convert from himetric; 2540 = himetric units per inch
LogicalToDeviceY = (Height * LOGPIXELS) / 2.54
Case vbMillimeters
' Convert from himetric; 2540 = himetric units per inch
LogicalToDeviceY = (Height * LOGPIXELS) / 25.4
Case vbHimetric
' Convert from himetric; 2540 = himetric units per inch
LogicalToDeviceY = (Height * LOGPIXELS) / 2540
Case vbTwips
' Convert to twips; 1440 = twips per inch
LogicalToDeviceY = (Height * LOGPIXELS) / 1440
Case vbCharacters
' Convert to twips; 1 horizontal character = 120 twips per unit;
vertical = 240 twips per unit
LogicalToDeviceY = ((Height * LOGPIXELS) * 240) / 1440
Case vbInches
' Convert to inches; 1440 = twips per inch
LogicalToDeviceY = Height * LOGPIXELS
Case vbPoints
' Convert to points; 72 = points per inch
LogicalToDeviceY = ((Height * LOGPIXELS) * 20) / 1440
Case vbPixels
' No conversion needed for pixels
LogicalToDeviceY = Height
Case Else
Err.Raise 5, Module
End Select
ExitLabel:
Exit Function
End Function
Public Function DeviceToLogicalX(ByVal Width As Single, ByVal ScaleTo As
ScaleModeConstants, Optional ByVal hdc As Long) As Single
'===========================================================================
====
' DeviceToLogicalX - Converts the supplied Width to the desired logical
unit.
'
' Width The value to convert from pixels.
' ScaleFrom The unit of measurement to scale from.
' hDC Optional. The device context that Width relates to.
'
' RETURNS The value scaled to pixels.
'===========================================================================
====
Dim LOGPIXELS As Long
' No error handler
On Error GoTo 0
' Use current meta device as a basic for the scale, if any,
' otherwise use the screen device.
If IsValidHandle(hdc) Then
' Get # of pixels per logical inch
LOGPIXELS = GetDeviceCaps(hdc, LOGPIXELSX)
Else
' Get the screen device
hdc = GetDC(0&)
' Get # of pixels per logical inch
LOGPIXELS = GetDeviceCaps(hdc, LOGPIXELSX)
' Release the screen
ReleaseDC 0, hdc
End If
' Now for perform the conversion
Select Case ScaleTo
Case vbCentimeters
' Convert to centimeters; 2540 = himetric units per inch
DeviceToLogicalX = (Width * 2.54) / LOGPIXELS
Case vbMillimeters
' Convert to millimeters; 2540 = himetric units per inch
DeviceToLogicalX = (Width * 25.4) / LOGPIXELS
Case vbHimetric
' Convert to himetric; 2540 = himetric units per inch
DeviceToLogicalX = (Width * 2540) / LOGPIXELS
Case vbTwips
' Convert from twips; 1440 = twips per inch
DeviceToLogicalX = (Width * 1440) / LOGPIXELS
Case vbCharacters
' Convert from twips; 1 horizontal character = 120 twips per unit;
vertical = 240 twips per unit
DeviceToLogicalX = ((Width * 1440) / LOGPIXELS) / 120
Case vbInches
' Convert from twips; 1440 = twips per inch
DeviceToLogicalX = Width / LOGPIXELS
Case vbPoints
' Convert from twips; 72 = points per inch
DeviceToLogicalX = ((Width * 1440) / LOGPIXELS) / 20
Case vbPixels
' No conversion needed for pixels
DeviceToLogicalX = Width
Case Else
Err.Raise 5, Module
End Select
ExitLabel:
Exit Function
End Function
Public Function DeviceToLogicalY(ByVal Height As Single, ByVal ScaleTo As
ScaleModeConstants, Optional ByVal hdc As Long) As Single
'===========================================================================
====
' DeviceToLogicalY - Converts the supplied Height to the desired logical
unit.
'
' Height The value to convert from pixels.
' ScaleFrom The unit of measurement to scale from.
' hDC Optional. The device context that Width relates to.
'
' RETURNS The value scaled to pixels.
'===========================================================================
====
Dim LOGPIXELS As Long
' No error handler
On Error GoTo 0
' Use current meta device as a basic for the scale, if any,
' otherwise use the screen device.
If IsValidHandle(hdc) Then
' Get # of pixels per logical inch
LOGPIXELS = GetDeviceCaps(hdc, LOGPIXELSY)
Else
' Get the screen device
hdc = GetDC(0&)
' Get # of pixels per logical inch
LOGPIXELS = GetDeviceCaps(hdc, LOGPIXELSY)
' Release the screen
ReleaseDC 0, hdc
End If
' Now for perform the conversion
Select Case ScaleTo
Case vbCentimeters
' Convert to centimeters; 2540 = himetric units per inch
DeviceToLogicalY = (Height * 2.54) / LOGPIXELS
Case vbMillimeters
' Convert to millimeters; 2540 = himetric units per inch
DeviceToLogicalY = (Height * 25.4) / LOGPIXELS
Case vbHimetric
' Convert to himetric; 2540 = himetric units per inch
DeviceToLogicalY = ((Height * 2540) / LOGPIXELS)
Case vbTwips
' Convert from twips; 1440 = twips per inch
DeviceToLogicalY = (Height * 1440) / LOGPIXELS
Case vbCharacters
' Convert from twips; 1 horizontal character = 120 twips per unit;
vertical = 240 twips per unit
DeviceToLogicalY = ((Height * 1440) / LOGPIXELS) / 240
Case vbInches
' Convert from twips; 1440 = twips per inch
DeviceToLogicalY = Height / LOGPIXELS
Case vbPoints
' Convert from twips; 72 = points per inch
DeviceToLogicalY = ((Height * 1440) / LOGPIXELS) / 20
Case vbPixels
' No conversion needed for pixels
DeviceToLogicalY = Height
Case Else
Err.Raise 5, Module
End Select
ExitLabel:
Exit Function
End Function
Public Function IsValidHandle(ByVal Handle As Long) As Boolean
Const INVALID_HANDLE_VALUE = -1
Select Case Handle
Case 0, INVALID_HANDLE_VALUE
Case Else
IsValidHandle = True
End Select
End Function
"Mike D Sutton" <Mike....@btclick.com> wrote in message
news:t5kD6.18203$986.27795@NewsReader...