Board index » Visual Studio » CRichEditCtrl and CRichEditView and Scrolling

CRichEditCtrl and CRichEditView and Scrolling

Visual Studio192
Hi,



From There is a method from CRichEditView call GetRichEditCtrl, which gets

the rich edit ctrl associated with the view. How can you from the

CRichEditCtrl get the view associated with it? I assume there is one.



The reason i ask, is I have a CRichEditCtrl but and I select text in it

using SetSel. What i want is for the control to scroll to the position of

the selected text automatically. I cant seem to find any information on this,

so if any one knows this would be helpful too.



Many thanks



Will


-
 

Re:CRichEditCtrl and CRichEditView and Scrolling

If you really need the view you can always get the RichEditCtrl's parent.

But make sure that you check the returned pointer's type against the view,

to make sure you have the correct pointer. (Don't know what it could be used

for so I am not able to give you more detailed answer on this).



As far as scrolling the selected test into view here is a sample code



void CEditView::SelectAndScroll(int Start,int End)

{

CRichEditCtrl *pEdit = GetRichEditCtrl();

ASSERT(pEdit);



pEdit->SetSel(Start,End);

int ScrollCount = pEdit->LineFromChar(Start) -

pEdit->GetFirstVisibleLine();

pEdit->LineScroll(ScrollCount);

}



AliR.





"wdhough" <wdhough@discussions.microsoft.com>wrote in message

Quote
Hi,



From There is a method from CRichEditView call GetRichEditCtrl, which gets

the rich edit ctrl associated with the view. How can you from the

CRichEditCtrl get the view associated with it? I assume there is one.



The reason i ask, is I have a CRichEditCtrl but and I select text in it

using SetSel. What i want is for the control to scroll to the position of

the selected text automatically. I cant seem to find any information on

this,

so if any one knows this would be helpful too.



Many thanks



Will





-

Re:CRichEditCtrl and CRichEditView and Scrolling

"wdhough" <wdhough@discussions.microsoft.com>wrote in message

Quote
Hi,



From There is a method from CRichEditView call GetRichEditCtrl, which gets

the rich edit ctrl associated with the view. How can you from the

CRichEditCtrl get the view associated with it? I assume there is one.





Silly, but...



template < typename T>

inline T* CtrlViewFromViewClassCtrl(IN CONST CWnd& rCtrl)

{

T* pRet = NULL;

if (rCtrl.IsKindOf(RUNTIME_CLASS(T)))

pRet = reinterpret_cast<T*>(const_cast<CWnd*>(&rCtrl));

return pRet;

}





...and...



CRichEditView* p =

CtrlViewFromViewClassCtrl<CRichEditView>(GetRichEditCtrl());



--

Jeff Partch [VC++ MVP]





-