I use TextOut to textout my text on the window at ramdom places but I dont know why the just written text still stays alive and waits to be overwritten by other texts when those texts' positions are next to or near it.
How could I solve this problem ?
Thanks a lot,
Regards,
Fiona
Marc G
January 14th, 2004, 02:56 PM
I don't understand your problem :confused:
Could you elaborate a bit more in detail?
Explain what you are doing?
Perhaps post the most relevant piece of code?
Sam Hobbs
January 14th, 2004, 03:21 PM
Originally posted by Homestead
I use TextOut to textout my text on the window at ramdom places but I dont know why the just written text still stays alive and waits to be overwritten by other texts when those texts' positions are next to or near it.What part of that is a problem? My interpretation of what you said is that there is not a problem; you seem to be describing the normal way that Windows works.
Homestead
January 14th, 2004, 07:40 PM
I mean the text drawn at random places and about redraw problem, I want it drawn only once and then when it s drawn again, it is to be drawn at a different place.
I could make the color random but I could make the text draw once only. It s drawn here but when it jumps to another place, the old drawn text is still there....
Now you understand my problem ?
Thanks a lot,
Regards,
Fiona
Sam Hobbs
January 14th, 2004, 08:04 PM
It still is not clear what is the problem and what is not the problem.
First describe what you want to happen and only what you want to happen, with no mention of what is or is not happening that you don't want to happen or that you do want to happen.
Then describe:
what is happening that you don't want to happen
is not happening that you want to happen
Then describe how you are trying to do what you need to do.
The problem is that sometimes people describe all of those things at the same time without clearly specifiying which is which.
Homestead
January 14th, 2004, 08:33 PM
I meant when my new text appears at a certain position, the old text should be deleted but I couldnt delete it, and do not know how to delete it, could you tell me ?
Thanks Sam,
Regards,
Fiona
Sam Hobbs
January 14th, 2004, 09:18 PM
Okay, now we are getting somewhere. In other words, I think that describes what it is that you want to do. I don't know how to do that, but if I understand the question, then it is something that has been asked before and there are answers available. However I know it would be difficult for you to find the previous questions and answers.
I think the most common solution includes use of Raster Operation Codes (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/pantdraw_73jn.asp), but I don't know anything more than that. A Raster Operation Code is also called a ROP. If you search for "ROP" you might find an answer. Otherwise, if you don't get an answer soon, post another question with the subject "How to move text around the window" or something like that, and make it clear that you need to remove some text from one place and redraw it another place. You can include a link to this thread, so that people should not complain about posting the question a second time.
Homestead
January 14th, 2004, 10:07 PM
Originally posted by Sam Hobbs
Okay, now we are getting somewhere. In other words, I think that describes what it is that you want to do. I don't know how to do that, but if I understand the question, then it is something that has been asked before and there are answers available. However I know it would be difficult for you to find the previous questions and answers.
I think the most common solution includes use of Raster Operation Codes (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/pantdraw_73jn.asp), but I don't know anything more than that. A Raster Operation Code is also called a ROP. If you search for "ROP" you might find an answer. Otherwise, if you don't get an answer soon, post another question with the subject "How to move text around the window" or something like that, and make it clear that you need to remove some text from one place and redraw it another place. You can include a link to this thread, so that people should not complain about posting the question a second time.
Now it s my turn to not undestand what you are talking about ? :confused:
I dont think there is anything about ROP, but it s Okay, I learn new thing, I already visit that page, you can check again...True !
Thanks Sam a lot,
Regards,
Fiona
Sam Hobbs
January 14th, 2004, 11:53 PM
I found a previous post with sample code that makes text move with the mouse. Whenever the mouse moves, the text moves with it. See if you can find that previous post. The code uses BeginPath, EndPath, SetROP2 and StrokePath. I tried the code and it works.
mdmd
January 14th, 2004, 11:55 PM
ROCs work with a pen. Fonts and TextOut don't use a pen.
Without seeing your code its hard to see exactly the best solution
for you. But these suggestions may be a start.
InvalidateRect
If you have the coordinates of the previous text, invalidate that
rect so it will be redrawn.
FillRect
If you have the coordinates of the previous text, draw over them
with a brush with the same color as the background of the
window.
Maybe post your code if you're having issues ?:thumb:
Sam Hobbs
January 15th, 2004, 12:16 AM
Originally posted by mdmd
ROCs work with a pen. Fonts and TextOut don't use a pen.If you are saying that BeginPath, EndPath, SetROP2 and StrokePath don't work with TextOut, then you really, really should be more careful. Perhaps I misunderstand the code I found, but if I understand it and it works as I describe, will you admit you were too quick to say it won't work?
mdmd
January 15th, 2004, 12:44 AM
Originally posted by Sam Hobbs
If you are saying that BeginPath, EndPath, SetROP2 and StrokePath don't work with TextOut, then you really, really should be more careful. Perhaps I misunderstand the code I found, but if I understand it and it works as I describe, will you admit you were too quick to say it won't work?
Read my post again - noting the times and what I mentioned.
Mine was being written as yours was being posted.
My statement was about ROC.
Now of the functions you mentioned only SetROP2 sets an ROC.
ROCs effect pens. I noted that TextOut does not use a pen.
Therefore SetROP2 will have no effect on TextOut.
Bringing in Paths( bitmaps, patblt, etc ) changes the issue.
Sam Hobbs
January 15th, 2004, 12:48 AM
Originally posted by mdmd
Mine was being written as yours was being posted.Well that does make a difference.
Originally posted by mdmd
Bringing in Paths( bitmaps, patblt, etc ) changes the issue.Note that the sample code was written by Feng Yuan, who wrote a book about Windows graphics programming.
mdmd
January 15th, 2004, 01:34 AM
Originally posted by Sam Hobbs
Note that the sample code was written by Feng Yuan, who wrote a book about Windows graphics programming.
Thats funny, I didn't know he was a member here. I have the
book but I don't see that sample in it. Searching on his name
and strokepath didn't bring up anything either, but I didn't
scrutinize all the posts, just titles.
I think R2_NOTXORPEN would be the mode to use before
beginning the path that will erase the text from the previous
path but I remember learning that this leaves artifacts behind on
some windows versions. I'd like to know what he uses now, but
I'll wager InvalidateRect()
mdmd
January 15th, 2004, 01:37 AM
Yeah, and StrokePath outlines the text in a box too, right ? I'm
pretty sure.
Sam Hobbs
January 15th, 2004, 01:40 AM
What's the best way of displaying and dragging text on a CView? (http://www.codeguru.com/forum/showthread.php?s=&threadid=91588)
His code is a little inadequate, since the drawing is done outside of WM_PAINT message processing. I hope is enough to help figure out how to do what Fiona needs to do during WM_PAINT message processing. Perhaps you can help Fiona with that.
mdmd
January 15th, 2004, 02:24 AM
I'll wait for her to post, I'm not sure where she's doing this.
I'd hesitate before using the paths though because in my tests
now the fonts are rendered differently with the paths - Width
and filling. If that doesn't matter than the paths are easy
enough.
There is a box around the text, he uses SetBkMode(TRANSPARENT)
to get rid of it. And always using R2_XORPEN removes any
artifact issue
// Its weird, even though I see the thread, it doesn't come up
// in any of the searches I'm doing :rolleyes:
Homestead
January 15th, 2004, 04:25 AM
char str[50]="Thanks very much for your help :-)" ;
int delay=2000;
switch(message){
case WM_CREATE:
time=SetTimer(hwnd,1,delay,NULL);
brush=(HBRUSH)GetStockObject(BLACK_BRUSH);
break;
case WM_ERASEBKGND:
hdc=GetDC(hwnd);
case WM_DESTROY:
KillTimer(hwnd,time);
break;
You helped me solved the problem.
But since my background is black and the rectangular containing the text when drawn is white, I would like to make it TRANSPARENT, how can I do that ?
Please help me...
Once again, Thanks a lot,
Regards,
Fiona
Marc G
January 15th, 2004, 06:36 AM
Use SetBkMode(hdc, TRANSPARENT);
Also, note that you don't have to use GetDC in your WM_ERASEBKGND handler because wParam is your hdc.
Homestead
January 15th, 2004, 06:49 AM
Originally posted by Marc G
Use SetBkMode(hdc, TRANSPARENT);
Also, note that you don't have to use GetDC in your WM_ERASEBKGND handler because wParam is your hdc.
Thanks Marc very very much, program works realy great now !
:)
Thanks,
Regards,
Fiona
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.