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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Color Printing via Printer Object 1

Status
Not open for further replies.

Sware

Programmer
Apr 19, 2005
124
US
I've discovered the Microsoft KB article (84269) that says that the ForeColor property of the Printer object "was not fully implemented" (and still isn't) and that the Windows API function call SetTextColor() must be used. I've used the following code in a new project as instructed by the article.

In Global Module (on one line):
Declare Function SetTextColor Lib "GDI" _
(ByVal hDC as Integer, ByVal crColor as Long) as Long

In Form1 Form_Click Event:
Sub Form_Click
For i = 0 to 15
x& = SetTextColor(Printer.hDC, QBColor(i))
Printer.Print "Hello"
Next i
Printer.EndDoc
End Sub

When I run the program and click the form I'm supposed to get the word "Hello" printed in 16 different colors. What I get is a Code 6 - Overflow error.

What's wrong? Also, are there any tools, techniques, etc. for printing in color via the Printer object? (I know I can use PrintForm but the material I'm printing exceeds the maximum vertical size of a QB form.

Thanks.
 
The problem is in your API function declaration. The hDC parameter should be a Long, not an Integer:

Private Declare Function SetTextColor Lib "GDI32" _
(ByVal hDC As [red]Long[/red], ByVal crColor As Long) As Long

Printer.hDC returns a Long, and the overflow comes when you try to pass a Long to an Integer parameter.

Also, when I tried to run the code with te function declaration using Lib "GDI" it failed...couldn't find the library. I had to switch it to GDI32.


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
>I've discovered the Microsoft KB article (84269)

Which refers to VB 1, 2 and 3 ...
 
Thanks JEBENSON - I've given you a star for an excellent response. Speaking of response and responsiveness, KB84269 was last updated in 2003. It contains "GDI" versus "GDI32" and "hDC as Integer" versus "hDC as Long". So much for Microsoft's responsiveness!
 
If you read it carefully, it says Vb 1,2,3. Not 5 or 6 so is quite accurate.
 
I owe Microsoft an apology of sorts. As noted in other posts, the KB article does not reference beyond VB 3.0 and the information is apparently correct for the referenced versions. More importantly, I've confirmed that the "bug" with the ForeColor property of the Printer object HAS BEEN FIXED in VB 6.0 (and perhaps in 4.0 and 5.0).

I got into this situation by searching on "Color Printing" within Visual Basic on the Microsoft website. KB84269 was the only result applicable to the Printer object. I erroneously jumped to the conclusion that the bug also existed in subsequent VB versions (i.e. initially I didn't think to try the ForeColor property with VB 6.0).

Given the search route that I took and others may take, I would suggest that Microsoft update KB84269 to include a statement that the ForeColor property is fully implemented in versions X.0 through 6.0.
 
<The problem is in your API function declaration. The hDC parameter should be a Long, not an Integer

Using the API Text Viewer that ships with VB6 (not to mention a number of other easily downloadable apps that do more) will easily avoid errors of this type.

HTH

Bob
 
Er, they are pretty specific about the versions the article covers. I don't think that they need to add anything else
 
BTW, there's another KB article (255115) that explains a bug with the Printer.ForeColor property in VB 6.0 and provides a workaround. The artivle was last updated in May 2003 and references only Windows 9X, Me, NT and 2000. I've confirmed that the bu still exists under XP Home and that the NT/2000 workaround resolves the situation under XP Home (and I assume XP Pro).
 
>and references only Windows 9X, Me, NT and 2000

The article states that it applies to all versions of VB6; the OS is irrelevant
 
With respect to KB article 255115, the Operating System IS RELEVANT because the Printer Object calls underlying Windows API functions. As described in the article, the nature of both the bug and the workaround is different for 9X/Me and NT/2000 systems. Therefore, updating the article to include XP is desirable.
 
Sadly I disagree with you. I no longer have the will to explain why
 
I'll try to explain why I (sadly) disagree with you:

1) The KB 255115 bug exists with VB 6.0 on a XP Home system (and presumably on a XP Pro system).

2) The NT/2000 workaround works with XP Home (and likely XP Pro).

Therefore, why not include a reference to XP in the article?

(I realize that XP is based on NT/2000, but it is a separate OS and users may not be aware of the NT/2000 basis.)
 
KB articles don't exist in isolation (if they did they'd often have to be much, much, much longer than they are now), and can be cross-referenced. In this case MS make it clear that the VB bug (and it is a VB bug, not an OS bug) is caused by the lazy way it deals with the StartPage API. Want to know if the API call works the same way on XP as on NT/2000(and thus resulting in VB needing the NT workaround)? Just look the API call up on MSDN.

But let's just agree to disagree
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top