OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Developer Forums > VBA > CorelDRAW/Corel DESIGNER VBA

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 02-10-2012, 06:05
3dvr 3dvr is offline
Junior Member
 
Join Date: Oct 2008
Posts: 8
Thumbs down How to get the print range?

Hi, everybody!
I Ask,
How to get the print range?
(Printer can really print area)

Last edited by 3dvr; 02-10-2012 at 10:37.
Reply With Quote
  #2  
Old 02-10-2012, 14:39
runflacruiser's Avatar
runflacruiser runflacruiser is offline
Senior Member
 
Join Date: Jun 2009
Location: Pigeon Forge, TN USA
Posts: 811
Default

Hi.
You can't get this info from printer so you need to use properties from Page such as :
Page.SizeWidth
Page.SizeHeight
Page.Paper

~John
Reply With Quote
  #3  
Old 02-10-2012, 21:57
3dvr 3dvr is offline
Junior Member
 
Join Date: Oct 2008
Posts: 8
Default

I refer to this region,
It will change the printer:

Last edited by 3dvr; 02-10-2012 at 21:59.
Reply With Quote
  #4  
Old 10-10-2012, 16:38
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,769
Blog Entries: 9
Send a message via ICQ to shelbym Send a message via AIM to shelbym Send a message via MSN to shelbym Send a message via Yahoo to shelbym
Default Printable Area

I do not believe there is a native way in VBA to do this, you can do it via some API calls. This code is 32-bit, it would need to be modified for CorelDRAW X6 64-bit.
Code:
Private Declare Function CreateIC Lib "gdi32" Alias "CreateICA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, ByVal lpInitData As Long) As Long
Private Declare Function DeleteDC32 Lib "gdi32" Alias "DeleteDC" (ByVal hDC As Long) As Long
Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hDC As Long, ByVal nIndex As Long) As Long

Sub OutputMargins()
    GetPrintableArea "Brother MFC-5895CW Printer"
End Sub

Public Function GetPrintableArea(ByVal strPrinterName As String, Optional ByVal lngDevMode As Long = 0&)
    Dim lngPhysicalWidth As Long
    Dim lngPhysicalHeight As Long
    Dim lngLeftOffSet As Long
    Dim lngTopOffSet As Long
    Dim lngRightOffset As Long
    Dim lngBottomOffset As Long
    Dim lngLogPX As Long
    Dim lngLogPY As Long
    Dim lngLeftMargin!, lngRightMargin!, lngTopMargin!, lngBottomMargin!
    Dim dwReturn&
    Dim hPDC As Long

    Const PHYSICALWIDTH = 110 ' Physical Width in device units
    Const PHYSICALHEIGHT = 111 ' Physical Height in device units
    Const PHYSICALOFFSETX = 112 ' Physical Printable Area x margin
    Const PHYSICALOFFSETY = 113 ' Physical Printable Area y margin
    Const LOGPIXELSX = 88 ' Logical pixels/inch in X
    Const LOGPIXELSY = 90 ' Logical pixels/inch in Y
    Const HORZRES = 8 ' Horizontal width in pixels
    Const VERTRES = 10 ' Vertical width in pixels

    hPDC = MakePDC(strPrinterName, lngDevMode)
    If hPDC = 0 Then Exit Function

    lngLeftOffSet = GetDeviceCaps(hPDC, PHYSICALOFFSETX)
    lngTopOffSet = GetDeviceCaps(hPDC, PHYSICALOFFSETY)
    lngPhysicalWidth = GetDeviceCaps(hPDC, PHYSICALWIDTH)
    lngPhysicalHeight = GetDeviceCaps(hPDC, PHYSICALHEIGHT)
    lngLogPX = GetDeviceCaps(hPDC, LOGPIXELSX)
    lngLogPY = GetDeviceCaps(hPDC, LOGPIXELSY)
    lngRightOffset = lngPhysicalWidth - GetDeviceCaps(hPDC, HORZRES) - lngLeftOffSet
    lngBottomOffset = lngPhysicalHeight - GetDeviceCaps(hPDC, VERTRES) - lngTopOffSet
    lngTopMargin = lngTopOffSet / lngLogPY
    lngBottomMargin = lngBottomOffset / lngLogPY
    lngLeftMargin = lngLeftOffSet / lngLogPX
    lngRightMargin = lngRightOffset / lngLogPX

    Debug.Print "Min Top Margin Inches " & lngTopMargin & "; Twips: " & lngTopMargin * 1440
    Debug.Print "Min Bottom Margin Inches " & lngBottomMargin & "; Twips " & lngBottomMargin * 1440
    Debug.Print "Min Left Margin Inches " & lngLeftMargin & "; Twips: " & lngLeftMargin * 1440
    Debug.Print "Min Right Margin Inches " & lngRightMargin & "; Twips: " & lngRightMargin * 1440
    Debug.Print "Min Top Margin MM " & DblRound((lngTopMargin * 1440 / 566.9) * 10, 2)
    Debug.Print "Min Bottom Margin MM " & DblRound((lngBottomMargin * 1440 / 566.9) * 10, 2)
    Debug.Print "Min Left Margin MM " & DblRound((lngLeftMargin * 1440 / 566.9) * 10, 2)
    Debug.Print "Min Right Margin MM " & DblRound((lngRightMargin * 1440 / 566.9) * 10, 2)
    
    dwReturn = DeleteDC32(hPDC)
End Function

Public Function MakePDC(ByVal strPrinterDevice As String, Optional lngDevMode As Long) As Long
    Dim hDC As Long
    hDC = CreateIC("WINSPOOL", strPrinterDevice, vbNullString, lngDevMode)
    MakePDC = hDC
End Function

Public Function DblRound(ByVal Number As Variant, NumDigits As Long, Optional UseBankersRounding As Boolean = False) As Double
    Dim dblPower As Double
    Dim varTemp As Variant
    Dim intSgn As Integer
    
    If Not IsNumeric(Number) Then
    ' Raise an error indicating that
    ' you've supplied an invalid parameter.
    Err.Raise 5
    End If
    dblPower = 10 ^ NumDigits
    ' Is this a negative number, or not?
    ' intSgn will contain -1, 0, or 1.
    intSgn = Sgn(Number)
    Number = Abs(Number)
    
    ' Do the major calculation.
    varTemp = CDec(Number) * dblPower + 0.5
    
    ' Now round to nearest even, if necessary.
    If UseBankersRounding Then
    If Int(varTemp) = varTemp Then
    ' You could also use:
    ' varTemp = varTemp + (varTemp Mod 2 = 1)
    ' instead of the next If ...Then statement,
    ' but I hate counting on TRue == -1 in code.
    If varTemp Mod 2 = 1 Then
    varTemp = varTemp - 1
    End If
    End If
    End If
    ' Finish the calculation.
    DblRound = intSgn * Int(varTemp) / dblPower
End Function
Output is in the VBA Immediate window and would look something like this:
Code:
Min Top Margin Inches 0.1166667; Twips: 168
Min Bottom Margin Inches 0.12; Twips 172.8
Min Left Margin Inches 0.1166667; Twips: 168
Min Right Margin Inches 0.12; Twips: 172.8
Min Top Margin MM 2.96
Min Bottom Margin MM 3.05
Min Left Margin MM 2.96
Min Right Margin MM 3.05
Hope that helps,

-Shelby
Reply With Quote
  #5  
Old 11-10-2012, 00:37
3dvr 3dvr is offline
Junior Member
 
Join Date: Oct 2008
Posts: 8
Default

Thank you,
I will try again....
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
BUG: Print events don't work when printing from Print Preview runflacruiser CorelDRAW/Corel DESIGNER VBA 2 09-08-2011 13:47
Simple Print Msg that comes up before print icons fungel General 1 10-10-2010 17:23
Use shapes in a range Manuel CorelDRAW/Corel DESIGNER VBA 1 09-05-2007 14:55
range problem chinkyk CorelDRAW/Corel DESIGNER VBA 0 20-10-2004 11:00
Import - Value out of Range ddonnahoe CorelDRAW/Corel DESIGNER VBA 0 13-04-2004 14:10


All times are GMT -5. The time now is 00:40.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com