Re: Update a graphic and save it



I must be doing something stupid, I can't get similar font sizes going to
the printer and the image. I am using the following code:
...
height = -MulDiv(12, GetDeviceCaps(hdc, LOGPIXELSY), 72)
hfont = CreateFont(height, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "Times New
Roman")
holdfont = SelectObject(hdc, hfont)
...
in a routine I call twice, once with the hdc from CreateCompatableDC(0), and
once with Printer.hdc. The font height seems to ba all out of wack. Is
there someting else I need to be doing?

The MulDiv() technique you're using to calculate the font size only works if the MM_TEXT mapping mode is set on the
target DC (unusual for a printer, which is capable of much higher resolutions than your standard display device.)
Since this method returns the height in pixels (which map 1:1 with device space), you can use the DPtoLP() API call to
convert this to logical space on the target DC:

'***
Private Declare Function DPtoLP Lib "GDI32.dll" (ByVal hDC As Long, _
ByRef lpPoint As PointAPI, ByVal nCount As Long) As Long
Private Declare Function SetMapMode Lib "GDI32.dll" ( _
ByVal hDC As Long, ByVal nMapMode As Long) As Long

Private Const MM_TEXT As Long = &H1

Private Type PointAPI
X As Long
Y As Long
End Type

....

Dim OldMapMode As Long
Dim PenSize As PointAPI

OldMapMode = SetMapMode(hdc, MM_TEXT)
PenSize.X = MulDiv(12, GetDeviceCaps(hdc, LOGPIXELSY), 72)

If (OldMapMode <> MM_TEXT) Then
' Perform device to logical space mapping
Call DPtoLP(hdc, PenSize, 1)
Call SetMapMode(hdc, OldMapMode)
End If

PenSize.X = -Abs(PenSize.X)

' PenSize.X should now contain correct mapping for the target DC
'***

Hope this helps,

Mike


- Microsoft Visual Basic MVP -
E-Mail: EDais@xxxxxxxx
WWW: Http://EDais.mvps.org/


.



Relevant Pages

  • Re: Importing JPEG data into spreadsheet
    ... Shapes can be sized very small and do not need to be constrained to cell ... Lib "gdi32" (ByVal hdc As Long, ... Private Declare Function StretchBlt Lib "gdi32" _ ...
    (microsoft.public.excel.programming)
  • Re: Importing JPEG data into spreadsheet
    ... Shapes can be sized very small and do not need to be constrained to cell ... Lib "gdi32" (ByVal hdc As Long, ... Private Declare Function StretchBlt Lib "gdi32" _ ...
    (microsoft.public.excel.programming)
  • Re: Select polygon on EMF on MouseOver
    ... Private Declare Function SetWindowExtEx Lib "GDI32.dll" (ByVal hDC As Long, ... ByVal nX As Long, ByVal nY As Long, ByRef lpPoint As Any) As Long ...
    (microsoft.public.vb.general.discussion)
  • Re: Error 480 - cant create autoredraw image
    ... Private Declare Function CreateCompatibleDC Lib "GDI32.dll" (ByVal hDC As Long) As Long ... Const DemoText As String = "Hello, ...
    (microsoft.public.vb.general.discussion)
  • Re: Mike D Suttons rotated label control
    ... Private Declare Function SetWorldTransform Lib "GDI32.dll" (_ ... ByVal hDC As Long, ByRef lpXform As XForm) As Long ... Dim OldXForm As XForm, RotXForm As XForm ...
    (microsoft.public.vb.general.discussion)

Loading