c++ - How to auto resize the text control in mfc -


i want put text in idc_text in mfc. want auto resize control input text. used code not work. me resolve it?

cfont *m_font1 = new cfont; cstatic * m_label; m_font1->createpointfont(200, "time new roman"); m_label = (cstatic *)getdlgitem(idc_text); m_label->setfont(m_font1); m_label->setwindowtext( _t("") ); //display text in thread threadstruct*    ts = (threadstruct*)param; cdc* vdc_txt; vdc_txt =ts->_this->getdlgitem(idc_text)->getdc(); ts->_this->getdlgitem(idc_text)->setwindowtexta(text.c_str());  //update length-  ts->_this->getdlgitem(idc_text)->setwindowpos(null, 0, 0, 1000, 1000, swp_nomove | swp_noactivate | swp_nozorder); 

however, number (1000,1000) set hand. want auto change based on text size. have me solve it?

update:

if font size same, , text different, should able reuse old font:

void changesize() {     cwnd* dlgitem = getdlgitem(idc_static1);      if (!dlgitem)         return;      cstring s;     dlgitem->getwindowtext(s);      cdc dc;     dc.createcompatibledc(null);     dc.selectobject(dlgitem->getfont());      crect r;     dlgitem->getclientrect(&r);      if (s.find('\n') < 0)         dc.drawtext(s, &r, dt_calcrect | dt_noprefix | dt_singleline | dt_editcontrol);     else         dc.drawtext(s, &r, dt_calcrect | dt_noprefix | dt_editcontrol);      dlgitem->setwindowpos(0, 0, 0, r.width(), r.height(), swp_nomove); } 

previous answer when font changing:

m_font1 should declared member data , setup setup once, , created , cleaned elsewhere. think that's doing.

then can draw text functions find text size, , resize control follows

void changesize() {     cwnd* dlgitem = getdlgitem(idc_static1);      if (!dlgitem)         return;      cstring s;     dlgitem->getwindowtext(s);      cdc dc;     dc.createcompatibledc(null);     //or use cclientdc dc(this) if device context available      dc.selectobject(m_font);      crect r;     dlgitem->getclientrect(&r);      if (s.find('\n') < 0)     {         //change width/height single line text         dc.drawtext(s, &r, dt_calcrect | dt_noprefix | dt_singleline | dt_editcontrol);     }     else     {         //change height multiple-line text         dc.drawtext(s, &r, dt_calcrect | dt_noprefix | dt_editcontrol);     }      dlgitem->setwindowpos(0, 0, 0, r.width(), r.height(), swp_nomove);     dlgitem->setfont(m_font, 1); } 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -