Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printer Select Dialog Form - Part 1

What VB shoud be able to do!

Printer Select Dialog Form - Part 1

by  CassandraR  Posted    (Edited  )
Printer Select Dialog ActiveX DLL

Below are listed seven code modules.

The first four modules provide the source code for a Printer Select dialog form, in an ActiveX DLL class format. The last three modules provide a simple test platform to engage the Printer Select class.

For those who are interested in using the code, please download each block code and save according to the instructions. The various files should be saved in one directory.

Hopefully, for those who need to get around Microsoft's useless Common Dialog Box's ShowPrinter "features", this module provides the starting point for adding a Printer Select dialog form to your projects. With the complete source code available below, one can extract a lot more information than the ShowPrinter provides and can build in features that you deem desirable. (The software below does not alter Windows' default printer setting to the selected printer.)

The Test1.frm code shows how to interface to this class. It is rather simple:
1. Make a project reference to the class.
2. Declare a variable of the class type:
Code:
Private m_PrintSelect As clsPrintSelect
3. Instantiate a member of the class type:
Code:
Set m_PrintSelect = New clsPrintSelect
4. Call the PrinterSelect routine.
Code:
m_PrintSelect.PrinterSelect
5. After selecting the printer and clicking on Okay, the program should call the class to get a pointer to the printer:
Code:
Set ptrMyPrinter = m_PrintSelect.PrinterSelected

Additional features may be added as you wish, albeit that that is your responsibility.

Module 1: PrintSelect.vbp -- project file for the Printer Select class.
Module 2: printsel.frm -- the Printer Select dialog form.
Module 3: mdlPrinterAccess.bas -- the printer access routines.
Module 4: clsPrintSelect.cls -- the class interface.
Module 5: Test1.frm -- a simple form with one command button to call the Printer Select class.
Module 6: Test1.vbp -- project file for the test platform.
Module 7: PrintSelect.vbg -- the group file for the test platform.

The modules have been divided into seven parts to fit within Tek-Tips' constraints.
Part 1 contains PrintSelect.vbg, PrintSelect.vbp, Test1.vbp and Test1.frm.
Parts 2A (FAQ222-3604), 2B, (FAQ222-3614) and 2C (FAQ222-4285) contains the mdlPrinterAccess.bas.<BR>
Parts 3A (FAQ222-3605) and 3B (FAQ222-4286) contains PrintSel.frm.
Part 4 (FAQ222-4287) contains clsPrintSelect.cls.

My company, Professional Logics Corporation (PLC), has agreed to the release of this programming with the following conditions:
1. Copyright notices must remain in the source code. PLC reserves all rights to the use of this code, except as listed here.

2. The code may be used, as is or as modified by the user, for non-profit and commercial use, without the obligation of royalties.

3. Writing credit must be given to PLC if the code is used in a commercial product. Such credit to be comprised of mention of PLC's supply of the Printer Select dialog form source code. Such credit should be included in the About menu item and/or the help file.

4. PLC shall not indemnify anyone or any company that uses the code.

5. PLC does not warranty or guarantee the correctness of the code.

6. PLC does not provide any support for the source code provided or to any product that uses the source code.

Cassie

Save as PrintSelect.vbg
Code:
VBGROUP 5.0
StartupProject=Test1.vbp
Project=PrintSelect.vbp
End of PrintSelect.vbg


Save as PrintSelect.vbp
Code:
Type=OleDll
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#..\..\..\..\..\WINDOWS\SYSTEM\StdOle2.Tlb#OLE Automation
Class=clsPrintSelect; clsPrintSelect.cls
Form=printsel.frm
Module=mdlPrinterAccess; mdlPrinterAccess.bas
Startup="(None)"
HelpFile=""
Command32=""
Name="PrinterSelectPrj"
HelpContextID="0"
CompatibleMode="1"
MajorVer=1
MinorVer=0
RevisionVer=0
AutoIncrementVer=0
ServerSupportFiles=0
VersionCompanyName="Professional Logics Corp"
CompilationType=0
OptimizationType=0
FavorPentiumPro(tm)=0
CodeViewDebugInfo=0
NoAliasing=0
BoundsCheck=0
OverflowCheck=0
FlPointCheck=0
FDIVCheck=0
UnroundedFP=0
StartMode=1
Unattended=0
Retained=0
ThreadPerObject=0
MaxNumberOfThreads=1
End of PrintSelect.vbp


Save as Test1.vbp
Code:
Type=Exe
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#..\..\..\..\..\WINDOWS\SYSTEM\StdOle2.Tlb#OLE Automation
Reference=*\APrintSelect.vbp
Form=Test1.frm
Startup="frmTest1"
Command32=""
Name="Test1"
HelpContextID="0"
CompatibleMode="0"
MajorVer=1
MinorVer=0
RevisionVer=0
AutoIncrementVer=0
ServerSupportFiles=0
VersionCompanyName="Professional Logics Corp"
CompilationType=0
OptimizationType=0
FavorPentiumPro(tm)=0
CodeViewDebugInfo=0
NoAliasing=0
BoundsCheck=0
OverflowCheck=0
FlPointCheck=0
FDIVCheck=0
UnroundedFP=0
StartMode=0
Unattended=0
Retained=0
ThreadPerObject=0
MaxNumberOfThreads=1
End of Test1.vbp


Save as Test1.frm
Code:
VERSION 5.00
Begin VB.Form frmTest1 
   Caption         =   "Print Select Test"
   ClientHeight    =   1080
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   ScaleHeight     =   1080
   ScaleWidth      =   4680
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton cmdSelectPrinter 
      Caption         =   "Select &Printer"
      Height          =   495
      Left            =   1200
      TabIndex        =   0
      Top             =   240
      Width           =   1815
   End
End
Attribute VB_Name = "frmTest1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private m_PrintSelect As clsPrintSelect
Private m_SelectedPrinter As Printer
'

Private Sub cmdSelectPrinter_Click()
    m_PrintSelect.PrinterSelect
    Set m_SelectedPrinter = m_PrintSelect.PrinterSelected
    MsgBox m_SelectedPrinter.DeviceName
End Sub

Private Sub Form_Load()
    Set m_PrintSelect = New clsPrintSelect
End Sub
End of Test1.frm
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top