SetWindowRgn For Text Or Label
-
There is a lot of samples for RGN's for bitmaps but I need to create a RGN for Text with a font and size. How can I do it? thanks in advance
Can you more explain,please? ;)
Of one Essence is the human race thus has Creation put the base One Limb impacted is sufficient For all Others to feel the Mace (Saadi )
-
Can you more explain,please? ;)
Of one Essence is the human race thus has Creation put the base One Limb impacted is sufficient For all Others to feel the Mace (Saadi )
I want to display text on the screen in such a way so the user will see only the text (Not the window). The RGN is made to disable coloring outside of specific places in the window. The effect of it is so you can make windows in a shape you design as so http://www.codeproject.com/KB/GDI/coolrgn.aspx[^]. How do I do the same effect on text?
-
There is a lot of samples for RGN's for bitmaps but I need to create a RGN for Text with a font and size. How can I do it? thanks in advance
Do you mean you wish to create a region with the shape of text? If so, try this, am not sure if it works but it is worth a try: 1. Create your font and select into a DC (a memory DC should work) 2. Use BeginPath to begin defining a path 3. Use TextOut or DrawText or such to display the text 4. Use CreateFromPath[^] to create a region. It is possible that it only works with vector-based fonts.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
-
Do you mean you wish to create a region with the shape of text? If so, try this, am not sure if it works but it is worth a try: 1. Create your font and select into a DC (a memory DC should work) 2. Use BeginPath to begin defining a path 3. Use TextOut or DrawText or such to display the text 4. Use CreateFromPath[^] to create a region. It is possible that it only works with vector-based fonts.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
Thanks for helping The function don't work with all fonts so I did this
SetRgn(CString str)
{
CRect r;GetClientRect(&r);
CMemoryDC dc(GetDC(),r);
CFont font;font.CreatePointFont(120,L"Arial",0,true);
COLORREF bgColor=dc.GetBkColor();
dc.FillSolidRect(r,bgColor);dc.SelectFont(font); dc.TextOut(0,0,str); CRgn rgn,tRgn;rgn.CreateRectRgn(0,0,0,0); for (int x=r.left;x<r.right;x++)> { for (int y=r.top;y<r.bottom;y++)> { if(!(!tRgn))tRgn.DeleteObject(); COLORREF c=dc.GetPixel(x,y); if(c!=bgColor) { tRgn.CreateRectRgn(x,y,x+1,y+1); rgn.CombineRgn(rgn,tRgn,RGN\_OR); } } } SetWindowRgn(rgn);
}
-
Thanks for helping The function don't work with all fonts so I did this
SetRgn(CString str)
{
CRect r;GetClientRect(&r);
CMemoryDC dc(GetDC(),r);
CFont font;font.CreatePointFont(120,L"Arial",0,true);
COLORREF bgColor=dc.GetBkColor();
dc.FillSolidRect(r,bgColor);dc.SelectFont(font); dc.TextOut(0,0,str); CRgn rgn,tRgn;rgn.CreateRectRgn(0,0,0,0); for (int x=r.left;x<r.right;x++)> { for (int y=r.top;y<r.bottom;y++)> { if(!(!tRgn))tRgn.DeleteObject(); COLORREF c=dc.GetPixel(x,y); if(c!=bgColor) { tRgn.CreateRectRgn(x,y,x+1,y+1); rgn.CombineRgn(rgn,tRgn,RGN\_OR); } } } SetWindowRgn(rgn);
}
I supose it really only works for vector-fonts since a raster-font probably has nothing to put into a path...Anyways, isn't that solution a bit slow?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
-
I supose it really only works for vector-fonts since a raster-font probably has nothing to put into a path...Anyways, isn't that solution a bit slow?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
I did a test in debug mode with breakpoints...(not the best way to check) 1000*1000=1,000,000 loop It was only 5 sec. a normal textout will not export so much as so. Update...
CSize sizeText;dc.GetTextExtent(str,str.GetLength(),&sizeText); for (int x=r.left;x<sizetext.cx;x++)> { for (int y=r.top;y<sizetext.cy;y++)>
....
modified on Monday, December 29, 2008 9:34 AM