Click here to Skip to main content
15,898,938 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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 
GeneralSimple Chat Program Pin
rct233332-Mar-05 10:02
rct233332-Mar-05 10:02 
GeneralRe: Simple Chat Program Pin
Ravi Bhavnani2-Mar-05 10:51
professionalRavi Bhavnani2-Mar-05 10:51 
GeneralRe: Simple Chat Program Pin
rct233332-Mar-05 11:12
rct233332-Mar-05 11:12 
GeneralRe: Simple Chat Program Pin
Ravi Bhavnani2-Mar-05 12:47
professionalRavi Bhavnani2-Mar-05 12:47 
GeneralRe: Simple Chat Program Pin
ThatsAlok2-Mar-05 18:15
ThatsAlok2-Mar-05 18:15 
QuestionHow to click a bitmap into a bitmap? MFC, Visual C++6 Pin
VogelH2-Mar-05 10:01
professionalVogelH2-Mar-05 10:01 
AnswerRe: How to click a bitmap into a bitmap? MFC, Visual C++6 Pin
Christian Graus2-Mar-05 11:08
protectorChristian Graus2-Mar-05 11:08 
GeneralRe: How to click a bitmap into a bitmap? MFC, Visual C++6 Pin
VogelH2-Mar-05 21:31
professionalVogelH2-Mar-05 21:31 
GeneralRe: How to click a bitmap into a bitmap? MFC, Visual C++6 Pin
Christian Graus3-Mar-05 11:13
protectorChristian Graus3-Mar-05 11:13 
GeneralRe: How to click a bitmap into a bitmap? MFC, Visual C++6 Pin
VogelH4-Mar-05 0:05
professionalVogelH4-Mar-05 0:05 
QuestionExit Program? Pin
Larsson2-Mar-05 9:08
Larsson2-Mar-05 9:08 
AnswerRe: Exit Program? Pin
David Crow2-Mar-05 9:17
David Crow2-Mar-05 9:17 
AnswerRe: Exit Program? Pin
Blake Miller2-Mar-05 10:37
Blake Miller2-Mar-05 10:37 
GeneralRe: Exit Program? Pin
Ed K2-Mar-05 11:09
Ed K2-Mar-05 11:09 
GeneralRe: Exit Program? Pin
Antony M Kancidrowski2-Mar-05 11:28
Antony M Kancidrowski2-Mar-05 11:28 
GeneralRe: Exit Program? Pin
Blake Miller2-Mar-05 11:31
Blake Miller2-Mar-05 11:31 

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.