Datareport problem.....
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Datareport problem.....

  1. #1
    Join Date
    Oct 2008
    Location
    Surigao City
    Posts
    8

    Datareport problem.....

    i have a problem with the datareport........
    i want to set my datareport in different size...
    but i have no idea on how to use the API...
    because it takes time adjusting my page size,layout on the
    control panel.......

    please help me.............

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,982

    Re: Datareport problem.....

    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jan 2006
    Location
    Pearl of the orient
    Posts
    303

    Re: Datareport problem.....

    You may also try this...
    Code:
    Option Explicit
    
    Private Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, pDefault As PRINTER_DEFAULTS) As Long
    Private Declare Function SetPrinter Lib "winspool.drv" Alias "SetPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, pPrinter As Any, ByVal Command As Long) As Long
    Private Declare Function GetPrinter Lib "winspool.drv" Alias "GetPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, pPrinter As Any, ByVal cbBuf As Long, pcbNeeded As Long) As Long
    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)
    Private Declare Function ClosePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long
    Private Declare Function DocumentProperties Lib "winspool.drv" Alias "DocumentPropertiesA" (ByVal hWnd As Long, ByVal hPrinter As Long, ByVal pDeviceName As String, pDevModeOutput As Any, pDevModeInput As Any, ByVal fMode As Long) As Long
    
    Private Const CCHDEVICENAME = 32
    Private Const CCHFORMNAME = 32
    
    Private Const STANDARD_RIGHTS_REQUIRED = &HF0000
    Private Const PRINTER_ACCESS_ADMINISTER = &H4
    Private Const PRINTER_ACCESS_USE = &H8
    Private Const PRINTER_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or PRINTER_ACCESS_ADMINISTER Or PRINTER_ACCESS_USE)
    
    Private Const DM_MODIFY = 8
    Private Const DM_IN_BUFFER = DM_MODIFY
    Private Const DM_COPY = 2
    Private Const DM_OUT_BUFFER = DM_COPY
    'Private Const DM_DUPLEX = &H1000&
    'Private Const DMDUP_SIMPLEX = 1
    'Private Const DMDUP_VERTICAL = 2
    'Private Const DMDUP_HORIZONTAL = 3
    'Private Const DM_ORIENTATION = &H1&
    
    Private Const DMPAPER_LEGAL As Long = 5
    Private Const DMPAPER_LETTER As Long = 1
    'Private Const DMPAPER_FIRST = DMPAPER_LETTER
    'Private Const DMPAPER_LETTERSMALL = 2          ' Letter Small 8 1/2 x 11 in
    'Private Const DMPAPER_TABLOID = 3              ' Tabloid 11 x 17 in
    'Private Const DMPAPER_LEDGER = 4               ' Ledger 17 x 11 in
    'Private Const DMPAPER_STATEMENT = 6            ' Statement 5 1/2 x 8 1/2 in
    ''Private Const DMPAPER_EXECUTIVE = 7            ' Executive 7 1/4 x 10 1/2 in
    'Private Const DMPAPER_A3 = 8                   ' A3 297 x 420 mm
    'Private Const DMPAPER_A4 = 9                   ' A4 210 x 297 mm
    'Private Const DMPAPER_A4SMALL = 10             ' A4 Small 210 x 297 mm
    'Private Const DMPAPER_A5 = 11                  ' A5 148 x 210 mm
    'Private Const DMPAPER_B4 = 12                  ' B4 250 x 354
    'Private Const DMPAPER_B5 = 13                  ' B5 182 x 257 mm
    'Private Const DMPAPER_FOLIO = 14               ' Folio 8 1/2 x 13 in
    'Private Const DMPAPER_QUARTO = 15              ' Quarto 215 x 275 mm
    'Private Const DMPAPER_10X14 = 16               ' 10x14 in
    'Private Const DMPAPER_11X17 = 17               ' 11x17 in
    'Private Const DMPAPER_NOTE = 18                ' Note 8 1/2 x 11 in
    'Private Const DMPAPER_ENV_9 = 19               ' Envelope #9 3 7/8 x 8 7/8
    'Private Const DMPAPER_ENV_10 = 20              ' Envelope #10 4 1/8 x 9 1/2
    'Private Const DMPAPER_ENV_11 = 21              ' Envelope #11 4 1/2 x 10 3/8
    'Private Const DMPAPER_ENV_12 = 22              ' Envelope #12 4 \276 x 11
    'Private Const DMPAPER_ENV_14 = 23              ' Envelope #14 5 x 11 1/2
    'Private Const DMPAPER_CSHEET = 24              ' C size sheet
    'Private Const DMPAPER_DSHEET = 25              ' D size sheet
    'Private Const DMPAPER_ESHEET = 26              ' E size sheet
    'Private Const DMPAPER_ENV_DL = 27              ' Envelope DL 110 x 220mm
    'Private Const DMPAPER_ENV_C5 = 28              ' Envelope C5 162 x 229 mm
    'Private Const DMPAPER_ENV_C3 = 29              ' Envelope C3  324 x 458 mm
    'Private Const DMPAPER_ENV_C4 = 30              ' Envelope C4  229 x 324 mm
    'Private Const DMPAPER_ENV_C6 = 31              ' Envelope C6  114 x 162 mm
    'Private Const DMPAPER_ENV_C65 = 32             ' Envelope C65 114 x 229 mm
    'Private Const DMPAPER_ENV_B4 = 33              ' Envelope B4  250 x 353 mm
    'Private Const DMPAPER_ENV_B5 = 34              ' Envelope B5  176 x 250 mm
    'Private Const DMPAPER_ENV_B6 = 35              ' Envelope B6  176 x 125 mm
    'Private Const DMPAPER_ENV_ITALY = 36           ' Envelope 110 x 230 mm
    'Private Const DMPAPER_ENV_MONARCH = 37         ' Envelope Monarch 3.875 x 7.5 in
    'Private Const DMPAPER_ENV_PERSONAL = 38        ' 6 3/4 Envelope 3 5/8 x 6 1/2 in
    'Private Const DMPAPER_FANFOLD_US = 39          ' US Std Fanfold 14 7/8 x 11 in
    'Private Const DMPAPER_FANFOLD_STD_GERMAN = 40  ' German Std Fanfold 8 1/2 x 12 in
    'Private Const DMPAPER_FANFOLD_LGL_GERMAN = 41  ' German Legal Fanfold 8 1/2 x 13 in
    Private Const DMORIENT_PORTRAIT As Long = 1
    Private Const DMORIENT_LANDSCAPE As Long = 2
    
    Private Type DEVMODE
        dmDeviceName As String * CCHDEVICENAME
        dmSpecVersion As Integer
        dmDriverVersion As Integer
        dmSize As Integer
        dmDriverExtra As Integer
        dmFields As Long
        dmOrientation As Long
        dmPaperSize As Long
        dmPaperWidth As Integer
        dmScale As Integer
        dmCopies As Integer
        dmDefaultSource As Integer
        dmPrintQuality As Integer
        dmColor As Integer
        dmDuplex As Integer
        dmYResolution As Integer
        dmTTOption As Integer
        dmCollate As Integer
        dmFormName As String * CCHFORMNAME
        dmLogPixels As Integer
        dmBitsPerPel As Long
        dmPelsWidth As Long
        dmPelsHeight As Long
        dmDisplayFlags As Long
        dmDisplayFrequency As Long
        dmICMMethod As Long
        dmICMIntent As Long
        dmMediaType As Long
        dmDitherType As Long
        dmReserved1 As Long
        dmReserved2 As Long
    End Type
    
    Public Type PRINTER_DEFAULTS
        pDataType As String
        pDevMode As Long
        DesiredAccess As Long
    End Type
    
    Public Enum MyPrinterPaperSize
        LETTER = DMPAPER_LETTER
        LEGAL = DMPAPER_LEGAL
    End Enum
    
    Public Enum MyPrinterOrientation
        PORTRAIT = DMORIENT_PORTRAIT
        LANDSCAPE = DMORIENT_LANDSCAPE
    End Enum
    
    Private InitialPaperSize As Long
    Private InitialPaperOrit As Long
    Private CallingHwnd As Long
    
    Public Sub ChangePaperSize(MyHwnd As Long, PaperSize As MyPrinterPaperSize, Optional Orientation As MyPrinterOrientation = 0)
        Dim PrinterHandle As Long
        Dim PrinterName As String
        Dim pd As PRINTER_DEFAULTS
        Dim MyDevMode As DEVMODE
        Dim result As Long
        Dim Needed As Long
        Dim pFullDevMode As Long
        Dim pi2_buffer() As Long
        CallingHwnd = MyHwnd
        PrinterName = Printer.DeviceName
        If PrinterName = vbNullString Then
            Exit Sub
        End If
        pd.pDataType = vbNullString
        pd.pDevMode = 0&
        pd.DesiredAccess = PRINTER_ALL_ACCESS
        result = OpenPrinter(PrinterName, PrinterHandle, pd)
        result = GetPrinter(PrinterHandle, 2, ByVal 0&, 0, Needed)
        ReDim pi2_buffer((Needed \ 4))
        result = GetPrinter(PrinterHandle, 2, pi2_buffer(0), Needed, Needed)
        pFullDevMode = pi2_buffer(7)
        Call CopyMemory(MyDevMode, ByVal pFullDevMode, Len(MyDevMode))
        InitialPaperSize = MyDevMode.dmPaperSize
        InitialPaperOrit = MyDevMode.dmOrientation
        MyDevMode.dmPaperSize = PaperSize
        If Orientation <> 0 Then MyDevMode.dmOrientation = Orientation
        Call CopyMemory(ByVal pFullDevMode, MyDevMode, Len(MyDevMode))
        result = DocumentProperties(MyHwnd, PrinterHandle, PrinterName, ByVal pFullDevMode, ByVal pFullDevMode, DM_IN_BUFFER Or DM_OUT_BUFFER)
        result = SetPrinter(PrinterHandle, 2, pi2_buffer(0), 0&)
        Call ClosePrinter(PrinterHandle)
    End Sub
    
    Public Sub RestorePrinterDefaults()
        Dim pd              As PRINTER_DEFAULTS
        Dim MyDevMode       As DEVMODE
        Dim result          As Long
        Dim Needed          As Long
        Dim pFullDevMode    As Long
        Dim pi2_buffer()    As Long
        Dim PrinterHandle   As Long
        Dim PrinterName     As String
    
        PrinterName = Printer.DeviceName
        If PrinterName = vbNullString Then
            Exit Sub
        End If
    
        pd.pDataType = vbNullString
        pd.pDevMode = 0&
        pd.DesiredAccess = PRINTER_ALL_ACCESS
    
        result = OpenPrinter(PrinterName, PrinterHandle, pd)
    
        result = GetPrinter(PrinterHandle, 2, ByVal 0&, 0, Needed)
        ReDim pi2_buffer((Needed \ 4))
        result = GetPrinter(PrinterHandle, 2, pi2_buffer(0), Needed, Needed)
    
        pFullDevMode = pi2_buffer(7)
    
        Call CopyMemory(MyDevMode, ByVal pFullDevMode, Len(MyDevMode))
        MyDevMode.dmPaperSize = InitialPaperSize
        MyDevMode.dmOrientation = InitialPaperOrit
        Call CopyMemory(ByVal pFullDevMode, MyDevMode, Len(MyDevMode))
        result = DocumentProperties(CallingHwnd, PrinterHandle, PrinterName, ByVal pFullDevMode, ByVal pFullDevMode, DM_IN_BUFFER Or DM_OUT_BUFFER)
        result = SetPrinter(PrinterHandle, 2, pi2_buffer(0), 0&)
    
        Call ClosePrinter(PrinterHandle)
    End Sub

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center