We help IT Professionals succeed at work.

Use changes in Printer Setup when printing?

Sungar
Sungar asked
on
Medium Priority
315 Views
Last Modified: 2007-12-19
I am trying to add the ability to print from my app in VB6.  It seemed very simple, but I've run into a problem.

I let the user select the printer & settings to use, and then print; however, the settings get ignored and the app just uses the defaults...

Specifically, if I try and change the mode of my HP inkjet printer from Normal to Fast, or change the media type, these settings are ignored.

I am running Windows 2000.  I am also using Olympus ImageKnife for my images that I want to print.  Below is a code snippet:

---------------------------------
Declare Function PrintDlg Lib "comdlg32.dll" Alias "PrintDlgA" (pPrintdlg As PRINTDLGS) As Long

Type PRINTDLGS
        lStructSize As Long
        hwndOwner As Long
        hDevMode As Long
        hDevNames As Long
        hDC As Long
        flags As Long
        nFromPage As Integer
        nToPage As Integer
        nMinPage As Integer
        nMaxPage As Integer
        nCopies As Integer
        hInstance As Long
        lCustData As Long
        lpfnPrintHook As Long
        lpfnSetupHook As Long
        lpPrintTemplateName As String
        lpSetupTemplateName As String
        hPrintTemplate As Long
        hSetupTemplate As Long
End Type
Public PrintDialog As PRINTDLGS

----------------------------
Function PrinterSetup(ByVal hWnd As Long) As Long  
    PrintDialog.hwndOwner = hWnd
    PrintDialog.lStructSize = Len(PrintDialog)
    PrintDialog.flags = cdlPDPrintSetup Or cdlPDReturnDC Or cdlPDNoPageNums
    ShowPrinter = PrintDlg(PrintDialog)
End Function

-----------------------------
Sub PrintImage()
        Printer.Print
        PicbufViewer.PrintLeft = 0
        PicbufViewer.PrintTop = 0
        PicbufViewer.PrintWidth = ViewerImageWidth
        PicbufViewer.PrintHeight = ViewerImageHeight
        PicbufViewer.PrintContents Printer.hDC
        Printer.EndDoc
End Sub
Comment
Watch Question

Commented:
Common Dialog Does not realy do any thing with Printer

It is just a user inerface

before printing U get settings and set it programmatically

by setting properties of Printer object

Hope that helps

Author

Commented:
Ok, so how to I "extract" those settings from the Common Dialog and use them to "set" the printer object?

Every driver has it's own settings, and UI so it's not obvious to me how to apply the changes for each printer to the printer object.  I'm not really concerned with changing number of pages and stuff, but the driver details like quality & media type.
Ryan ChongSoftware Tead Lead / Business Analyst / System Analyst / Data Engineer
CERTIFIED EXPERT

Commented:
Hi Sungar,

Some useful resource on how to set the Default Printer:

http://www.freevbcode.com/ShowCode.Asp?ID=641 

http://www.mvps.org/vbnet/code/system/defprinternt.htm

regards.

Commented:
hey sungar i'm trying the same thing, i'm probably going the wrong way, but i placed all the printer devicenames in a listbox and want the user to print from there, does anybody know if this is possible

Commented:
hey sungar i'm trying the same thing, i'm probably going the wrong way, but i placed all the printer devicenames in a listbox and want the user to print from there, does anybody know if this is possible

Commented:
the first link helped me out! thanks

Author

Commented:
So, this above code helped to set the default printer, but it doesn't help me to change printer settings internal to the printer driver, like quality mode & media settings.

Some drivers are actually working and remembering the settings but others aren't.  Weird.  Anyway I've leared a lot from the above links, just haven't solved all the problems yet.

Thanks for the help.
CERTIFIED EXPERT
Author of the Year 2009

Commented:
Hi Sungar,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Refund points and save as a 0-pt PAQ.

Sungar, Please DO NOT accept this comment as an answer.
EXPERTS: Post a comment if you are certain that an expert deserves credit.  Explain why.
==========
DanRollins -- EE database cleanup volunteer
Per recommendation, points refunded and question closed.

Netminder
CS Moderator

Explore More ContentExplore courses, solutions, and other research materials related to this topic.