DOCUMENT:Q183163 30-MAR-1998 [vbwin] TITLE :BUG: Setting Orientation Changes Background Mix Mode for Printer PRODUCT :Microsoft Visual Basic for Windows PROD/VER:WINDOWS:4.0,5.0 OPER/SYS:WINDOWS KEYWORDS:VB4ALL VB4WIN vb5all vbwin ====================================================================== --------------------------------------------------------------------- The information in this article applies to: - 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. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available. 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 has 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 --------------------------- 1. Create a new Project in Visual Basic. Form1 is created by default. 2. Add a CommandButton to Form1. 3. 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 sets the background mix mode to Opaque 'Printer.Orientation = 1 ' Prints correctly without this line ' The next line will reset the background mix mode 'iBKMode = SetBkMode(Printer.hDC, TRANSPARENT) iBKMode = GetBkMode(Printer.hDC) Debug.Print "GetBkMode = " & iBKMode Debug.Print "Printer.FontTransparent = " & Printer.FontTransparent Printer.ForeColor = &H80000008 ' black Printer.Line (100, 100)-(2800, 500), , BF Printer.ForeColor = RGB(255, 255, 255) ' white Printer.CurrentX = 200 Printer.CurrentY = 200 Printer.Print "Testing....." Printer.EndDoc End Sub 4. Run the Project and Click on Command1. 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 5. Choose Stop from the Run Menu or click on the Stop button to end the program. 6. Uncomment the line that sets Orientation, run the Project and click on Command1. A page prints with a black rectangle in the upper-left containing a white rectangle instead of text. The Immediate Window displays the following: GetBkMode = 1 GetBkMode = 2 Printer.FontTransparent = True The next step demonstrates that the background mix mode is being changed by setting the Orientation property of the Printer object, even if it is set to the current value. 7. Uncomment the SetBkMode line, run the Project and click on Command1. The Page prints correctly again with a black rectangle containing white text in the upper-left. Additional query words: blank clear ====================================================================== Keywords : VB4ALL VB4WIN vb5all vbwin Version : WINDOWS:4.0,5.0 Platform : WINDOWS Issue type : kbbug Solution Type : kbpending ============================================================================= THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY. Copyright Microsoft Corporation 1998.