Help!! Drawing a text using DrawText on the from and Changing CRect of form according the Text.
-
Hi
I am new to GUI programming. I am learning MFC and able to create one application.
But I have one problem that i am not able to solve yet.Problem:
I want to display a message that tells the upcoming Birthdays. I don't know how long birthday list can be, so I can't use Static control. I tried to use DrawText() Function to draw text. I know DrawText() extends the base of the rectangle to bound the last line of text. I am able to draw the text message but have following problems.-
I don't know how to get the correct height of the text message rect.
-
How to change the dimensions of the Dialog box according the text message.
-
Sometimes Text is not displayed, only blank area is displayed. Don't know why?
I want to do something like this: Link to IMAGE
I Created DrawText() Function which paint the text. I called DrawText() in OnPaint().
void CRUNDlg::DrawText()
{CPaintDC dc(this);
CRect rect,rcDialog,temprec;
CFont fFont;
CFont *fOldFont;
int h; // i tried to use h to calculate height of text but in vain// rect: for DrawText
// rcDialog: for Dialog dimensions
// temprec: for height calculation of text drawn
//GetWindowRect(&rcDialog);
GetClientRect(&rect);dc.SetTextColor(RGB(0,0,196));
dc.SetBkMode(TRANSPARENT);temprec=rcDialog;
temprec.bottom=0;
temprec.bottom =rect.top=10;fFont.CreateFont(20,0,0,0,FW_NORMAL|FW_BLACK,0,1,0,DEFAULT_CHARSET,OUT_CHARACTER_PRECIS,CLIP_CHARACTER_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|FF_DONTCARE,"Arial");
fOldFont =dc.SelectObject(&fFont);h=dc.DrawText("Birthday Alert",rect,DT_NOCLIP|DT_CENTER);
temprec.bottom+=rect.top;fFont.Detach();
fFont.CreateFont(15,0,0,0,FW_NORMAL|FW_BLACK,0,0,0,DEFAULT_CHARSET,OUT_CHARACTER_PRECIS,CLIP_CHARACTER_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|FF_DONTCARE,"Arial");
fOldFont -
-
Hi
I am new to GUI programming. I am learning MFC and able to create one application.
But I have one problem that i am not able to solve yet.Problem:
I want to display a message that tells the upcoming Birthdays. I don't know how long birthday list can be, so I can't use Static control. I tried to use DrawText() Function to draw text. I know DrawText() extends the base of the rectangle to bound the last line of text. I am able to draw the text message but have following problems.-
I don't know how to get the correct height of the text message rect.
-
How to change the dimensions of the Dialog box according the text message.
-
Sometimes Text is not displayed, only blank area is displayed. Don't know why?
I want to do something like this: Link to IMAGE
I Created DrawText() Function which paint the text. I called DrawText() in OnPaint().
void CRUNDlg::DrawText()
{CPaintDC dc(this);
CRect rect,rcDialog,temprec;
CFont fFont;
CFont *fOldFont;
int h; // i tried to use h to calculate height of text but in vain// rect: for DrawText
// rcDialog: for Dialog dimensions
// temprec: for height calculation of text drawn
//GetWindowRect(&rcDialog);
GetClientRect(&rect);dc.SetTextColor(RGB(0,0,196));
dc.SetBkMode(TRANSPARENT);temprec=rcDialog;
temprec.bottom=0;
temprec.bottom =rect.top=10;fFont.CreateFont(20,0,0,0,FW_NORMAL|FW_BLACK,0,1,0,DEFAULT_CHARSET,OUT_CHARACTER_PRECIS,CLIP_CHARACTER_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|FF_DONTCARE,"Arial");
fOldFont =dc.SelectObject(&fFont);h=dc.DrawText("Birthday Alert",rect,DT_NOCLIP|DT_CENTER);
temprec.bottom+=rect.top;fFont.Detach();
fFont.CreateFont(15,0,0,0,FW_NORMAL|FW_BLACK,0,0,0,DEFAULT_CHARSET,OUT_CHARACTER_PRECIS,CLIP_CHARACTER_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|FF_DONTCARE,"Arial");
fOldFontYou should consider using a
CListBox
or aCListCtrl
to display a collection of birthdays. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com -