Board index » delphi » Painting without painting

Painting without painting

I need to do something a bit unorthodox here...

I have a component that presents text and other items in a smart
manner. One thing this component will do is tell you
exactly how much text is containt within its display area (in
pixels). Under normal conditions, the component uses
this feature display the vertical scroll bar if needed.

high level procedure:

Paint;
if (TextSize > WindowSize) then
        VertScrollBar.Visible := True;

Now here comes the fun part...I now want to
use this component in a manner similar to
hypertext help, in that it will pop up itself
in a stand alone window, and *resize the window*
based on how much text is there.

Right now, this requires two paints. the initial paint
which is needed to calculate exactly how much
text is in the control, then a second paint
after Setting the window bounds.

Naturally this causes a very ugly flash. Speed is not
that essential as its very quick. Being an amature Win
programmer, I figured I could paint the initial window
at a non-visible coordinate then move it in the set
bounds, but Paint messages do not seem to get processed
when the window is at an invalid window coordinate.

Anyone know how to fake out paint? I checked out
the TRANSPARENT property of a window in the WIN16 API
sections of the MSD CDROM, but the m{*word*203}of that story
is that this feature really does not work in the WIN 16 API...

TIA,

bvl

 

Re:Painting without painting


a...@lehigh.edu (Brian P. Van Lieu) wrote:

Quote
> Now here comes the fun part...I now want to
> use this component in a manner similar to
> hypertext help, in that it will pop up itself
> in a stand alone window, and *resize the window*
> based on how much text is there.

> Right now, this requires two paints. the initial paint
> which is needed to calculate exactly how much
> text is in the control, then a second paint
> after Setting the window bounds.

You don't need to paint the text to find out how many pixels it will take.
Use TCanvas.TextWidth to find the number of pixels required.  If you can't
use TextWidth for some reason like your string is longer than 255
characters, you can do it at the API level using DrawText with the
DT_CALCRECT flag (and whatever other flags you need like maybe
DT_SINGLELINE).  DrawText with the DT_CALCRECT doesn't actually paint, it
only calculates.

Quote
> Anyone know how to fake out paint? I checked out
> the TRANSPARENT property of a window in the WIN16 API
> sections of the MSD CDROM, but the m{*word*203}of that story
> is that this feature really does not work in the WIN 16 API...

TRANSPARENT works fine, just probably not as you want it to work.  It does
not make a window that has a background that is invisible, i.e. what is
under it always shows through.  Only what is under it initially is shown,
and if moved, that is not updated.  I've never come across a good use for
it, but that's how it is supposed to work.

Regards,
Brad
bstow...@pobox.com
Free Delphi Stuff:  http://www.pobox.com/~bstowers/delphi/

Re:Painting without painting


a...@lehigh.edu (Brian P. Van Lieu) wrote:

Quote
>Now here comes the fun part...I now want to
>use this component in a manner similar to
>hypertext help, in that it will pop up itself
>in a stand alone window, and *resize the window*
>based on how much text is there.

A couple of ideas:

Check out (TCanvas?).TextWidth.  I assume that there's a corresponding
TextHeight, but I've never looked.

Create an invisible TCanvas (not connected to any onscreen component)
and do your first write to that so you can get the sizing info.  After
sizing the visible window, this also leaves you the option of using
TCanvas.Draw (or TCanvas.CopyRect if you don't want the entire Canvas)
to copy the sizing Canvas to the visible one without having to
actually redraw the text.

Other Threads