Wallentin
07-09-2005, 11:11 PM
Hi!
I am not sure if this is the right place to post "hardcore" IE developer
questions? If not could somebody point me in the right direction?
I have discovered that a IHTMLTxtRange obtained from a IHTMLTextAreaElement
does not work with other IHTMLTxtRanges.
For example when I use compareEndPoints on a range obtained from a
IHTMLSelectionObject and a range obtained from a IHTMLTextAreaElement I get a
E_INVALIDARG COM Error
My problem is I need to know where the caret is situated inside the TextArea
and to my knowledge the only way of knowing this is to retrieve the selection
and this introduces an “incompatiple” txtrange!? All other ranges work fine
with eachother – even InputText which is a lot like a TextArea.
In the code below only the range resulting from a TextArea will fail with a
E_INVALIDARG error.
Have any of you come across this problem? Is it a bug?
Any comments are more than welcome.
Thanks in advance ...
/W
//Creating the caret IHTMLTextRange
MSHTML::IHTMLSelectionObjectPtr selection = m_document->Getselection();
MSHTML::IHTMLTxtRangePtr caretRange = selection->createRange();
caretRange ->collapse(VARIANT_FALSE);
//Creating the text IHTMLTextRange
MSHTML::IHTMLTxtRangePtr txtRange = 0;
MSHTML::IHTMLElementPtr active = m_document->GetactiveElement();
if (active) {
MSHTML::IHTMLInputTextElementPtr input = active;
if (input) {
txtRange = input->createTextRange();
}
else {
MSHTML::IHTMLTextAreaElementPtr area = active;
if (area) {
txtRange = area->createTextRange();
}
}
}
if (txtRange==0) {
MSHTML::IHTMLBodyElementPtr body = m_document->Getbody();
if (body) {
txtRange = body->createTextRange();
}
}
try {
_bstr_t compareHow ("StartToStart");
long compare = txtRange->compareEndPoints(compareHow, caretRange);
}
catch(_com_error& err) {
…
}
I am not sure if this is the right place to post "hardcore" IE developer
questions? If not could somebody point me in the right direction?
I have discovered that a IHTMLTxtRange obtained from a IHTMLTextAreaElement
does not work with other IHTMLTxtRanges.
For example when I use compareEndPoints on a range obtained from a
IHTMLSelectionObject and a range obtained from a IHTMLTextAreaElement I get a
E_INVALIDARG COM Error
My problem is I need to know where the caret is situated inside the TextArea
and to my knowledge the only way of knowing this is to retrieve the selection
and this introduces an “incompatiple” txtrange!? All other ranges work fine
with eachother – even InputText which is a lot like a TextArea.
In the code below only the range resulting from a TextArea will fail with a
E_INVALIDARG error.
Have any of you come across this problem? Is it a bug?
Any comments are more than welcome.
Thanks in advance ...
/W
//Creating the caret IHTMLTextRange
MSHTML::IHTMLSelectionObjectPtr selection = m_document->Getselection();
MSHTML::IHTMLTxtRangePtr caretRange = selection->createRange();
caretRange ->collapse(VARIANT_FALSE);
//Creating the text IHTMLTextRange
MSHTML::IHTMLTxtRangePtr txtRange = 0;
MSHTML::IHTMLElementPtr active = m_document->GetactiveElement();
if (active) {
MSHTML::IHTMLInputTextElementPtr input = active;
if (input) {
txtRange = input->createTextRange();
}
else {
MSHTML::IHTMLTextAreaElementPtr area = active;
if (area) {
txtRange = area->createTextRange();
}
}
}
if (txtRange==0) {
MSHTML::IHTMLBodyElementPtr body = m_document->Getbody();
if (body) {
txtRange = body->createTextRange();
}
}
try {
_bstr_t compareHow ("StartToStart");
long compare = txtRange->compareEndPoints(compareHow, caretRange);
}
catch(_com_error& err) {
…
}