Microsoft KB Archive/198712

From BetaArchive Wiki

Article ID: 198712

Article Last Modified on 6/24/2004



APPLIES TO

  • Microsoft Visual Basic 4.0 Standard Edition
  • Microsoft Visual Basic 4.0 Professional Edition
  • Microsoft Visual Basic 5.0 Professional Edition
  • Microsoft Visual Basic 6.0 Professional Edition
  • Microsoft Visual Basic 4.0 Enterprise Edition
  • Microsoft Visual Basic 5.0 Enterprise Edition
  • Microsoft Visual Basic 6.0 Enterprise Edition
  • Microsoft Visual Basic 5.0 Learning Edition
  • Microsoft Visual Basic 6.0 Learning Edition



This article was previously published under Q198712

SYMPTOMS

When you use the Printer CommonDialog control from a Visual Basic application under Microsoft Windows 95 or Microsoft Windows 98, changes that are made may be shared with other applications. If you look at the properties of the printer that is being used, it may also reflect your selections. This can include, but is not limited to, attributes such as Copies, PaperSize, Default Source, Duplex, and Orientation.

CAUSE

The common dialog itself does not normally effect global default settings. However, the implementation in the Visual Basic common dialog control does. This is how changes made in the dialog are made known to the Printer object, which reads the new global default settings.

NOTE: With Microsoft Windows NT-based platforms, this is not a problem. Windows NT security features prevent the common dialog control from changing the printer's global default settings. This also means that the Printer object is not updated with the user's selections in the Common Dialog. The one change that can be made is the Default Printer because this is a user preference. To prevent this, you can set the PrinterDefault property to False before you call the ShowPrinter method. For additional information, see the article cross-reference in the "References" section of this article.

RESOLUTION

To work around this behavior, use one of the following methods to substitute another dialog box for the printer common dialog:

  • Use the Win32 API function PrintDlg or PageSetupDlg to open a printer dialog box. Changes that are made through this dialog box are stored in a DEVMODE structure. These settings can then be assigned directly to the Printer object's properties. The article in the "References" section of this article includes a sample DLL that uses the PrintDlg function for this purpose.
  • Create and use your own dialog box rather than the CommonDialog control. The changes that are made through this dialog box can then be assigned directly to the Printer object's properties.


STATUS

This behavior is by design.

MORE INFORMATION

As you work through the following steps, please note that when the Printer Common Dialog is first displayed from a Visual Basic application, it always defaults to Copies = 1, regardless of what the printer driver's current default setting may be.

Steps to Reproduce the Behavior

  1. Create a new Visual Basic Project. Form1 is created by default.
  2. On the Project menu, click Components, and then select the Microsoft Common Dialog Control check box. Click OK.
  3. Add a CommandButton control and a CommonDialog control to Form1.
  4. Paste the following code into the form's module:

          Private Sub Command1_Click()
          Debug.Print "Before: CommonDialog Copies = " & CommonDialog1.Copies _
             & ", "; "Printer Object Copies = " & Printer.Copies
          CommonDialog1.ShowPrinter
          Debug.Print "After:  CommonDialog Copies = " & CommonDialog1.Copies _
             & ", "; "Printer Object Copies = " & Printer.Copies
          End Sub
                        
  5. Check the Copies property of your default printer driver; set it to 1.
  6. Run the project, and then click Command1.
  7. In the Printer dialog box, change Copies to 4, and then click OK. Notice that the Immediate window contains the following output:

       Before: CommonDialog Copies = 1; Printer Object Copies = 1
       After:  CommonDialog Copies = 4; Printer Object Copies = 4
                        
  8. Close the project, and then check the Copies property of your default printer driver. Notice that the Copies property also contains the value 4.
  9. Open a text editor such as WordPad, and then click Print. The dialog box that opens also shows Copies = 4. If you change the number of copies in this dialog box, the change is remmebered, but the change does not affect the printer driver.


REFERENCES

For additional information, click the article number below to view the article in the Microsoft Knowledge Base:

173981 PRB: Behavior Differences of Print Dialog Box on Different Platforms


NOTE: This article includes an example of the first workaround.

MSDN Library CD

WIN32 Software Development Kit (SDK) Programmer's Guide, search on: "DEVMODE".


Additional query words: comdlg32

Keywords: kbcmndlgprint kbcmndlg kbprb KB198712