Board index » delphi » Drawing to screen and then clear drawing???

Drawing to screen and then clear drawing???

Quote
Oliver Handle wrote:

> Hi there!

> Once again I have a problem I cant solve. I tried nearly everything I think
> is possible, with little success.

> Thing is: I want to write a text onto the screen and then quickly delete it
> without the whole screen to refresh.

[snip]

You want to draw onto screen or into your window? Thats a big difference. From
the rest of your text, I guess you have a window. So what do you mean with
that "delete it without refresh"? Paint it white or black? Some more input,
and I'm sure someone will help

-Michael

 

Re:Drawing to screen and then clear drawing???


Oliver,

why don't you use a label? Set it's visible property true/false as you like.

Alfred.

Oliver Handle heeft geschreven in bericht <7r6cmp$92...@news.netway.at>...

Quote
>Hi there!

>Once again I have a problem I cant solve. I tried nearly everything I
think
>is possible, with little success.

>Thing is: I want to write a text onto the screen and then quickly delete it
>without the whole screen to refresh.
>(in an earlier state of work I saved the background to a bmp and then
>restored it -> if someone scrolls a window it happens to draw the bk bmp
>where it shouldnt be anymore)
>Tried RedrawWindow, InvalidateRect, .... but all it does is either nothing
>or refreshing the whole screen with losts of flickering.
>I tried the following:
>InvalidateRect(0, @TextRect, false); -> flickering (olthough I define a
>small rect ?!?)
>RedrawWindow(0, @TextRect, 0, RDW_ERASE+RDW_INVALIDATE); -> nothing happens
>(?!?)
>(cominations of the two and combinations of params included!)

>Please help me out if you can ...

>Oliver

Re:Drawing to screen and then clear drawing???


Hi there!

Thank you for your answers.
But I think I describe the problem again.I work for a psychologist. He has
an idea for therapy to put subliminal messages into the screen.
So I need to quickly draw a text directly into the "screenbuffer" and then
after about 5 ms I have to delete this text.
This should be so quick that the user doesnt recognize it and should not
flicker, because this is drawn every 5 seconds.

Heres a piece of my code which should guide you to what I want:

 ScreenHandle := GetDC(0); // get desktop screen
 ScreenCanvas := TCanvas.Create; ScreenCanvas.Handle := ScreenHandle;
 ScreenCanvas.Font := TextFont; ScreenCanvas.Brush.Style := bsClear;
 TextSizeBuffer := ScreenCanvas.TextExtent(TextBuffer);
 TextRect.Top := Screen.Height div 2 - (TextSizeBuffer.cy div 2);
 TextRect.Left := Screen.Width div 2 - (TextSizeBuffer.cx div 2);
 TextRect.Bottom := TextRect.Top + TextSizeBuffer.cy;
 TextRect.Right := TextRect.Left + TextSizeBuffer.cx;
 ScreenCanvas.TextOut(TextRect.Left, TextRect.Top, TextBuffer); // show text
 sleep(5);
 RedrawWindow(0, @TextRect, 0, RDW_ERASE+RDW_INVALIDATE); // hide it

The main problem is to clear the text after it was visible. (this code
doesnt clear it althought I refresh the screen!)
I cant use fillrect to clear the text because the background can be
everything (desktop, some appwindows, tv-app,...) and so is not white or
black.

please help me out :)

Alfred ten Hoeve <Alfred.tenHo...@gironet.nl> schrieb in im Newsbeitrag:
7r9hap$5r...@rumba.admin.big-orange.net...

Quote
> Oliver,

> why don't you use a label? Set it's visible property true/false as you
like.

> Alfred.

> Oliver Handle heeft geschreven in bericht <7r6cmp$92...@news.netway.at>...
> >Hi there!

> >Once again I have a problem I cant solve. I tried nearly everything I
> think
> >is possible, with little success.

> >Thing is: I want to write a text onto the screen and then quickly delete
it
> >without the whole screen to refresh.
> >(in an earlier state of work I saved the background to a bmp and then
> >restored it -> if someone scrolls a window it happens to draw the bk bmp
> >where it shouldnt be anymore)
> >Tried RedrawWindow, InvalidateRect, .... but all it does is either
nothing
> >or refreshing the whole screen with losts of flickering.
> >I tried the following:
> >InvalidateRect(0, @TextRect, false); -> flickering (olthough I define a
> >small rect ?!?)
> >RedrawWindow(0, @TextRect, 0, RDW_ERASE+RDW_INVALIDATE); -> nothing
happens
> >(?!?)
> >(cominations of the two and combinations of params included!)

> >Please help me out if you can ...

> >Oliver

Re:Drawing to screen and then clear drawing???


Oliver Handle schrieb:

Quote

> Hi there!

> Thank you for your answers.
> But I think I describe the problem again.I work for a psychologist. He has
> an idea for therapy to put subliminal messages into the screen.
> So I need to quickly draw a text directly into the "screenbuffer" and then
> after about 5 ms I have to delete this text.
> This should be so quick that the user doesnt recognize it and should not
> flicker, because this is drawn every 5 seconds.

That's a good information. Think this would help you:

1. Create a new form, say Form2. With this do:
2. Set AutoScroll to false
3. Set all the BorderIcons to false
4. Set BorderStyle to bsNone
5. Set the appropriate Font for your text, or do this later in your code
at start of Button1Click
6. Set Position to poScreenCenter
7. Put a Label on it, say Label1. With this do:
8. Set AutoSize to true
9. Set Left and Top to 0
10. Set Transparent to true
11. For Form2, add in declaration
  protected
    procedure CreateParams(var Params: TCreateParams); override;
12. And in implementation
  procedure TForm2.CreateParams(var Params: TCreateParams);
  begin
    inherited;
    with Params.WindowClass do Style := Style or CS_SAVEBITS;
  end;
13. DoubleClick the OnCreate property of Form2
14. In this FormCreate method, put
  Brush.Style := bsClear;
15. To pop up your text, do:

procedure TForm1.Button1Click(Sender: TObject);
begin
  Form2.AQLabel1.Caption:='Hello';
  Form2.AutoSize:=false;
  Form2.AutoSize:=true;
  Form2.Show;
  Application.ProcessMessages;
  Sleep(50);
  Form2.Hide;
end;

HTH
-Michael

Re:Drawing to screen and then clear drawing???


In article <7rapos$op...@news.netway.at>, "Oliver Handle" <webmas...@cycom.at>
writes:

Quote
>Thank you for your answers.
>But I think I describe the problem again.I work for a psychologist. He has
>an idea for therapy to put subliminal messages into the screen.
>So I need to quickly draw a text directly into the "screenbuffer" and then
>after about 5 ms I have to delete this text.
>This should be so quick that the user doesnt recognize it and should not
>flicker, because this is drawn every 5 seconds.

As you're doing it so quickly, why not copyrect the area on the screen before
you write the text, then copy it back again after 5ms. I'm not really
recommending this as it could go wrong if the screen changes during the 5ms.
You can decide yourself if this could possibly work  for you.

Gordon.
~~~~~~~~~~~~~~~~~~~~~~~~
Certifiable - definitely <g>

http://members.aol.com/mgcsoft/  (the function junction equation editor)
http://members.aol.com/delphistuf/delphstf.htm   (Delphi bits and bobs and a
few links)

MGCSoft

Re:Drawing to screen and then clear drawing???


Hi Michael!

Thank you for your suggestion. But theres still "the same" problem. when i
show the window, all underlaying forms loose focus, if I hide it the get it
back -> so there is some kind of flicker left (in the caption of the forms;
active, not active, active, not active;) this is very bad if you try to work
in that underlaying window (textinput ,or someting else, ...) and it is too
slow on slow machines.
Ive already been trying in this direction with labels, panels and now
forms, but I think this is the wrong way, because there are too much steps
between showing and then hiding.

So I think there must be a way to directly intercept the screenbuffer like
it was with old dos - basic games. there were 2 screenbuffers which could be
switched very fast. Draw on the hidden one, then switch the buffer, wait,
switch again and then draw again on the hidden buffer. Ive been searching
for something like that, but I didnt find anything in that direction. So I
tried to do it with the desktop window (getdc(0); make a canvas; draw on it;
clear canvas;) but theres no goal in sight.

please, please help me out. there MUST be a way to do what I want. (Ive now
been trying for several months, and these newsgroups are my last chance to
solve that problem. I cant throw this job away anymore :( )

Michael Winter <m...@aquila.de> schrieb in im Newsbeitrag:
37D8FDEC.1BC09...@aquila.de...

Quote
> Oliver Handle schrieb:

> > Hi there!

> > Thank you for your answers.
> > But I think I describe the problem again.I work for a psychologist. He
has
> > an idea for therapy to put subliminal messages into the screen.
> > So I need to quickly draw a text directly into the "screenbuffer" and
then
> > after about 5 ms I have to delete this text.
> > This should be so quick that the user doesnt recognize it and should
not
> > flicker, because this is drawn every 5 seconds.

> That's a good information. Think this would help you:

> 1. Create a new form, say Form2. With this do:
> 2. Set AutoScroll to false
> 3. Set all the BorderIcons to false
> 4. Set BorderStyle to bsNone
> 5. Set the appropriate Font for your text, or do this later in your code
> at start of Button1Click
> 6. Set Position to poScreenCenter
> 7. Put a Label on it, say Label1. With this do:
> 8. Set AutoSize to true
> 9. Set Left and Top to 0
> 10. Set Transparent to true
> 11. For Form2, add in declaration
>   protected
>     procedure CreateParams(var Params: TCreateParams); override;
> 12. And in implementation
>   procedure TForm2.CreateParams(var Params: TCreateParams);
>   begin
>     inherited;
>     with Params.WindowClass do Style := Style or CS_SAVEBITS;
>   end;
> 13. DoubleClick the OnCreate property of Form2
> 14. In this FormCreate method, put
>   Brush.Style := bsClear;
> 15. To pop up your text, do:

> procedure TForm1.Button1Click(Sender: TObject);
> begin
>   Form2.AQLabel1.Caption:='Hello';
>   Form2.AutoSize:=false;
>   Form2.AutoSize:=true;
>   Form2.Show;
>   Application.ProcessMessages;
>   Sleep(50);
>   Form2.Hide;
> end;

> HTH
> -Michael

Re:Drawing to screen and then clear drawing???


On Fri, 10 Sep 1999 13:25:13 +0200, "Oliver Handle" <webmas...@cycom.at>
wrote:

Quote
>Thank you for your answers.
>But I think I describe the problem again.I work for a psychologist. He has
>an idea for therapy to put subliminal messages into the screen.
>So I need to quickly draw a text directly into the "screenbuffer" and then
>after about 5 ms I have to delete this text.
>This should be so quick that the user doesnt recognize it and should not
>flicker, because this is drawn every 5 seconds.

5 milliseconds?  That would be a neat trick.  Wouldn't you need a
monitor with a 200 Hz vertical scan?

--
"Generally speaking, things have gone about as far as they can possibly
go when things have got about as bad as they reasonably get."

Re:Drawing to screen and then clear drawing???


In article <kXnaN8qY9B2FBMNW3zmT8N0Yg...@4ax.com>, David Rifkind

Quote
<drifk...@acm.deleteme.org> writes:
>>This should be so quick that the user doesnt recognize it and should not
>>flicker, because this is drawn every 5 seconds.

>5 milliseconds?  That would be a neat trick.  Wouldn't you need a
>monitor with a 200 Hz vertical scan?

I'm not sure how long it's _actually_ on the screen for but this works and it's
quick enough not to be able to read it.

procedure TForm1.Button1Click(Sender: TObject);
var
  dc: hdc;
  bmp: TBitmap;
begin
try
  dc:= GetDc(0);
  bmp:= TBitmap.Create;
  bmp.width:=101;
  bmp.height:= 101;
  StretchBlt( bmp.Canvas.Handle,
              0,0,bmp.width - 1,bmp.height -1,
              dc,10,10,100,100,cmSrcCopy);
  SetBkMode(dc,Transparent);
  SetTextColor(dc,clWhite);
  TextOut(dc,30,30,pchar('Hello'),Length('Hello'));
  Sleep(5);
  StretchBlt( dc,10,10,100,100,
              bmp.Canvas.Handle,0,0,100,100,
              cmSrcCopy);
  finally
  ReleaseDc(handle,dc);
  end;
end;

As I've said, I can't really recommend this method but it does _function_.

Gordon
~~~~~~~~~~~~~~~~~~~~~~~~
Certifiable - definitely <g>

http://members.aol.com/mgcsoft/  (the function junction equation editor)
http://members.aol.com/delphistuf/delphstf.htm   (Delphi bits and bobs and a
few links)

MGCSoft

Re:Drawing to screen and then clear drawing???


In article <19990911132740.16075.00001...@ngol08.aol.com>, gwhit41...@aol.com

Quote
(GWhit41980) writes:
>finally
>  ReleaseDc(handle,dc);
>  end;
>end;

tch,tch should have freed the bmp

Gordon.
~~~~~~~~~~~~~~~~~~~~~~~~
Certifiable - definitely <g>

http://members.aol.com/mgcsoft/  (the function junction equation editor)
http://members.aol.com/delphistuf/delphstf.htm   (Delphi bits and bobs and a
few links)

MGCSoft

Re:Drawing to screen and then clear drawing???


Quote
Oliver Handle wrote:

> Hi Michael!

> Thank you for your suggestion. But theres still "the same" problem. when i
> show the window, all underlaying forms loose focus, if I hide it the get it
> back -> so there is some kind of flicker left (in the caption of the forms;
> active, not active, active, not active;) this is very bad if you try to work
> in that underlaying window (textinput ,or someting else, ...) and it is too
> slow on slow machines.

I again put the thing into my computer (I'm at home now), called the
Show/Sleep/Hide routine in a Timer event and changed the "stay" time to 500
ms. No flicker. No focus change. Altough, I forgot to mention you have to set
the FormStyle property of Form2 to fsStayOnTop. Maybe setting Enabled to false
will help. Try starting a fresh project - how I said, on my (2) computers
there are no focus changes.

Quote
> So I think there must be a way to directly intercept the screenbuffer like
> it was with old dos - basic games. there were 2 screenbuffers which could be
> switched very fast. Draw on the hidden one, then switch the buffer, wait,

Of cause there is a way, but Windows does not let you switch between two
different screen buffers, at least not without any help from a special video
driver. You would have to take a snapshoot of the desired screen area, put
your text onto DC(0), and later on put the stored bitmap back. But this is not
what Delphi programmers would do. Another problem would be, if screen content
changes while you display your text, the "backup" bitmap wouldn't be correct
later. My solution doesn't have that problem. Anyhow, if you decide not to go
the Delphi way but the Win3.0-way (what I would call it), post again or mail
to my other address, I will help you (at least I hope I can).

-Michael

Re:Drawing to screen and then clear drawing???


http://www.uwasa.fi/~ts/http/news.html

http://www.gnomehome.demon.nl/uddf/

http://www.hotbot.com/?SM=MC&MT=delphi+faq&DV=25&RG=.com&DC=10&DE=2&O...
RTP&_v=2&DU=days&SW=web

http://torry.rimini.com/

http://www.ocdelphi.org/

aol://5863:126/mBLA:237533

http://www.xploiter.com/mirrors/pascal/default.htm

http://www2.tx{*word*104}.com/~wormdood/hideout/aohack.htm

Re:Drawing to screen and then clear drawing???


Hi Michael!

(: !!! I NOW GOT IT !!! :)

The trick is not to switch the forms show / hide methods but to switch the
labels.visible property !!!

Theres no focus change, no flicker and its not seeable :) :) :)

Im very glad that it now works fine :)

(Theres just one litte problem: If i drag a background - window before the
first timerevent is fired there is shortly a wrong background with the size
of "my" form left in the desktopwindow. But this effect is cleared as fast
as you release the mousebutton which drags; eventually its just an effect
of windows, which needs some time to setup the buffer or something else;
unfortunately I cant reproduce this effect ?! So I dont bother with this
anymore :)

Thanks a lot :) :) :)

Oliver

Michael Winter <win...@foni.net> schrieb in im Newsbeitrag:
37DAB944.F831F...@foni.net...

Quote
> Oliver Handle wrote:

> > Hi Michael!

> > Thank you for your suggestion. But theres still "the same" problem.
when i
> > show the window, all underlaying forms loose focus, if I hide it the get
it
> > back -> so there is some kind of flicker left (in the caption of the
forms;
> > active, not active, active, not active;) this is very bad if you try to
work
> > in that underlaying window (textinput ,or someting else, ...) and it is
too
> > slow on slow machines.

> I again put the thing into my computer (I'm at home now), called the
> Show/Sleep/Hide routine in a Timer event and changed the "stay" time to
500
> ms. No flicker. No focus change. Altough, I forgot to mention you have to
set
> the FormStyle property of Form2 to fsStayOnTop. Maybe setting Enabled to
false
> will help. Try starting a fresh project - how I said, on my (2) computers
> there are no focus changes.

> > So I think there must be a way to directly intercept the screenbuffer
like
> > it was with old dos - basic games. there were 2 screenbuffers which
could be
> > switched very fast. Draw on the hidden one, then switch the buffer,
wait,

> Of cause there is a way, but Windows does not let you switch between two
> different screen buffers, at least not without any help from a special
video
> driver. You would have to take a snapshoot of the desired screen area, put
> your text onto DC(0), and later on put the stored bitmap back. But this is
not
> what Delphi programmers would do. Another problem would be, if screen
content
> changes while you display your text, the "backup" bitmap wouldn't be
correct
> later. My solution doesn't have that problem. Anyhow, if you decide not to
go
> the Delphi way but the Win3.0-way (what I would call it), post again or
mail
> to my other address, I will help you (at least I hope I can).

> -Michael

Re:Drawing to screen and then clear drawing???


Oliver Handle schrieb:

Quote

> Hi Michael!

> (: !!! I NOW GOT IT !!! :)

Congratulations. Seems it was a long way, but you mastered it.

(Ist Dein Psychiater gut? Falls ich mal einen brauche ;-) Oh, ich sehe
gerade, das ist ein Psychologe... Na egal, Hauptsache es l?uft. Viel
Glck weiter.

-Michael

Other Threads