Prev: _AfxGetNextMnem() changes in MFC 8.0
Next: CProgressDlg
From: AliR on 16 Oct 2006 15:27 I am not sure about when m_sizeNatural is set, but I don't think it changes much unless the control changes it's size. Sorry that I can't help much on that. As far as EM_FORMATRANGE goes. here is a very good example project written by Henry Skoglund http://www.tungware.com/RTFScaler3.zip AliR. <matanasescu(a)gmail.com> wrote in message news:1161025315.129339.127550(a)m73g2000cwd.googlegroups.com... > > Hi AliR, > > The container (RichEdit) calls and prepares the DC for > CComControl::OnDraw(). > The boundaries of the rectangle inside which I can drawn are dictated > by CComControl::m_sizeNatural. > I can use CComControl::FireViewChange() to force the container to > repaint the control. > Conclusion: how can I set the correct m_sizeNatural before OnDraw > (which I can force with FireViewChange()) > > I would like to know how to use EM_FORMATRANGE in this scenario. I'm > using RTF. > > > AliR wrote: > > You can get a dc anytime by calling GetDC(). Don't forget to call ReleaseDC > > when you are done with the DC. > > > > void CMyRichEdit::GetTextExtent(CString Text) > > { > > CDC *pDC = GetDC(); > > > > .... > > > > ReleaseDC(pDC); > > } > > > > By the way a better way to get the text boundaries for a rich edit control > > is to use EM_FORMATRANGE. requires a bit more work, but if you are using RTF > > it will be very accurate. > > > > AliR. > > > > <matanasescu(a)gmail.com> wrote in message > > news:1161023169.185547.317680(a)m73g2000cwd.googlegroups.com... > > > Hi Ajay, > > > > > > I need the text extent. I can calculate the text extent only when I > > > receive the DC to draw on. That's in OnDraw. > > > > > > > > > Ajay Kalra wrote: > > > > Change the size of control when its text changes and not in OnDraw. > > > > OnDraw can be called many many times without any changes in the text. > > > > > > > > --- > > > > Ajay > > > > > > > > matanase...(a)gmail.com wrote: > > > > > Hi, > > > > > > > > > > I have an ATL control used to display text. > > > > > The control lives inside a CRichEditControl. > > > > > The problem is that the application needs to resize the control to fit > > > > > the text. > > > > > O solution I adopted is to call FieViewChange() inside of OnDraw, > > after > > > > > > > > > > > > > > > > > > > > I calculate the text extent using DC passed as parameter > > > > > (CDC::GetTextExtent). > > > > > This allows the control to be redrawn inside the boundaries I specify > > > > > in the prev call of OnDraw. > > > > > So: > > > > > > > > > > > > > > > CMyComControl::OnDraw(...) > > > > > { > > > > > .... > > > > > CRect rcTextSize = pDC->GetTextExtent( strText, nChars ); > > > > > > > > > > > > > > > if( m_sizeNatural != rcTextSize ) > > > > > { > > > > > m_sizeNatural = rcTextSize + some margins > > > > > FireViewChange(); //this will alow OnDraw to be called with > > > > > correct margins > > > > > } > > > > > .... > > > > > > > > > > > > > > > > > > > > } > > > > > > > > > > > > > > > However in some specific situations the application crashes. I > > couldn't > > > > > > > > > > > > > > > figure out why, but I discovered that removing FireViewChange() from > > > > > OnDraw solves the crash. > > > > > I believe that calling FireViewChange() inside OnDraw() may be tricky, > > > > > but this was the only way I could find to calculate m_sizeNatural > > > > > function of text extent (DC dependent). > > > > > > > > > > > > > > > Is there any other solutions to my problem? > > > > > Any comments on this are welcomed. > > > > > > > > > > > > > > > Thanks > > > >
From: matanasescu on 16 Oct 2006 15:42 Thanks, I really appreciate any advice. AliR wrote: > I am not sure about when m_sizeNatural is set, but I don't think it changes > much unless the control changes it's size. Sorry that I can't help much on > that. > As far as EM_FORMATRANGE goes. > here is a very good example project written by Henry Skoglund > http://www.tungware.com/RTFScaler3.zip > > AliR. > > > > <matanasescu(a)gmail.com> wrote in message > news:1161025315.129339.127550(a)m73g2000cwd.googlegroups.com... > > > > Hi AliR, > > > > The container (RichEdit) calls and prepares the DC for > > CComControl::OnDraw(). > > The boundaries of the rectangle inside which I can drawn are dictated > > by CComControl::m_sizeNatural. > > I can use CComControl::FireViewChange() to force the container to > > repaint the control. > > Conclusion: how can I set the correct m_sizeNatural before OnDraw > > (which I can force with FireViewChange()) > > > > I would like to know how to use EM_FORMATRANGE in this scenario. I'm > > using RTF. > > > > > > AliR wrote: > > > You can get a dc anytime by calling GetDC(). Don't forget to call > ReleaseDC > > > when you are done with the DC. > > > > > > void CMyRichEdit::GetTextExtent(CString Text) > > > { > > > CDC *pDC = GetDC(); > > > > > > .... > > > > > > ReleaseDC(pDC); > > > } > > > > > > By the way a better way to get the text boundaries for a rich edit > control > > > is to use EM_FORMATRANGE. requires a bit more work, but if you are using > RTF > > > it will be very accurate. > > > > > > AliR. > > > > > > <matanasescu(a)gmail.com> wrote in message > > > news:1161023169.185547.317680(a)m73g2000cwd.googlegroups.com... > > > > Hi Ajay, > > > > > > > > I need the text extent. I can calculate the text extent only when I > > > > receive the DC to draw on. That's in OnDraw. > > > > > > > > > > > > Ajay Kalra wrote: > > > > > Change the size of control when its text changes and not in OnDraw. > > > > > OnDraw can be called many many times without any changes in the > text. > > > > > > > > > > --- > > > > > Ajay > > > > > > > > > > matanase...(a)gmail.com wrote: > > > > > > Hi, > > > > > > > > > > > > I have an ATL control used to display text. > > > > > > The control lives inside a CRichEditControl. > > > > > > The problem is that the application needs to resize the control to > fit > > > > > > the text. > > > > > > O solution I adopted is to call FieViewChange() inside of OnDraw, > > > after > > > > > > > > > > > > > > > > > > > > > > > > I calculate the text extent using DC passed as parameter > > > > > > (CDC::GetTextExtent). > > > > > > This allows the control to be redrawn inside the boundaries I > specify > > > > > > in the prev call of OnDraw. > > > > > > So: > > > > > > > > > > > > > > > > > > CMyComControl::OnDraw(...) > > > > > > { > > > > > > .... > > > > > > CRect rcTextSize = pDC->GetTextExtent( strText, nChars ); > > > > > > > > > > > > > > > > > > if( m_sizeNatural != rcTextSize ) > > > > > > { > > > > > > m_sizeNatural = rcTextSize + some margins > > > > > > FireViewChange(); //this will alow OnDraw to be called > with > > > > > > correct margins > > > > > > } > > > > > > .... > > > > > > > > > > > > > > > > > > > > > > > > } > > > > > > > > > > > > > > > > > > However in some specific situations the application crashes. I > > > couldn't > > > > > > > > > > > > > > > > > > figure out why, but I discovered that removing FireViewChange() > from > > > > > > OnDraw solves the crash. > > > > > > I believe that calling FireViewChange() inside OnDraw() may be > tricky, > > > > > > but this was the only way I could find to calculate m_sizeNatural > > > > > > function of text extent (DC dependent). > > > > > > > > > > > > > > > > > > Is there any other solutions to my problem? > > > > > > Any comments on this are welcomed. > > > > > > > > > > > > > > > > > > Thanks > > > > > >
From: Tony Thomas on 17 Oct 2006 00:23
Why don't you use PostMessage to the parent window telling to redraw..insted of Firing Events, Events have much highre overhead than message posting am I rite..?Since you are Firing the event in a Paint handler..its not good I think.. <matanasescu(a)gmail.com> wrote in message news:1161027734.865501.103850(a)f16g2000cwb.googlegroups.com... > > Thanks, I really appreciate any advice. > > AliR wrote: >> I am not sure about when m_sizeNatural is set, but I don't think it >> changes >> much unless the control changes it's size. Sorry that I can't help much >> on >> that. >> As far as EM_FORMATRANGE goes. >> here is a very good example project written by Henry Skoglund >> http://www.tungware.com/RTFScaler3.zip >> >> AliR. >> >> >> >> <matanasescu(a)gmail.com> wrote in message >> news:1161025315.129339.127550(a)m73g2000cwd.googlegroups.com... >> > >> > Hi AliR, >> > >> > The container (RichEdit) calls and prepares the DC for >> > CComControl::OnDraw(). >> > The boundaries of the rectangle inside which I can drawn are dictated >> > by CComControl::m_sizeNatural. >> > I can use CComControl::FireViewChange() to force the container to >> > repaint the control. >> > Conclusion: how can I set the correct m_sizeNatural before OnDraw >> > (which I can force with FireViewChange()) >> > >> > I would like to know how to use EM_FORMATRANGE in this scenario. I'm >> > using RTF. >> > >> > >> > AliR wrote: >> > > You can get a dc anytime by calling GetDC(). Don't forget to call >> ReleaseDC >> > > when you are done with the DC. >> > > >> > > void CMyRichEdit::GetTextExtent(CString Text) >> > > { >> > > CDC *pDC = GetDC(); >> > > >> > > .... >> > > >> > > ReleaseDC(pDC); >> > > } >> > > >> > > By the way a better way to get the text boundaries for a rich edit >> control >> > > is to use EM_FORMATRANGE. requires a bit more work, but if you are >> > > using >> RTF >> > > it will be very accurate. >> > > >> > > AliR. >> > > >> > > <matanasescu(a)gmail.com> wrote in message >> > > news:1161023169.185547.317680(a)m73g2000cwd.googlegroups.com... >> > > > Hi Ajay, >> > > > >> > > > I need the text extent. I can calculate the text extent only when I >> > > > receive the DC to draw on. That's in OnDraw. >> > > > >> > > > >> > > > Ajay Kalra wrote: >> > > > > Change the size of control when its text changes and not in >> > > > > OnDraw. >> > > > > OnDraw can be called many many times without any changes in the >> text. >> > > > > >> > > > > --- >> > > > > Ajay >> > > > > >> > > > > matanase...(a)gmail.com wrote: >> > > > > > Hi, >> > > > > > >> > > > > > I have an ATL control used to display text. >> > > > > > The control lives inside a CRichEditControl. >> > > > > > The problem is that the application needs to resize the control >> > > > > > to >> fit >> > > > > > the text. >> > > > > > O solution I adopted is to call FieViewChange() inside of >> > > > > > OnDraw, >> > > after >> > > > > > >> > > > > > >> > > > > > >> > > > > > I calculate the text extent using DC passed as parameter >> > > > > > (CDC::GetTextExtent). >> > > > > > This allows the control to be redrawn inside the boundaries I >> specify >> > > > > > in the prev call of OnDraw. >> > > > > > So: >> > > > > > >> > > > > > >> > > > > > CMyComControl::OnDraw(...) >> > > > > > { >> > > > > > .... >> > > > > > CRect rcTextSize = pDC->GetTextExtent( strText, >> > > > > > nChars ); >> > > > > > >> > > > > > >> > > > > > if( m_sizeNatural != rcTextSize ) >> > > > > > { >> > > > > > m_sizeNatural = rcTextSize + some margins >> > > > > > FireViewChange(); //this will alow OnDraw to be >> > > > > > called >> with >> > > > > > correct margins >> > > > > > } >> > > > > > .... >> > > > > > >> > > > > > >> > > > > > >> > > > > > } >> > > > > > >> > > > > > >> > > > > > However in some specific situations the application crashes. I >> > > couldn't >> > > > > > >> > > > > > >> > > > > > figure out why, but I discovered that removing FireViewChange() >> from >> > > > > > OnDraw solves the crash. >> > > > > > I believe that calling FireViewChange() inside OnDraw() may be >> tricky, >> > > > > > but this was the only way I could find to calculate >> > > > > > m_sizeNatural >> > > > > > function of text extent (DC dependent). >> > > > > > >> > > > > > >> > > > > > Is there any other solutions to my problem? >> > > > > > Any comments on this are welcomed. >> > > > > > >> > > > > > >> > > > > > Thanks >> > > > >> > > |