|
-
December 5th, 2007, 07:33 PM
#1
DrawText draw ouside the rect
Hi,
In my sdi application, when i try to use draw text, nothing appear. I tried DT_NOCLIP and i noticed that the text was drawn under the rect i send to the function
Code:
CRect rc(re.m_Location,re.m_Size);
switch(GetDocument()->m_ReportElement[i].m_Type) {
case RECTANGLE:
pDC->Rectangle(rc);
break;
case ELIPSE:
pDC->Ellipse(rc);
break;
case TEXT:
//int OLDMODE = pDC->SetMapMode(MM_TEXT); // old mode is MM_ISOTROPIC
pDC->Rectangle(rc);
pDC->DrawText("top", &rc, DT_LEFT | DT_TOP);
//pDC->SetMapMode(OLDMODE);
//pDC->TextOut(rc.left, rc.top, re.m_Text);
break;
}
Anyone can explain me why and give me a solution for the text to be drawn in the rect.
Thanks
-
December 6th, 2007, 12:13 AM
#2
Re: DrawText draw ouside the rect
Your description is not clear.
- Are you saying, if you specify DT_NOCLIP, you see the text. But if you don't specify DT_NOCLIP, you don't see the text ?
- In what class and what function have you placed this code ?
-
December 6th, 2007, 02:31 PM
#3
Re: DrawText draw ouside the rect
Code:
pDC->Rectangle(rc);
pDC->DrawText("top", &rc, DT_LEFT | DT_TOP);
Under normal circumstances this code will draw a rectangle on the screen and will write the text in the top left corner.
If this isn't happening it's because the circumstances aren't normal. There is something in the pDC settings that is not the way it should be.
You can test the two commands from a new project. Only create and select a brush and define a rectangle. DO NOT DO ANYTHING ELSE. It will work perfectly.
From what I can see I suspect that there are problems with the way the rectangle is defined. Possibly the parameters of the rectangle are not the way they should be for a given mapping mode. (All mapping modes, except MM_TEXT, require negative y coordinates - the 2-nd and 4-th parameters of the rectangle.)
Even if you are aware of that, you may still have an error in the coordinates or size computation.
This is not the only possibility, there may be others as well but I don't know what else you have in your application.
If you created the new project as I suggested, try to copy in it one by one each additional setting for pDC and watch when the issue will pop up.
-
December 6th, 2007, 03:24 PM
#4
Re: DrawText draw ouside the rect
srelu is right that the two lines of code by themselves should display the text properly and that the problem is most likely with the state of the CDC or some other unknown factor.
Since the text is drawn under the rectangle when you use DT_NOCLIP I would guess that it may have something to do with the rectangle having its top and bottom mixed up. An easy test would be to call rc.NormalizeRect() before using it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|