[RESOLVED] Converting pixels to points?
Is there a way of converting pixels to points? The dimensions in VB are in pixels, but Office COM such as WordApp.Resize are expressed in points. So trying to align app windows is a mess.
I guess the ratio of pixels to points varies from one monitor to another(?), so this would need to be calculated at run time.
I tried a nifty trick of doing Me.Font.SizeInPoints / Me.FontHeight but that doesnt seem to be quite right or a very sensible way of doing it.
Re: Converting pixels to points?
Ive cracked it...
For posterity (and to save anyone else spending an entire day trying to get API's to work) here is the code.
VB Code:
Public Declare Function GetDC Lib "user32" (ByVal hwnd As IntPtr) As Int32
Public Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As IntPtr, ByVal nIndex As Int32) As Int32
Public Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Int32, ByVal hdc As Int32) As Int32
Public Const LOGPIXELSX = 88
Private Const POINTS_PER_INCH As Long = 72
Public Function PointsPerPixel() As Double
Dim hDC As IntPtr
Dim lDotsPerInch As Int32
hDC = GetDC(IntPtr.Zero)
lDotsPerInch = GetDeviceCaps(hDC, LOGPIXELSX)
PointsPerPixel = POINTS_PER_INCH / lDotsPerInch
ReleaseDC(IntPtr.Zero, hDC)
Return PointsPerPixel
End Function
Re: [RESOLVED] Converting pixels to points?
Hi
thanks for your answer. But can you explain about the folloeing lines? and what are 88 and 72? are they g.DpiX and g.DpiY?
Public Const LOGPIXELSX = 88
Private Const POINTS_PER_INCH As Long = 72