BUG: Setting Orientation Changes Background Mix Mode for Printer
ID: Q183163
|
The information in this article applies to:
-
Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, version 6.0
-
Microsoft Visual Basic Control Creation, Learning, Professional, and Enterprise Editions for Windows, version 5.0
-
Microsoft Visual Basic Standard, Professional, and Enterprise Editions, 16-bit and 32-bit, for Windows, version 4.0
SYMPTOMS
When printing, a white rectangle appears inside of a printed box instead of
the expected text, or text appears with a white background when printed
onto a shaded box.
CAUSE
When you set Printer.Orientation, or use the Line method, the background
mix mode for the Printer.hDC is set to Opaque.
RESOLUTION
Use the SetBkMode API to set the background mix mode back to Transparent.
STATUS
Microsoft has confirmed this to be a bug in the Microsoft products
listed at the beginning of this article.
MORE INFORMATION
The background mix mode of a device context (DC) affects text, hatched
brushes, and pen styles that are not solid lines. The effect can be that
the background changes so that text is not visible. The API function
GetBkMode returns the current setting for the background mix mode for a
specified DC and SetBkMode sets it. The mode can be Opaque or Transparent
and has the following effects:
Value Description
----------- -----------------------------
OPAQUE Background is filled with the current background color
before the text, hatched brush, or pen is drawn.
TRANSPARENT Background remains untouched.
The background mix mode should be determined by the FontTransparent Property of the Printer object, which defaults to True, meaning that the mode should be Transparent. When you set Printer.Orientation, or use the Line method, it can have the undesired effect of also setting the background mix mode to Opaque, while leaving FontTransparent still set to True. The solution to this is to use the SetBkMode API function to set it back to Transparent. The following sample demonstrates the problem and a solution.
Steps to Reproduce Behavior
- Create a new Project in Visual Basic. Form1 is created by default.
- Add a CommandButton to Form1.
- Paste the following code into the Form's module:
Private Declare Function SetBkMode Lib "gdi32" _
(ByVal hDC As Long, ByVal nBkMode As Integer) As Integer
Private Declare Function GetBkMode Lib "gdi32" _
(ByVal hDC As Long) As Integer
'For VB4 16-bit, replace the 2 lines above with the following 2 lines
'Private Declare Function SetBkMode Lib "GDI" _
(ByVal hDC As Integer, ByVal nBkMode As Integer) As Integer
'Private Declare Function GetBkMode Lib "GDI" _
(ByVal hDC As Integer) As Integer
Private Const TRANSPARENT = 1
Private Const OPAQUE = 2
Private iBKMode As Integer
Private Sub Command1_Click()
iBKMode = GetBkMode(Printer.hDC)
Debug.Print "GetBkMode = " & iBKMode
' The next line may set the background mix mode to Opaque
'Printer.Orientation = 1 ' May print correctly without this line
iBKMode = GetBkMode(Printer.hDC)
Debug.Print "GetBkMode = " & iBKMode
Debug.Print "Printer.FontTransparent = " & Printer.FontTransparent
Printer.ForeColor = &H80000008 ' black
' The Line method can also cause this problem:
Printer.Line (100, 100)-(2800, 500), , BF
iBKMode = GetBkMode(Printer.hDC)
Debug.Print "GetBkMode = " & iBKMode
Printer.ForeColor = RGB(255, 255, 255) ' white
Printer.CurrentX = 200
Printer.CurrentY = 200
' The next line will reset the background mix mode
'iBKMode = SetBkMode(Printer.hDC, TRANSPARENT)
Printer.Print "Testing....."
Printer.EndDoc
End Sub
- Run the Project and click on Command1. Either a Page prints correctly with a black rectangle containing white text in the upper-left, and the Immediate Window displays the following:
GetBkMode = 1
GetBkMode = 1
Printer.FontTransparent = True
GetBkMode = 1
or a page prints with a black rectangle in the upper-left containing a
white rectangle instead of text and the Immediate Window displays the
following:
GetBkMode = 1
GetBkMode = 1
Printer.FontTransparent = True
GetBkMode = 2
In the latter case, it is the Line method that caused the problem.
- Choose Stop from the Run menu or click on the Stop button to end the program.
- Uncomment the line that sets Orientation, run the Project and click on Command1. If a page prints with a black rectangle in the upper-left containing a white rectangle instead of text, it indicates that setting the Orientation property changed the background mix mode and the Immediate Window displays the following:
GetBkMode = 1
GetBkMode = 2
Printer.FontTransparent = True
GetBkMode = 2
- Uncomment the SetBkMode line, run the Project and click on Command1. ThePage prints correctly again with a black rectangle containing white text in the upper-left.
Additional query words:
blank clear
Keywords : kbPrinting kbVBp kbVBp400bug kbVBp500bug kbVBp600bug kbDSupport
Version : WINDOWS:4.0,5.0,6.0
Platform : WINDOWS
Issue type : kbbug
|