Click here to Skip to main content
15,911,646 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionhow to use a video codec to compress avi file Pin
Mohsen Saad2-Mar-05 15:22
Mohsen Saad2-Mar-05 15:22 
GeneralText to matrix conversion Pin
SeanSheehan2-Mar-05 14:32
SeanSheehan2-Mar-05 14:32 
GeneralSmall executables Pin
Verolix2-Mar-05 13:49
Verolix2-Mar-05 13:49 
GeneralRe: Small executables Pin
ThatsAlok2-Mar-05 18:00
ThatsAlok2-Mar-05 18:00 
Generalresizing workarea Pin
ahto1112-Mar-05 12:07
ahto1112-Mar-05 12:07 
GeneralC++ library Pin
Ahmed Adel2-Mar-05 11:33
Ahmed Adel2-Mar-05 11:33 
GeneralRe: C++ library Pin
ThatsAlok2-Mar-05 18:10
ThatsAlok2-Mar-05 18:10 
QuestionError? Pin
Larsson2-Mar-05 10:53
Larsson2-Mar-05 10:53 
AnswerRe: Error? Pin
Ravi Bhavnani2-Mar-05 10:55
professionalRavi Bhavnani2-Mar-05 10:55 
GeneralRe: Error? Pin
Larsson2-Mar-05 10:57
Larsson2-Mar-05 10:57 
GeneralRe: Error? Pin
Ravi Bhavnani2-Mar-05 11:01
professionalRavi Bhavnani2-Mar-05 11:01 
GeneralRe: Error? Pin
Larsson2-Mar-05 11:06
Larsson2-Mar-05 11:06 
GeneralRe: Error? Pin
Christian Graus2-Mar-05 11:07
protectorChristian Graus2-Mar-05 11:07 
GeneralRe: Error? Pin
Larsson2-Mar-05 11:10
Larsson2-Mar-05 11:10 
GeneralRe: Error? Pin
Christian Graus2-Mar-05 11:13
protectorChristian Graus2-Mar-05 11:13 
GeneralRe: Error? Pin
David Crow3-Mar-05 2:42
David Crow3-Mar-05 2:42 
AnswerRe: Error? Pin
Antony M Kancidrowski2-Mar-05 11:23
Antony M Kancidrowski2-Mar-05 11:23 
GeneralRe: Error? Pin
Larsson2-Mar-05 11:37
Larsson2-Mar-05 11:37 
GeneralRe: Error? Pin
Christian Graus2-Mar-05 11:55
protectorChristian Graus2-Mar-05 11:55 
GeneralRe: Error? Pin
Larsson2-Mar-05 12:01
Larsson2-Mar-05 12:01 
GeneralRe: Error? Pin
Christian Graus2-Mar-05 12:05
protectorChristian Graus2-Mar-05 12:05 
GeneralRe: Error? Pin
Larsson2-Mar-05 12:08
Larsson2-Mar-05 12:08 
GeneralRe: Error? Pin
Larsson2-Mar-05 12:05
Larsson2-Mar-05 12:05 
GeneralHelp!! Drawing a text using DrawText on the from and Changing CRect of form according the Text. Pin
VikramDelhi2-Mar-05 10:19
VikramDelhi2-Mar-05 10:19 

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.




  1. I don't know how to get the correct height of the text
    message rect.


  2. How to change the dimensions of the Dialog box according
    the text message.


  3. 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 =dc.SelectObject(&fFont);



rect.top+=h+5;

temprec.bottom+=rect.top;

dc.SetTextColor(RGB(14,14,255));

h=dc.DrawText("Following is a Birthday
List",rect,DT_EXPANDTABS|DT_NOCLIP|DT_CENTER);



temprec.bottom+=rect.top;

rect.top+=h+5;

temprec.bottom+=rect.top;



dc.SetTextColor(RGB(0,0,0));

h=dc.DrawText("vikram sharma\t21-11-88\nThis Is
Test",rect,DT_EXPANDTABS|DT_NOCLIP|DT_CENTER);

temprec.bottom+=rect.top;



GetWindowRect(&rcDialog);

ClientToScreen(&temprec);

if(!(rcDialog.bottom>= temprec.bottom))

rcDialog.bottom= temprec.bottom;





MoveWindow(&rcDialog);

CentreTheDlg();



}

 


GeneralRe: Help!! Drawing a text using DrawText on the from and Changing CRect of form according the Text. Pin
Ravi Bhavnani2-Mar-05 10:50
professionalRavi Bhavnani2-Mar-05 10:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.