Re: Printing Colored Text (and a Concern about System GDI Resources)


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Re: Printing Colored Text (and a Concern about System GDI Resources)

  1. #1
    Tim Manos Guest

    Re: Printing Colored Text (and a Concern about System GDI Resources)

    Hi all,

    Here's a little more background:

    I'm trying to print red text on a yellow box on the Printer object and on a
    PictureBox (for print preview purposes). In some cases the text has to be
    printed in an angle, so I have to use calls to the Win API anyway. Printing
    angled text is taken care of.

    Here are the problems that I'm faced with:

    1. The app I'm writing will be installed on computers with different prints
    of which I cannot influence their breed and origin.
    The red text and yellow box I mentioned above prints as I want it on
    most printers but on some it prints the box and the text in the
    color I want BUT, a white rectangle that is as wide and as high as the text
    is printed around the text no matter what font I use. When I first saw that
    happening I thought that a newer driver would help. Well... it didn't. MS
    Word prints the above text and box as it should (MS Word uses API calls,
    doesn't it?), and because I'm using API calls anyway, why not for the whole
    printing which in my opinion will eliminate the white rectangle problem?

    2. I read that widows resources, like pens and brushes have to be used with
    great care because they are limited and run out quickly. They
    also have to be used almost exclusively as local variables. Here's a rough
    object model of the document I want to print: CDocument that is a
    collection of CLabel classes. The CLabel class is a collection of CItem
    classes. The CItem class contains all the information about its
    position on the CDocument, its font, color, etc. The CDocument has a
    PrintOn(hDC as long) method the calls the PrintOn(hDC as long) method on all
    CLabel classes that call the PrintOn(hDC as long) method on the CItem
    classes. The CItem uses only 8 colors. The qustion is: in this case can I
    have 8 LOGBRUSH objects on a .bas module that will be globally available and
    will be created when the PrintOn(hDC as long) method on the CDocument is
    called and used by the CItem objects and destroyed just before the PrintOn(h
    DC as long) on the CDocument method exits?

    3. I have noticed that when several apps written in VB run at the same time
    the system resources and GDI resources run out very rapidly and they go
    up when I shot the apps down. Someone told me that this is only a Win 95/98
    problem. So my conclusion is that VB uses GDI resources not very
    efficiently (do correct me if I'm wrong). And I don't use API calls in all
    apps I write. The above problem aggravates when I use the MSHFlexGrid OCX
    with many cells. What's your comment on that? And better still how
    do you deal with this? Are VC++ apps better at handling this?

    Thanks in advance for your responses


    Tim


    Here's a response I got from: Igor Roytberg [iroy55@hotmail.com]

    Tim,

    the question should probably be not about which Win API to cal but why in
    the world would you want to complicate "ta **** out" your program?! I can
    understand if object doesn't have Fore/BackColor properties, but in your
    case you must be working with labels or textboxes, isn't it? I hope you've
    got the point.
    Another story would be if you need to change Fore/BackColor at run time to
    the object that doesn't have any of these properties and sets some default
    colors which you may not like. Please give us some more details on what
    exactly you are trying to accomplish.
    Regards,
    Roy


    Tim Manos <timmanos@t-online.de> wrote in message
    news:3b5c9515$1@news.devx.com...
    > Dear API gurus,
    >
    > How do I set the fore and back color of a device context to print text

    that
    > is, say, red? And more precisely, how do I draw a yellow box with and

    print
    > red text on it? All that using API calls. An example would be very much
    > appreciable.
    >
    > Thanks in advance,
    >
    > Tim
    >
    >






  2. #2
    Tim Manos Guest

    Re: Printing Colored Text (and a Concern about System GDI Resources)

    Hi all,

    Here's a little more background:

    I'm trying to print red text on a yellow box on the Printer object and on a
    PictureBox (for print preview purposes). In some cases the text has to be
    printed in an angle, so I have to use calls to the Win API anyway. Printing
    angled text is taken care of.

    Here are the problems that I'm faced with:

    1. The app I'm writing will be installed on computers with different prints
    of which I cannot influence their breed and origin.
    The red text and yellow box I mentioned above prints as I want it on
    most printers but on some it prints the box and the text in the
    color I want BUT, a white rectangle that is as wide and as high as the text
    is printed around the text no matter what font I use. When I first saw that
    happening I thought that a newer driver would help. Well... it didn't. MS
    Word prints the above text and box as it should (MS Word uses API calls,
    doesn't it?), and because I'm using API calls anyway, why not for the whole
    printing which in my opinion will eliminate the white rectangle problem?

    2. I read that widows resources, like pens and brushes have to be used with
    great care because they are limited and run out quickly. They
    also have to be used almost exclusively as local variables. Here's a rough
    object model of the document I want to print: CDocument that is a
    collection of CLabel classes. The CLabel class is a collection of CItem
    classes. The CItem class contains all the information about its
    position on the CDocument, its font, color, etc. The CDocument has a
    PrintOn(hDC as long) method the calls the PrintOn(hDC as long) method on all
    CLabel classes that call the PrintOn(hDC as long) method on the CItem
    classes. The CItem uses only 8 colors. The qustion is: in this case can I
    have 8 LOGBRUSH objects on a .bas module that will be globally available and
    will be created when the PrintOn(hDC as long) method on the CDocument is
    called and used by the CItem objects and destroyed just before the PrintOn(h
    DC as long) on the CDocument method exits?

    3. I have noticed that when several apps written in VB run at the same time
    the system resources and GDI resources run out very rapidly and they go
    up when I shot the apps down. Someone told me that this is only a Win 95/98
    problem. So my conclusion is that VB uses GDI resources not very
    efficiently (do correct me if I'm wrong). And I don't use API calls in all
    apps I write. The above problem aggravates when I use the MSHFlexGrid OCX
    with many cells. What's your comment on that? And better still how
    do you deal with this? Are VC++ apps better at handling this?

    Thanks in advance for your responses


    Tim


    Here's a response I got from: Igor Roytberg [iroy55@hotmail.com]

    Tim,

    the question should probably be not about which Win API to cal but why in
    the world would you want to complicate "ta **** out" your program?! I can
    understand if object doesn't have Fore/BackColor properties, but in your
    case you must be working with labels or textboxes, isn't it? I hope you've
    got the point.
    Another story would be if you need to change Fore/BackColor at run time to
    the object that doesn't have any of these properties and sets some default
    colors which you may not like. Please give us some more details on what
    exactly you are trying to accomplish.
    Regards,
    Roy


    Tim Manos <timmanos@t-online.de> wrote in message
    news:3b5c9515$1@news.devx.com...
    > Dear API gurus,
    >
    > How do I set the fore and back color of a device context to print text

    that
    > is, say, red? And more precisely, how do I draw a yellow box with and

    print
    > red text on it? All that using API calls. An example would be very much
    > appreciable.
    >
    > Thanks in advance,
    >
    > Tim
    >
    >






  3. #3
    KevinC Guest

    Re: Printing Colored Text (and a Concern about System GDI Resources)


    I am not qualified to answer your system resource questions but I have in
    the past ran into the same printing problem with colored text and colored
    backgrounds. I found a tip on vb2themax (i believe) that said to use the
    API function SetBkMode to flip the bit that tells the foreground printing
    to use transparency because it is inadvertantly turned on with certain printing
    commands. It has worked like a charm.

    declare function SetBkMode Lib "gdi32" (ByVal hdc as long, _
    ByVal nBkMode as Integer) as integer
    const TRANSPARENT = 1

    then in code:
    SetBkMode locObj.hdc, TRANSPARENT

    "Tim Manos" <timmanos@t-online.de> wrote:
    >Hi all,
    >
    >Here's a little more background:
    >
    >I'm trying to print red text on a yellow box on the Printer object and on

    a
    >PictureBox (for print preview purposes). In some cases the text has to be
    >printed in an angle, so I have to use calls to the Win API anyway. Printing
    >angled text is taken care of.
    >
    >Here are the problems that I'm faced with:
    >
    >1. The app I'm writing will be installed on computers with different prints
    >of which I cannot influence their breed and origin.
    > The red text and yellow box I mentioned above prints as I want it on
    >most printers but on some it prints the box and the text in the
    >color I want BUT, a white rectangle that is as wide and as high as the text
    >is printed around the text no matter what font I use. When I first saw that
    >happening I thought that a newer driver would help. Well... it didn't. MS
    >Word prints the above text and box as it should (MS Word uses API calls,
    >doesn't it?), and because I'm using API calls anyway, why not for the whole
    >printing which in my opinion will eliminate the white rectangle problem?
    >
    >2. I read that widows resources, like pens and brushes have to be used with
    >great care because they are limited and run out quickly. They
    >also have to be used almost exclusively as local variables. Here's a rough
    >object model of the document I want to print: CDocument that is a
    >collection of CLabel classes. The CLabel class is a collection of CItem
    >classes. The CItem class contains all the information about its
    >position on the CDocument, its font, color, etc. The CDocument has a
    >PrintOn(hDC as long) method the calls the PrintOn(hDC as long) method on

    all
    >CLabel classes that call the PrintOn(hDC as long) method on the CItem
    >classes. The CItem uses only 8 colors. The qustion is: in this case can

    I
    >have 8 LOGBRUSH objects on a .bas module that will be globally available

    and
    >will be created when the PrintOn(hDC as long) method on the CDocument is
    >called and used by the CItem objects and destroyed just before the PrintOn(h
    >DC as long) on the CDocument method exits?
    >
    >3. I have noticed that when several apps written in VB run at the same time
    >the system resources and GDI resources run out very rapidly and they

    go
    >up when I shot the apps down. Someone told me that this is only a Win 95/98
    >problem. So my conclusion is that VB uses GDI resources not very
    >efficiently (do correct me if I'm wrong). And I don't use API calls in all
    >apps I write. The above problem aggravates when I use the MSHFlexGrid OCX
    >with many cells. What's your comment on that? And better still how
    >do you deal with this? Are VC++ apps better at handling this?
    >
    >Thanks in advance for your responses
    >
    >
    >Tim
    >
    >
    >Here's a response I got from: Igor Roytberg [iroy55@hotmail.com]
    >
    > Tim,
    >
    >the question should probably be not about which Win API to cal but why in
    >the world would you want to complicate "ta **** out" your program?! I can
    >understand if object doesn't have Fore/BackColor properties, but in your
    >case you must be working with labels or textboxes, isn't it? I hope you've
    >got the point.
    >Another story would be if you need to change Fore/BackColor at run time

    to
    >the object that doesn't have any of these properties and sets some default
    >colors which you may not like. Please give us some more details on what
    >exactly you are trying to accomplish.
    >Regards,
    >Roy
    >
    >
    >Tim Manos <timmanos@t-online.de> wrote in message
    >news:3b5c9515$1@news.devx.com...
    >> Dear API gurus,
    >>
    >> How do I set the fore and back color of a device context to print text

    >that
    >> is, say, red? And more precisely, how do I draw a yellow box with and

    >print
    >> red text on it? All that using API calls. An example would be very much
    >> appreciable.
    >>
    >> Thanks in advance,
    >>
    >> Tim
    >>
    >>

    >
    >
    >
    >



  4. #4
    KevinC Guest

    Re: Printing Colored Text (and a Concern about System GDI Resources)


    I am not qualified to answer your system resource questions but I have in
    the past ran into the same printing problem with colored text and colored
    backgrounds. I found a tip on vb2themax (i believe) that said to use the
    API function SetBkMode to flip the bit that tells the foreground printing
    to use transparency because it is inadvertantly turned on with certain printing
    commands. It has worked like a charm.

    declare function SetBkMode Lib "gdi32" (ByVal hdc as long, _
    ByVal nBkMode as Integer) as integer
    const TRANSPARENT = 1

    then in code:
    SetBkMode locObj.hdc, TRANSPARENT

    "Tim Manos" <timmanos@t-online.de> wrote:
    >Hi all,
    >
    >Here's a little more background:
    >
    >I'm trying to print red text on a yellow box on the Printer object and on

    a
    >PictureBox (for print preview purposes). In some cases the text has to be
    >printed in an angle, so I have to use calls to the Win API anyway. Printing
    >angled text is taken care of.
    >
    >Here are the problems that I'm faced with:
    >
    >1. The app I'm writing will be installed on computers with different prints
    >of which I cannot influence their breed and origin.
    > The red text and yellow box I mentioned above prints as I want it on
    >most printers but on some it prints the box and the text in the
    >color I want BUT, a white rectangle that is as wide and as high as the text
    >is printed around the text no matter what font I use. When I first saw that
    >happening I thought that a newer driver would help. Well... it didn't. MS
    >Word prints the above text and box as it should (MS Word uses API calls,
    >doesn't it?), and because I'm using API calls anyway, why not for the whole
    >printing which in my opinion will eliminate the white rectangle problem?
    >
    >2. I read that widows resources, like pens and brushes have to be used with
    >great care because they are limited and run out quickly. They
    >also have to be used almost exclusively as local variables. Here's a rough
    >object model of the document I want to print: CDocument that is a
    >collection of CLabel classes. The CLabel class is a collection of CItem
    >classes. The CItem class contains all the information about its
    >position on the CDocument, its font, color, etc. The CDocument has a
    >PrintOn(hDC as long) method the calls the PrintOn(hDC as long) method on

    all
    >CLabel classes that call the PrintOn(hDC as long) method on the CItem
    >classes. The CItem uses only 8 colors. The qustion is: in this case can

    I
    >have 8 LOGBRUSH objects on a .bas module that will be globally available

    and
    >will be created when the PrintOn(hDC as long) method on the CDocument is
    >called and used by the CItem objects and destroyed just before the PrintOn(h
    >DC as long) on the CDocument method exits?
    >
    >3. I have noticed that when several apps written in VB run at the same time
    >the system resources and GDI resources run out very rapidly and they

    go
    >up when I shot the apps down. Someone told me that this is only a Win 95/98
    >problem. So my conclusion is that VB uses GDI resources not very
    >efficiently (do correct me if I'm wrong). And I don't use API calls in all
    >apps I write. The above problem aggravates when I use the MSHFlexGrid OCX
    >with many cells. What's your comment on that? And better still how
    >do you deal with this? Are VC++ apps better at handling this?
    >
    >Thanks in advance for your responses
    >
    >
    >Tim
    >
    >
    >Here's a response I got from: Igor Roytberg [iroy55@hotmail.com]
    >
    > Tim,
    >
    >the question should probably be not about which Win API to cal but why in
    >the world would you want to complicate "ta **** out" your program?! I can
    >understand if object doesn't have Fore/BackColor properties, but in your
    >case you must be working with labels or textboxes, isn't it? I hope you've
    >got the point.
    >Another story would be if you need to change Fore/BackColor at run time

    to
    >the object that doesn't have any of these properties and sets some default
    >colors which you may not like. Please give us some more details on what
    >exactly you are trying to accomplish.
    >Regards,
    >Roy
    >
    >
    >Tim Manos <timmanos@t-online.de> wrote in message
    >news:3b5c9515$1@news.devx.com...
    >> Dear API gurus,
    >>
    >> How do I set the fore and back color of a device context to print text

    >that
    >> is, say, red? And more precisely, how do I draw a yellow box with and

    >print
    >> red text on it? All that using API calls. An example would be very much
    >> appreciable.
    >>
    >> Thanks in advance,
    >>
    >> Tim
    >>
    >>

    >
    >
    >
    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center