Board index » cppbuilder » Rendering controls to canvas

Rendering controls to canvas


2005-07-20 11:14:28 PM
cppbuilder25
Hi all, I want to paint controls on the form's canvas, i.e. I
create the controls, but don't place them on the form. I just
paint the canvas, as if there were controls on it.
Here is the problem: I use a second hidden form to place my
controls on, but as the form is invisible, the controls remain
invisible too. When I tried to copy their canvas to the form's
canvas with BitBlt, the form remained empty. Just for testing I
made that other form visible and yes: the controls where painted
to my first form, too.
My question: As the controls don't think it necessary to paint
themselves to a hidden form's canvas, can I create another
virtual Canvas that the controls think paintworthy?
 
 

Re:Rendering controls to canvas

Thorsten Kettner wrote:
Quote
Hi all, I want to paint controls on the form's canvas, i.e. I
create the controls, but don't place them on the form. I just
paint the canvas, as if there were controls on it.

Here is the problem: I use a second hidden form to place my
controls on, but as the form is invisible, the controls remain
invisible too. When I tried to copy their canvas to the form's
canvas with BitBlt, the form remained empty. Just for testing I
made that other form visible and yes: the controls where painted
to my first form, too.

My question: As the controls don't think it necessary to paint
themselves to a hidden form's canvas, can I create another
virtual Canvas that the controls think paintworthy?
Thorsten,
Instead of using the second form, let the form owns the controls. When
the Form needs to be Repainted, it will call all the Child Controls
Paint function. In the controls paint function decide to draw or not by
the Controls Visible property.
Sabetay
 

Re:Rendering controls to canvas

"Thorsten Kettner" < XXXX@XXXXX.COM >wrote in message
Quote
Hi all, I want to paint controls on the form's canvas, i.e. I
create the controls, but don't place them on the form. I just
paint the canvas, as if there were controls on it.
Why can't you just place the controls on the form and let them paint
themselves normally? You are not gaining anything by trying to copy images
from a secondary form. You are only making your code design overly more
complex then it needs to be.
Gambit
 

{smallsort}

Re:Rendering controls to canvas

"Remy Lebeau \(TeamB\)" < XXXX@XXXXX.COM >wrote:
Quote

"Thorsten Kettner" < XXXX@XXXXX.COM >wrote in message
news:42de6a54$ XXXX@XXXXX.COM ...

>Hi all, I want to paint controls on the form's canvas, i.e. I
>create the controls, but don't place them on the form. I just
>paint the canvas, as if there were controls on it.

Why can't you just place the controls on the form and let them
paint themselves normally? You are not gaining anything by
trying to copy images from a secondary form. You are only
making your code design overly more complex then it needs to
be.
However, I would like to know if it is possible or not. I tried
PaintTo, but nothing happened. I tried WM_PRINT, but it didn't
work either. Can you, Remy, or anybody else tell me what's
wrong with this code? Why doesn't the Button1 render to my
form's canvas?
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Button1->Visible = false;
::SendMessage(Button1->Handle, WM_PRINT, (WPARAM)Canvas->Handle, (LPARAM)PRF_CLIENT|PRF_NONCLIENT);
}
Button1 gets invisible, then I send it the message to render
itself to my form's dc, but the form remains empty. I noticed
that the form's OnPaint gets called when I make the button
invisible, but it doesn't get called after WM_PRINT, which it
should. Am I wrong?
 

Re:Rendering controls to canvas

Sabetay Toros < XXXX@XXXXX.COM >wrote:
Quote
Instead of using the second form, let the form owns the
controls. When the Form needs to be Repainted, it will call
all the Child Controls Paint function. In the controls paint
function decide to draw or not by the Controls Visible
property.
Hm, I guess you mean "let the form be Parent of the controls",
right? Then I would make my controls invisible, and in their
paint method I would deceide to draw them though? Is that what
you say? Well, as far as I see the controls' Paint method does
not get called when they are invisible. I tried Repaint(), but
Paint() was not called. Am I missing something?
 

Re:Rendering controls to canvas

"Thorsten Kettner" < XXXX@XXXXX.COM >wrote in message
Quote
However, I would like to know if it is possible or not. I tried
PaintTo, but nothing happened. I tried WM_PRINT, but it
didn't work either. Can you, Remy, or anybody else tell me
what's wrong with this code? Why doesn't the Button1 render
to my form's canvas?
Well, for starters, your button is invisible when you draw it. And second,
you are drawing it to the form's Canvas, which is not valid outside of the
form's OnPaint event. Your drawing it going to disappear as soon as the
form redraws itself.
Quote
I noticed that the form's OnPaint gets called when I make the
button invisible, but it doesn't get called after WM_PRINT, which
it should.
No, it shouldn't.
Gambit
 

Re:Rendering controls to canvas

"Thorsten Kettner" < XXXX@XXXXX.COM >wrote in message
Quote
Hm, I guess you mean "let the form be Parent of the controls",
right?
Yes.
Quote
Then I would make my controls invisible, and in their paint method
I would deceide to draw them though? Is that what you say?
No, that is not what he is saying. He is telling you the same thing that I
am - don't use a second form at all, and just put the controls directly onto
your main form, keep them visible, and let them draw themselves normally.
Then you don't have to do anything extra on your part at all to show them.
Quote
Well, as far as I see the controls' Paint method does not get called
when they are invisible.
Correct. There is no point in drawing something that cannot be seen in the
first place.
Gambit
 

Re:Rendering controls to canvas

"Remy Lebeau \(TeamB\)" < XXXX@XXXXX.COM >wrote:
Quote

>[snip] I tried WM_PRINT, but it didn't work either. [snip]

Well, for starters, your button is invisible when you draw
it. And second, you are drawing it to the form's Canvas,
which is not valid outside of the form's OnPaint event. Your
drawing it going to disappear as soon as the form redraws
itself.
Okay, so far I understand, but using this informations raises
further questions concerning WM_PRINT. I will ask in the api
group. I think my question belongs there and it is better to
extract new questions to a new thread instead of using the
same thread over and over to place all new enquiries.
Thanks.
 

Re:Rendering controls to canvas

"Thorsten Kettner" < XXXX@XXXXX.COM >wrote in message
Quote

"Remy Lebeau \(TeamB\)" < XXXX@XXXXX.COM >wrote:
>
>>[snip] I tried WM_PRINT, but it didn't work either. [snip]
>
>Well, for starters, your button is invisible when you draw
>it. And second, you are drawing it to the form's Canvas,
>which is not valid outside of the form's OnPaint event. Your
>drawing it going to disappear as soon as the form redraws
>itself.

Okay, so far I understand, but using this informations raises
further questions concerning WM_PRINT. I will ask in the api
group. I think my question belongs there and it is better to
extract new questions to a new thread instead of using the
same thread over and over to place all new enquiries.
This may be obvious, but maybe you meant WM_PAINT, and not WM_PRINT?
- Dennis
 

Re:Rendering controls to canvas

"Dennis Jones" < XXXX@XXXXX.COM >wrote:
Quote
This may be obvious, but maybe you meant WM_PAINT, and not
WM_PRINT?
No, I mean WM_PRINT. WM_PAINT paints the control to its
parent's canvas, WM_PRINT paints it to the canvas you specify.
But thanks anyhow, Dennis.
PS: I got it working now. WM_PRINT dosn't work with Perform on
my system, but with SendMessage it works. Don't know why, but I
don't care much, actually, now that my problem is solved.
 

Re:Rendering controls to canvas

"Thorsten Kettner" < XXXX@XXXXX.COM >wrote in message
Quote
No, I mean WM_PRINT. WM_PAINT paints the
control to its parent's canvas
No, it doesn't. Where did you get that idea from? Like WM_PRINT, WM_PAINT
also has an HDC as the message's wParam value. All painting is done to the
provided HDC.
Quote
WM_PRINT paints it to the canvas you specify.
So does WM_PAINT.
Gambit
 

Re:Rendering controls to canvas

"Remy Lebeau \(TeamB\)" < XXXX@XXXXX.COM >wrote:
Quote

"Thorsten Kettner" < XXXX@XXXXX.COM >wrote:
>No, I mean WM_PRINT. WM_PAINT paints the
>control to its parent's canvas

No, it doesn't. Where did you get that idea from? Like
WM_PRINT, WM_PAINT also has an HDC as the message's wParam
value. All painting is done to the provided HDC.
Oh yes, you are right. I didn't see that. So the difference
between WM_PAINT and WM_PRINT is only that WM_PRINT paints
clipped and invisible parts, too.