+ Reply to Thread
Results 1 to 3 of 3

Right margin, top margin

  1. #1
    Registered User
    Join Date
    02-20-2005
    Posts
    6

    Right margin, top margin

    HI there,

    now i found a way to get informations about the non printable left and top margin of a printer using GetDeviceCaps (PHYSICALOFFSETX , PHYSICALOFFSETY).

    But I can't find any information about the right and bottom margins. I assume they are different from the left and top offset. Does anybody know, where I find information about this topic?

    The users settings about the margins are located in the printer driver. How can I read this settings?

    Thanks in advance for any hint,

    TopSat

  2. #2
    Forum Contributor
    Join Date
    12-11-2004
    MS-Off Ver
    2007
    Posts
    137
    Hello TopSat

    I hope this help you


    Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" _
    (ByVal lpDriverName As String, ByVal lpDeviceName As String, _
    ByVal lpOutput As Long, ByVal lpInitData As Long) As Long

    Declare Function GetDeviceCaps Lib "gdi32" _
    (ByVal hdc As Long, ByVal nIndex As Long) As Long

    Const HORZRES = 8
    Const VERTRES = 10
    Const LOGPIXELSX = 88
    Const LOGPIXELSY = 90
    Const PHYSICALWIDTH = 110
    Const PHYSICALHEIGHT = 111
    Const PHYSICALOFFSETX = 112
    Const PHYSICALOFFSETY = 113

    Sub ProprietesZoneImpressionImprimante()
    'source http://support.microsoft.com/?id=193943
    Dim dpiX As Long, dpiY As Long
    Dim MarginLeft As Long, MarginRight As Long
    Dim MarginTop As Long, MarginBottom As Long
    Dim PrintAreaHorz As Long, PrintAreaVert As Long
    Dim PhysHeight As Long, PhysWidth As Long
    Dim Info As String, Cible As String
    Dim HwndPrint As Long

    Cible = "hp deskjet 940c series" 'printer name
    HwndPrint = CreateDC(0, Cible, 0, 0)

    dpiX = GetDeviceCaps(HwndPrint, LOGPIXELSX)
    Info = "Pixels X: " & dpiX & " dpi"

    dpiY = GetDeviceCaps(HwndPrint, LOGPIXELSY)
    Info = Info & vbCrLf & "Pixels Y: " & dpiY & " dpi"

    MarginLeft = GetDeviceCaps(HwndPrint, PHYSICALOFFSETX)
    Info = Info & vbCrLf & "Unprintable space on left: " & _
    MarginLeft & " pixels (" & Format(MarginLeft / dpiX, "0.000") & " inches)"

    MarginTop = GetDeviceCaps(HwndPrint, PHYSICALOFFSETY)
    Info = Info & vbCrLf & "Unprintable space on top: " & _
    MarginTop & " pixels (" & Format(MarginTop / dpiY, "0.000") & " inches)"

    PrintAreaHorz = GetDeviceCaps(HwndPrint, HORZRES)
    Info = Info & vbCrLf & "Printable space (Horizontal): " & _
    PrintAreaHorz & " pixels (" & Format(PrintAreaHorz / dpiX, "0.000") & " inches)"

    PrintAreaVert = GetDeviceCaps(HwndPrint, VERTRES)
    Info = Info & vbCrLf & "Printable space (Vertical): " & _
    PrintAreaVert & " pixels (" & Format(PrintAreaVert / dpiY, "0.000") & " inches)"

    PhysWidth = GetDeviceCaps(HwndPrint, PHYSICALWIDTH)
    Info = Info & vbCrLf & "Total space (Horizontal): " & _
    PhysWidth & " pixels (" & Format(PhysWidth / dpiX, "0.000") & " inches)"

    MarginRight = PhysWidth - PrintAreaHorz - MarginLeft
    Info = Info & vbCrLf & "Unprintable space on right: " & _
    MarginRight & " pixels (" & Format(MarginRight / dpiX, "0.000") & " inches)"

    PhysHeight = GetDeviceCaps(HwndPrint, PHYSICALHEIGHT)
    Info = Info & vbCrLf & "Total space (Vertical): " & _
    PhysHeight & " pixels (" & Format(PhysHeight / dpiY, "0.000") & " inches)"

    MarginBottom = PhysHeight - PrintAreaVert - MarginTop
    Info = Info & vbCrLf & "Unprintable space on bottom: " & _
    MarginBottom & " pixels (" & Format(MarginBottom / dpiY, "0.000") & " inches)"

    MsgBox Info, , "Information"

    End Sub



    Regards ,
    michel

  3. #3
    Registered User
    Join Date
    02-20-2005
    Posts
    6

    Thumbs up

    Hi Michel,

    sorry for being so late. Thanks a lot for the code to determine the devicecaps values.

    Regards,

    TopSat

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1