Solved

FontTransparent on the Printer

Posted on 1997-04-08
3
334 Views
Last Modified: 2012-05-04
How do you make sure that the fonttransparent setting does what it's supposed to do.  I'm having problems printing to the printer device directly using code.  When I use the print method there is an area that surrounds my text that erases the background.  I have set
PRINTER.FONTTRANSPARENT = TRUE
but it does the same thing wether the setting is true or false.  I am using VB 4 and it happens with both the 16 and 32 bit versions.
0
Comment
Question by:bizon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 

Author Comment

by:bizon
ID: 1425175
Edited text of question
0
 

Author Comment

by:bizon
ID: 1425176
Edited text of question
0
 

Accepted Solution

by:
dixonpx earned 100 total points
ID: 1425177
PSS ID Number: Q145726
---------------------------------------------------------------------
The information in this article applies to:
 
- Standard, Professional, and Enterprise Editions of Microsoft Visual
  Basic, 16-bit and 32-bit, for Windows, version 4.0
---------------------------------------------------------------------
 
SYMPTOMS
========
 
When printing under Windows 95, the FontTransparent property of the Printer
object fails to change the way that the text is printed on the background.
The FontTransparent property determines whether background text and
graphics are displayed in the spaces around and within characters. The
Visual Basic default for this property is True, meaning that the background
will display in the spaces around the text. Under Windows 95, the text will
print as if FontTransparent is set to False, even though it is set to True.
 
Additionally, whenever a NewPage method is issued, all text on the new page
will print as if FontTransparent is set to False even if it was printing
correctly on the previous page.
 
CAUSE
=====
 
The background mix mode, which directly relates to the Visual Basic
FontTransparent property, and several other attributes of the printer
device context, are modified at the start of a page by Windows 95. This is
a change in behavior from Windows NT and previous versions of Windows that
is not addressed properly by the Visual Basic Printer Object. The problem
should only affect the 32-bit version of Visual Basic, although some cases
of the 16-bit version exhibiting this behavior have been reported. For more
information on the cause, please see the following article(s) in the
Microsoft Windows SDK Knowledge Base:
 
   ARTICLE-ID: Q125696
   TITLE     : StartPage/EndPage Resets Printer DC Attributes in Windows 95
 
RESOLUTION
==========
 
To work around the problem, call the SetBKMode Windows API function to set
the background mix mode. An example is shown in the More Information
section below.
 
STATUS
======
 
Microsoft has confirmed this to be a problem in the Microsoft products
listed at the beginning of this article. We are researching this problem
and will post new information here in the Microsoft Knowledge Base as it
becomes available.
 
MORE INFORMATION
================
 
The code to duplicate the problem is as follows:
 
1. Start Visual Basic. From the File menu, choose New Project (ALT, F, N).
   Form1 is created by default.
 
2. In the click event of the form, add the following code:
 
   Private Sub Form_Click()
 
      Printer.Line (0, 0)-(Printer.Width, Printer.Height), &HC0C0C0, BF
      Printer.CurrentX = 0
      Printer.CurrentY = 0
      Printer.FontTransparent = True
      Printer.Print "Printer.FontTransparent = " & Printer.FontTransparent
      Printer.FontTransparent = False
      Printer.Print "Printer.FontTransparent = " & Printer.FontTransparent
      Printer.EndDoc
 
   End Sub
 
4. From the Run menu, choose start (ALT, R, S), or press F5 to run the
   program.
 
5. Click the form. The result should be a gray page with one line of black
   text in the upper left corner and another line of black text in a white
   box beneath the first. On Windows 95, this will yield a gray page with
   a white box and black text for both lines.
 
The following steps correct the problem in the previous example:
 
1. Add the following declarations to the General section of the form:
 
   #If Win32 Then
 
      Private Declare Function SetBkMode Lib "gdi32"  _
      (ByVal hdc As Long, ByVal nBkMode As Long) As Long
 
      Private iBKMode as Long
 
   #Else
 
      Private Declare Function SetBkMode Lib "GDI" (ByVal hDC As Integer _
       , ByVal nBkMode As Integer) As Integer
 
      Private iBKMode as Integer
 
   #End If
 
      Private Const TRANSPARENT = 1
      Private Const OPAQUE = 2
 
2. Correct the code in the click event of the form as such:
 
   Private Sub Form_Click()
 
      Printer.Print ""
      Printer.Line (0, 0)-(Printer.Width, Printer.Height), &HC0C0C0, BF
      Printer.CurrentX = 0
      Printer.CurrentY = 0
      Printer.FontTransparent = True
      'Correctly sets the background mix mode to transparent
      iBKMode = SetBKMode(Printer.Hdc, TRANSPARENT)
      Printer.Print "Printer.FontTransparent = " & Printer.FontTransparent
      Printer.FontTransparent = False
      'Correctly sets the background mix mode to opaque
      iBKMode = SetBKMode(Printer.Hdc, OPAQUE)
      Printer.Print "Printer.FontTransparent = " & Printer.FontTransparent
      Printer.EndDoc
 
   End Sub
 
4. From the Run menu, choose start (ALT, R, S), or press F5 to run the
   program.
 
5. Click the form. The text should now print as expected.
 
Additional reference words: 4.00 vb416 vb432
KBCategory: kbprb
KBSubcategory: APrgPrint
=============================================================================
Copyright Microsoft Corporation 1996.



0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month11 days, 1 hour left to enroll

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question