Click here to Skip to main content
15,912,578 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: working on charts in vb.net Pin
Abbhie21-Sep-07 6:24
Abbhie21-Sep-07 6:24 
GeneralRe: working on charts in vb.net Pin
DanB198321-Sep-07 6:28
DanB198321-Sep-07 6:28 
QuestionVB.NET Events Pin
Richard J. Hanney21-Sep-07 3:47
Richard J. Hanney21-Sep-07 3:47 
AnswerRe: VB.NET Events Pin
Tom Deketelaere21-Sep-07 4:18
professionalTom Deketelaere21-Sep-07 4:18 
AnswerRe: VB.NET Events Pin
nlarson1121-Sep-07 4:20
nlarson1121-Sep-07 4:20 
GeneralRe: VB.NET Events Pin
Richard J. Hanney22-Sep-07 1:37
Richard J. Hanney22-Sep-07 1:37 
QuestionNeed help using DocumentProperties Pin
BS_Schimmel21-Sep-07 3:38
BS_Schimmel21-Sep-07 3:38 
AnswerRe: Need help using DocumentProperties Pin
BS_Schimmel23-Sep-07 19:34
BS_Schimmel23-Sep-07 19:34 
ok, I updated the code and now the DocumentProperties function returns no error... but the settings are not applied on the new printer....

Public Function fMovePrinter( _<br />
                                ByVal sSource As String, _<br />
                                ByVal sDestination As String, _<br />
                                ByVal sPrinter As String, _<br />
                                ByVal lvSource As ListView, _<br />
                                ByVal lvDestination As ListView, _<br />
                                ByVal bDelete As Boolean _<br />
                                ) As Boolean<br />
<br />
        'first open the source printer to get the handle<br />
        Dim hSource As IntPtr<br />
        Dim pd As New PRINTER_DEFAULTS<br />
<br />
        pd.DesiredAccess = PrinterAccessRights.PRINTER_ALL_ACCESS<br />
        If Not OpenPrinter(sPrinter, hSource, pd) Then<br />
            Throw New Exception(Err.LastDllError & " unable to OpenPrinter " & sPrinter)<br />
            Return False<br />
        End If<br />
<br />
        'now call the GetPrinter API to get the PRINTER_INFO_2 structure<br />
        Dim BytesWritten As Int32 = 0<br />
        Dim ptBuf As IntPtr<br />
        Dim pi2 As New PRINTER_INFO_2<br />
        Dim dmOut As New DEVMODE<br />
<br />
        ptBuf = Marshal.AllocHGlobal(1)<br />
<br />
        'Get the number of bytes needed<br />
        If Not GetPrinter(hSource, 2, ptBuf, 1, BytesWritten) Then<br />
            If BytesWritten > 0 Then<br />
                Marshal.FreeHGlobal(ptBuf)<br />
                ptBuf = Marshal.AllocHGlobal(BytesWritten)<br />
                'Get the PRINTER_INFO_2 structure<br />
                If GetPrinter(hSource, 2, ptBuf, BytesWritten, BytesWritten) Then<br />
                    Marshal.PtrToStructure(ptBuf, pi2)<br />
                    If pi2.lpDeviceMode > 0 Then<br />
                        'Get the DEVMODE structure<br />
                        Dim ptrDevMode As New IntPtr(pi2.lpDeviceMode)<br />
                        Marshal.PtrToStructure(ptrDevMode, dmOut)<br />
                    End If<br />
                Else<br />
                    Marshal.FreeHGlobal(ptBuf)<br />
                    ClosePrinter(hSource)<br />
                    Throw New Exception(Err.LastDllError & " unable to GetPrinter #2 " & sPrinter)<br />
                    Return False<br />
                End If<br />
                'free ptBuf<br />
                Marshal.FreeHGlobal(ptBuf)<br />
                'ClosePrinter(hSource)<br />
            Else<br />
                Throw New Exception(Err.LastDllError & " BytesWritten #1 " & BytesWritten)<br />
                Return False<br />
            End If<br />
<br />
        Else<br />
            Throw New Exception(Err.LastDllError & " unable to GetPrinter #1 " & sPrinter)<br />
            Return False<br />
        End If<br />
<br />
        'modify the pi2 structure with the needed parameters<br />
        Dim strPrinter As String<br />
        strPrinter = sPrinter<br />
        If strPrinter.LastIndexOf("\") > 0 Then<br />
            strPrinter = strPrinter.Remove(strPrinter.IndexOf("\"), strPrinter.LastIndexOf("\") + 1)<br />
        End If<br />
<br />
        With pi2<br />
            .pPrinterName = strPrinter<br />
            .pServerName = sDestination<br />
            .pPortName = "LPT1:"<br />
        End With<br />
<br />
        'change the DEVMODE structure with the needed parameters<br />
        Dim strFullPrinterPath As String = "\\" & sDestination & "\" & strPrinter<br />
        With dmOut<br />
            .pDeviceName = strFullPrinterPath<br />
        End With<br />
<br />
        'copy the devmode structure back into the PRINTER_INFO_2 structure<br />
        'Dim hdmIn As IntPtr<br />
        pi2.lpDeviceMode = Marshal.AllocHGlobal(Marshal.SizeOf(dmOut))<br />
        Marshal.StructureToPtr(dmOut, pi2.lpDeviceMode, False)<br />
<br />
        If bDelete = True Then<br />
            Call DeletePrinter(hSource)<br />
            hSource = IntPtr.Zero<br />
        End If<br />
<br />
        'create the printer on the destination<br />
        Dim hDestination As IntPtr<br />
        hDestination = AddPrinter("\\" & sDestination, 2, pi2)<br />
        If hDestination = 0 Then<br />
            If Err.LastDllError = 1802 Then<br />
                Call DeletePrinter(hSource)<br />
                Debug.Print(Err.LastDllError.ToString)<br />
                hDestination = AddPrinter("\\" & sDestination, 2, pi2)<br />
                If hDestination = 0 Then<br />
                    Throw New Exception(Err.LastDllError & " unable to AddPrinter, tried twice because printer allready exists on " & sDestination)<br />
                    Return False<br />
                End If<br />
            Else<br />
                Throw New Exception(Err.LastDllError & " unable to AddPrinter")<br />
                Return False<br />
            End If<br />
        End If<br />
<br />
        If hSource <> 0 Then<br />
            ClosePrinter(hSource)<br />
            hSource = IntPtr.Zero<br />
        End If<br />
<br />
        'dmOut = Nothing<br />
<br />
        Dim intRet As Int32<br />
        'get size of the DEVMODE structure<br />
        intRet = DocumentProperties(IntPtr.Zero, hDestination, strFullPrinterPath, IntPtr.Zero, IntPtr.Zero, DocumentPropertiesModes.DM_GETSIZE)<br />
        If intRet < 0 Then<br />
            Throw New Exception(Err.LastDllError & " unable to get DocumentProperties #1")<br />
            Return False<br />
        End If<br />
<br />
        'create a new instance of the DEVMODE structure with size returned<br />
        Dim hdmIn As IntPtr<br />
        hdmIn = Marshal.AllocHGlobal(intRet)<br />
<br />
        intRet = DocumentProperties(IntPtr.Zero, hDestination, strFullPrinterPath, hdmIn, IntPtr.Zero, DocumentPropertiesModes.DM_OUT_BUFFER)<br />
        If intRet < 0 Then<br />
            Throw New Exception(Err.LastDllError & " unable to get DocumentProperties #2")<br />
            Return False<br />
        End If<br />
<br />
        'get the structure from the pointer<br />
        Dim dmIn As New DEVMODE<br />
        dmIn = Marshal.PtrToStructure(hdmIn, dmIn.GetType)<br />
<br />
        'modify the structure with the settings from the source printer<br />
        With dmIn<br />
            .dmCollate = dmOut.dmCollate<br />
            .dmColor = dmOut.dmColor<br />
            .dmCopies = dmOut.dmCopies<br />
            .dmDefaultSource = dmOut.dmDefaultSource<br />
            .dmDuplex = dmOut.dmDuplex<br />
            .dmFormName = dmOut.dmFormName<br />
            .dmMediaType = dmOut.dmMediaType<br />
            .dmOrientation = dmOut.dmOrientation<br />
            .dmPaperLength = dmOut.dmPaperLength<br />
            .dmPaperSize = dmOut.dmPaperSize<br />
            .dmPaperWidth = dmOut.dmPaperWidth<br />
            .dmPrintQuality = dmOut.dmPrintQuality<br />
            .dmScale = dmOut.dmScale<br />
            .dmSize = dmOut.dmSize<br />
            .dmTTOption = dmOut.dmTTOption<br />
        End With<br />
<br />
        'copy the structure back in the pointer<br />
        Marshal.StructureToPtr(dmIn, hdmIn, False)<br />
<br />
        'set the new settings on the destination printer<br />
        intRet = DocumentProperties(IntPtr.Zero, hDestination, strFullPrinterPath, hdmIn, hdmIn, DocumentPropertiesModes.DM_IN_BUFFER Or DocumentPropertiesModes.DM_OUT_BUFFER)<br />
        If intRet < 0 Then<br />
            Throw New Exception(Err.LastDllError & " unable to set DocumentProperties #1")<br />
            Return False<br />
        End If<br />
<br />
        'reget the PRINTER_INFO_2 structure from the destination printer<br />
        Dim PI2In As New PRINTER_INFO_2<br />
        'Dim hPI2In As IntPtr<br />
        BytesWritten = 0<br />
        ptBuf = Marshal.AllocHGlobal(1)<br />
        If Not GetPrinter(hDestination, 2, ptBuf, 1, BytesWritten) Then<br />
            If BytesWritten > 0 Then<br />
                Marshal.FreeHGlobal(ptBuf)<br />
                ptBuf = Marshal.AllocHGlobal(BytesWritten)<br />
                'reget the PRINTER_INFO_2 structure<br />
                If GetPrinter(hDestination, 2, ptBuf, BytesWritten, BytesWritten) Then<br />
                    Marshal.PtrToStructure(ptBuf, PI2In)<br />
                    PI2In.lpDeviceMode = hdmIn<br />
                    'hPI2In = Marshal.AllocHGlobal(Marshal.SizeOf(PI2In))<br />
                    'Marshal.StructureToPtr(PI2In, hPI2In, False)<br />
                    intRet = SetPrinter(hDestination, 2, PI2In, PrinterControlCommands.PRINTER_CONTROL_SETPRINTERINFO)<br />
                    Debug.Print(Err.LastDllError)<br />
                    If intRet = 0 Then<br />
                        Throw New Exception(Err.LastDllError & " unable to SetPrinter #1")<br />
                        Return False<br />
                    End If<br />
                Else<br />
                    Marshal.FreeHGlobal(ptBuf)<br />
                    ClosePrinter(hDestination)<br />
                    Throw New Exception(Err.LastDllError & " unable to GetPrinter #3 " & strFullPrinterPath)<br />
                    Return False<br />
                End If<br />
            Else<br />
                Throw New Exception(Err.LastDllError & " BytesWritten #2 " & BytesWritten)<br />
                Return False<br />
            End If<br />
        End If<br />
        Call ClosePrinter(hDestination)<br />
        Marshal.FreeHGlobal(hdmIn)<br />
        Dim lvItem As New ListViewItem<br />
        lvItem = lvDestination.Items.Add(sPrinter)<br />
        lvItem.SubItems.Add(PI2In.pDriverName)<br />
        lvItem.SubItems.Add(PI2In.pShareName)<br />
        lvDestination.Refresh()<br />
        Me.Refresh()<br />
        pi2 = Nothing<br />
        PI2In = Nothing<br />
        dmIn = Nothing<br />
        dmOut = Nothing<br />
        Return True<br />
    End Function

Questioncrystal report Pin
gt221-Sep-07 3:10
gt221-Sep-07 3:10 
Questionhow to save all items in a listview Pin
gt221-Sep-07 2:39
gt221-Sep-07 2:39 
AnswerRe: how to save all items in a listview Pin
Justin Perez21-Sep-07 3:10
Justin Perez21-Sep-07 3:10 
QuestionHow to Retiveing Time now? Pin
somsakchoto21-Sep-07 2:26
somsakchoto21-Sep-07 2:26 
AnswerRe: How to Retiveing Time now? Pin
GuyThiebaut21-Sep-07 2:34
professionalGuyThiebaut21-Sep-07 2:34 
GeneralRe: How to Retiveing Time now? Pin
somsakchoto21-Sep-07 2:43
somsakchoto21-Sep-07 2:43 
GeneralRe: How to Retiveing Time now? Pin
GuyThiebaut21-Sep-07 2:52
professionalGuyThiebaut21-Sep-07 2:52 
GeneralRe: How to Retiveing Time now? Pin
somsakchoto21-Sep-07 3:03
somsakchoto21-Sep-07 3:03 
GeneralRe: How to Retiveing Time now? Pin
Colin Angus Mackay21-Sep-07 4:24
Colin Angus Mackay21-Sep-07 4:24 
QuestionPrint a Formm Pin
Trupti Mehta21-Sep-07 1:35
Trupti Mehta21-Sep-07 1:35 
AnswerRe: Print a Formm Pin
Duncan Edwards Jones21-Sep-07 3:15
professionalDuncan Edwards Jones21-Sep-07 3:15 
AnswerRe: Print a Formm Pin
JamesS[C1]21-Sep-07 3:42
JamesS[C1]21-Sep-07 3:42 
Question, Print a Formm Pin
Trupti Mehta21-Sep-07 1:32
Trupti Mehta21-Sep-07 1:32 
QuestionDecimal Digits - can't figure why? Pin
Trupti Mehta21-Sep-07 1:32
Trupti Mehta21-Sep-07 1:32 
AnswerRe: Decimal Digits - can't figure why? Pin
Dave Kreskowiak21-Sep-07 5:20
mveDave Kreskowiak21-Sep-07 5:20 
GeneralRe: Decimal Digits - can't figure why? Pin
Trupti Mehta21-Sep-07 19:48
Trupti Mehta21-Sep-07 19:48 
GeneralRe: Decimal Digits - can't figure why? Pin
Dave Kreskowiak22-Sep-07 3:08
mveDave Kreskowiak22-Sep-07 3:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.