Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Help!! Drawing a text using DrawText on the from and Changing CRect of form according the Text.

Help!! Drawing a text using DrawText on the from and Changing CRect of form according the Text.

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++comgraphicstutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    VikramDelhi i
    wrote on last edited by
    #1

    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

    R 1 Reply Last reply
    0
    • V VikramDelhi i

      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

      R Offline
      R Offline
      Ravi Bhavnani
      wrote on last edited by
      #2

      You should consider using a CListBox or a CListCtrl to display a collection of birthdays. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups