• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 219
  • Last Modified:

Program for color printing VB sources

I am looking for a program with which you can print vb sources on a color printer with all the reserved words in their color, with the comments in green and so on.

thanks
0
tsjarlie
Asked:
tsjarlie
  • 3
  • 2
1 Solution
 
watyCommented:
Put all your code in the RTF file and
Use this code to print a RTF file (with colors)

' #VBIDEUtils#************************************************************
' * Programmer Name  : Waty Thierry
' * Web Site         : www.geocities.com/ResearchTriangle/6311/
' * E-Mail           : waty.thierry@usa.net
' * Date             : 30/07/99
' * Time             : 14:07
' **********************************************************************
' * Comments         : Print RTF
' *
' *
' **********************************************************************

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal msg As Long, ByVal wp As Long, lp As Any) As Long

Public Const WM_USER = &H400
Public Const EM_FORMATRANGE As Long = WM_USER + 57

Public Sub PrintRTF(rtf As RichTextBox, nnLeftMarginWidth As Long, nnTopMarginHeight As Long, nnRightMarginWidth As Long, nnBottomMarginHeight As Long)
   ' #VBIDEUtils#************************************************************
   ' * Programmer Name  : Waty Thierry
   ' * Web Site         : www.geocities.com/ResearchTriangle/6311/
   ' * E-Mail           : waty.thierry@usa.net
   ' * Date             : 30/10/98
   ' * Time             : 14:43
   ' * Module Name      : Main_Module
   ' * Module Filename  : Main.bas
   ' * Procedure Name   : PrintRTF
   ' * Parameters       :
   ' *                    rtf As RichTextBox
   ' *                    nnLeftMarginWidth As Long
   ' *                    nnTopMarginHeight As Long
   ' *                    nnRightMarginWidth As Long
   ' *                    nnBottomMarginHeight As Long
   ' **********************************************************************
   ' * Comments         : Print RTF
   ' *
   ' *
   ' **********************************************************************
   
   Dim nLeftOffset      As Long
   Dim nTopOffset       As Long
   Dim nLeftMargin      As Long
   Dim nTopMargin       As Long
   Dim nRightMargin     As Long
   Dim nBottomMargin    As Long
   Dim fr               As FormatRange
   Dim rcDrawTo         As RECT
   Dim rcPage           As RECT
   Dim nTextLength      As Long
   Dim nNextCharPos     As Long
   Dim nRet             As Long
   
   Printer.Print Space(1)
   Printer.ScaleMode = vbTwips
   nLeftOffset = Printer.ScaleX(GetDeviceCaps(Printer.hdc, PHYSICALOFFSETX), vbPixels, vbTwips)
   nTopOffset = Printer.ScaleY(GetDeviceCaps(Printer.hdc, PHYSICALOFFSETY), vbPixels, vbTwips)
   nLeftMargin = nnLeftMarginWidth - nLeftOffset
   nTopMargin = nnTopMarginHeight - nTopOffset
   nRightMargin = (Printer.Width - nnRightMarginWidth) - nLeftOffset
   nBottomMargin = (Printer.Height - nnBottomMarginHeight) - nTopOffset
   rcPage.left = 0
   rcPage.tOp = 0
   rcPage.Right = Printer.ScaleWidth
   rcPage.Bottom = Printer.ScaleHeight
   rcDrawTo.left = nLeftMargin
   rcDrawTo.tOp = nTopMargin
   rcDrawTo.Right = nRightMargin
   rcDrawTo.Bottom = nBottomMargin
   fr.hdc = Printer.hdc
   fr.hdcTarget = Printer.hdc
   fr.rc = rcDrawTo
   fr.rcPage = rcPage
   fr.chrg.cpMin = 0
   fr.chrg.cpMax = -1
   nTextLength = Len(rtf.Text)
   Do
      fr.hdc = Printer.hdc
      fr.hdcTarget = Printer.hdc
      nNextCharPos = SendMessage(rtf.hwnd, EM_FORMATRANGE, True, fr)
      If nNextCharPos >= nTextLength Then Exit Do
      fr.chrg.cpMin = nNextCharPos
      Printer.NewPage
      Printer.Print Space(1)
   Loop
   Printer.EndDoc
   nRet = SendMessage(rtf.hwnd, EM_FORMATRANGE, False, ByVal CLng(0))

End Sub

0
 
tsjarlieAuthor Commented:
Thank you for the fast answer,
the problem is that I am rather new to vb and don't exactly understand your solution, could you explain some more ?
I saved the vb source in word in a rtf format, the I made a new project in vb6
and cut and paste your source in a form but when I ran the program I got an error on the constant declaration.
What am I doing wrong ? Everything ?

tsjarlie
0
 
watyCommented:
Could you tell me on wich line?
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
tsjarlieAuthor Commented:
the line is :

Public Const WM_USER = &H400

the error is :

Compile error:

Constants, fixed-lenght strings, arrays, user-defined types and Declare statements not allowed as Public members of object modules
0
 
KDivadCommented:
Remove the "Public" word from the line or move the code to a .bas module.
0
 
watyCommented:
yeps
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now