Saturday, January 29, 2005

MSHTML Hosting - More Editing

Previously I talked about exposing the HTML editor hiding inside the WebBrowser control. I also talked about IOleCommandTarget and how you can control formatting and layout features of the editor. It won't take long before you discover that the IOleCommandTarget command ID's are somewhat limited. At some point, you will need to insert specialized text or HTML at the current cursor location or replacing the current selection. Luckily for us, there is an easy way to do it: IHTMLTxtRange.

I talked about IHTMLTxtRange in a previous post. It is useful for finding text or getting the text of the current selection. It can also do the reverse: It can insert text or HTML at the current cursor location or selection using the pasteHTML method. Here's a simple example:


IHTMLDocument2* pDoc = ...;

IHTMLSelectionObject* pSelection = 0;
HRESULT hr = pDoc->get_selection(&pSelection);
if (SUCCEEDED(hr)) {
   IDispatch* pDispRange = 0;
   hr = pSelection->createRange(&pDispRange);
   if (SUCCEEDED(hr)) {
      IHTMLTxtRange* pTextRange = 0;
      hr = pDispRange->QueryInterface(IID_IHTMLTxtRange, (void**)&pTextRange);
      if (SUCCEEDED(hr)) {
         CComBSTR sText = L"This is <b>better</b> text";
         pTextRange->get_pasteHTML(sText);
         pTextRange->Release();
      }
      pDispRange->Release();
   }
   pSelection->Release();
}

pDoc->Release();

In the above example, the selection may have selected text or it may just be a cursor location. The HTML overwrites any selected text. Otherwise, it's inserted at the cursor location.

Overall, IHTMLTxtRange is a very useful interface. I have used it for implementing spell check, find/replace and inserting complex HTML. Just to be clear, IHTMLTxtRange works when design mode is off or on. The WebBrowser control does not need to be in edit mode to call pasteHTML.

22 Comments:

At 4:56 AM, Anonymous Anonymous said...

Great blog article!

I followed your coding but when I do this:

CComQIPtr#IHTMLBodyElement> spBody = spBodyEl;

if (spBody)
{
CComPtr#IHTMLTxtRange> spRange;
spBody->createTextRange(&spRange);

if (spRange)
{
###spRange->moveToPoint(ptDoc.x, ptDoc.y);

...my code crashes at the ### indicated above. However, it only does this in IE7, not in IE6 or any previous IE versions.

So, I'm wondering if there any strange changes in IE7 that could cause a crash on spRange pointer or the moveToPoint call...?

Ok to mail me at tommy(attt)infografix.nu!

Any idea?

/Tommy

 
At 2:43 AM, Blogger Adi said...

Oes Tsetnoc one of the ways in which we can learn seo besides Mengembalikan Jati Diri Bangsa. By participating in the Oes Tsetnoc or Mengembalikan Jati Diri Bangsa we can improve our seo skills. To find more information about Oest Tsetnoc please visit my Oes Tsetnoc pages. And to find more information about Mengembalikan Jati Diri Bangsa please visit my Mengembalikan Jati Diri Bangsa pages. Thank you So much.

 
At 6:36 AM, Anonymous professional writing service said...

Its nice to see such work.

 
At 6:58 AM, Blogger polo shirts said...

History of polo ralph lauren. Polo fashions had its humble beginnings in 1968 when tie salesman Ralph Lauren gave it a kick start. By 1969 he had a boutique polo ralph lauren factory stores within the Manhattan department store Bloomingdale's. ... Brands and luxury standard. Since Ralph Lauren's first brand, Polo Ralph Lauren, was launched, the company has expanded to include a variety of luxury brands such as Polo Golf, Polo Denim, Polo Sport. You can buy cheap Ralph Lauren Clothing at Ralph Lauren outlet.Also We provide polo shirts
Ralph Lauren polo shirt, 50% OFF! polo ralph lauren outlet online is your best choice!In 2006, polo ralph lauren outlet became the first designer in Wimbledon's 133-year history to create official uniforms for the tournament. As part of this year's event, which starts next week, polo ralph lauren sale will introduces the first ... determination to maintain and enhance the values for which our two brands are famous throughout the world. The rugby ralph lauren brand brings to Wimbledon the look of timeless elegance, drawing on our rich history and traditions

 
At 10:11 AM, Anonymous Custom Essays said...

This is a great article and a source for my custom essays. Thank you for sharing and keep it up!

 
At 10:28 PM, Blogger 一笑千年 said...

In reality, almost almost all colors enables you vbnfuyt to brush or perhaps tint prescribed oakley frogskins . Generally, cheap Oakley sunglasses virtual test can become fallen directly into several sorts and different online vendors could have their distinct ones. oakley frogskins can be abbreviated directly into "try-on" or perhaps "virtual try-on". In any manner, one can easily open this kind of item when he desires to choose his / her beloved low-cost oakley jawbone . Another extremely professional low-cost Oakley sunglasses virtual test is founded on the info of peoples' faces and also heads. Such test oakley flak jacket will be professional and also complicated, yet very correct. Some blanks concerning people's face can be filled, like the length, size, height with the face, brow, and a great many other oakley radar

 
At 2:42 AM, Blogger bestzyh said...

As it can certainly always be reported folks stars zjfgksy benefit from getting into oakley frogskins in the personalized variations. Along with these kinds of patterns are generally individual for the children. As a result, while the idea happens to the part of fans, these kind of oakley frogskins are set up approximately related to the patterns ones. while correctly as being a happening comes about, that is, your fans in the accurate Oakley place on Oakley sunglasses of these accurate variations. In addition, these are on the way to almost never change his or her style throughout getting into oakley jawbone .Your younger looking girls-oriented Oakley sunglasses, by way of example, are generally actually common. These kind of sun glasses could be the effects involving reduction regular along with cool issues jointly. specifically can be additional, your charges involving oakley flak jacket may be affordable. This has confirmed that will plenty of buyers will probably pay for the children. And thus, oakley radar can invest in just about any shade as well as any kind Oakley sunglasses whenever they similar to. Your component can be the belief that fans will certainly adhere to your patterns in the idols, of course getting into Oakley sunglasses.Normally, duplicate Oakley sunglasses may be affordable.

 
At 4:05 AM, Blogger bestzyh said...

Though these kind of oakley frogskins may be fabricated along with uijgfnhm classy, these are cheap. this specific actually is primarily since nearly all while using users involving Oakley sunglasses, your enormous men and women, are not able to spend on deluxe solutions. most of the charges involving oakley frogskins presented from the market are generally underneath one hundred bucks. Your temple involving oakley jawbone can be wide-ranging along with comprehensive involving creative imagination.Zero matter your fine rounded radian or maybe your oblong composition, your temple involving oakley flak jacket can be delicate. The idea not simply calls for your seen elegance into mind, but in addition can be warm for you to don. moreover for you to these kind of, your permanent fixture involving chemical along with shade can be fair. Right now, you may can understand the contact lenses involving individual's oakley radar come to be even bigger along with more substantial. buyers whom place on some Oakley sunglasses using enormous contact lenses declare who's may screen his or her good individuality.

 
At 12:30 AM, Blogger 一笑千年 said...

I need to think fsdjhjhl of a two of oakley frogskins .After an extensive time operating under the sun, I feel rather uncomfortable, and I can have a couple oakley frogskins to support me protect my little brown eyes. I've lived with bad eyesight for virtually every lengthy time period, I need to think of a two of oakley jawbone to support me view items obviously and guard the eye by powerful sun light and extra violet radiations. Subsequently, I want to purchase a couple oakley flak jacket at on-line spectacles shop to be a end reaction to their higher high class and tolerable prices.Make a gross sales pitch and train your people today to consequence your shoppers to obtain your oakley radar . in scenario you could have perfect sales guys and saleswomen, it may improve ones margins. with comparability to help clothes, Oakley sunglasses tend to be attempted oneasily with not significantly more than something like 20 seconds. with scenario people exhibit most of these in check-out companies, your people can sporting them whilst delaying with regard to their change and own it within their buy which shows extra profit.

 
At 2:25 AM, Blogger 一笑千年 said...

They may be Oakley Sunglasses Discount trjgfhpo promoting creating a much more clear perspective. In fact, Cheap Oakley Sunglasses is normally an assortment of Oakley sunglasses and also Oakleys, plus the Oakley sunglasses, which is often quick to the significant classification sun shades, express to supply best quality and also a added brilliant world for your wearers.If you'd prefer normal Oakley Frogskins sporting activities, then you definately should certainly examine acquiring a couple of Oakley Jawbone . These kinds of performer sun shades are usually especially designed for extreme normal water ailments. The particular executive guiding the particular style and design from your Oakley Jawbone Sunglasses is approximately permitting you to notice greater while using the copyrighted Trend 500 and also 500 sun shades. It won't need to value an individual a great provide and also a lower leg to have Oakley sunglasses. when you retailer with a certified on the net supplier, you may receive the least expensive price tag Oakley sunglasses.Once we relate for your significant classification, practically almost every person can feel from your Oakley television set which is often intended to offer you significant decision photo while using the electronic digital sign approach stuck.

 
At 8:57 PM, Blogger 一笑千年 said...

Oakley Sunglasses Discount is visual compromise and the other hfkjtylt is eye protection. In fact, bifocal safety glass is neither a sole nor a strange member in the large family of eyewear products. Prescription Cheap Oakley Sunglasses and prescription goggles are both special types of eyewear that come in a similar design principle.They are designed to shield your eyes from the ultra violet rays of the sun and make it more comfortable for you to see when you're outside. Why do some people want to wear them indoors or at night? In fact, there is no need in wearing them. Maybe they think wearing cool Oakley Frogskins can make them cooler. Other occasions like a social gathering or setting, it is also not suitable to wear Oakley sunglasses. People at the parties will presumably have conversations with others they are interested in.Children will think those Oakley Jawbone are good and can make them more attractive. Of course, now the Oakley sunglasses for children vary a lot in styles that can fit any demand and interest. The Oakley Jawbone Sunglasses of some film characters are also very popular among children. Those Oakley sunglasses are a little expensive than ordinary Oakley sunglasses. Parents should thus let their children do their own choices on what to buy. As sometimes, children will be unsatisfied with the patents' choices. What parents should do only is to consider whether those Oakley sunglasses are durable, comfortable, suitable, etc.It is difficult to approach a new person and say hello to them when someone is wearing dark, cool Oakley sunglasses.

 
At 8:22 PM, Anonymous Proyectores Baratos said...

'm wondering if there any strange changes in IE7 that could cause a crash on spRange pointer or the moveToPoint call

 
At 8:22 PM, Anonymous como hacer crecer el cabello said...

Generally, cheap Oakley sunglasses virtual test can become fallen directly into several sorts and different online vendors could have their distinct ones

 
At 2:29 AM, Anonymous Anonymous said...

this is very interesting, I will consider
and thank you for sharing...
Como enamorar a una amiga
dieta de la manzana |

 
At 3:04 PM, Blogger cludia said...

Those Oakley sunglasses are a little expensive than ordinary Oakley sunglasses. Parents should thus let their children do their own choices on what to buy. As sometimes, children will be unsatisfied with the patents' choices. What parents should do only is to consider whether those Oakley sunglasses are durable, comfortable, suitable

armarios baratos|
Trabajos manuales desde casa

 
At 10:49 PM, Blogger paula said...

Parents should thus let their children do their own choices on what to buy. As sometimes, children will be unsatisfied with the patents' choices. What parents should do only is to consider whether those Oakley sunglasses are durable, comfortable, suitable, etc. creditos economicos|
Dietas Rapidas y Efectivas |

 
At 10:34 PM, Blogger paula said...

Generally, cheap Oakley sunglasses virtual test can become fallen directly into several sorts and different online vendors could have their distinct ones. trabajar desde mi casa |
encuestas remuneradas |

 
At 1:24 AM, Blogger nicole said...

before you discover that the IOleCommandTarget command ID's are somewhat limited. At some point, you will need to insert specialized text or HTML at the current cursor location or replacing t

preuniversitarios en Santiago centro

 
At 3:24 AM, Anonymous cheap uggs australia said...

Discount UGG Boots That poor children do, but not necessarily, to taste good, be sure to what to what, but the mother has actually engaged with others, even food and clothing also must worry about the embarrassment.

cheap uggs australia The room itself is another one scene, hung on the ceiling of the aircraft model, the ground is a model train track, a large table is more than a dozen twenty armored Toys, all are placed neatly. yt66dyg

ugg kenly black The chef asked: "You learn to turn eyeball it?"

cheap uggs for men Freehand said suddenly lost her wallet, but also all the back to find, long while, to remember is to throw in the car forgot to bring out.

www.uggsaustralia.me.uk Carrying a suitcase, wandering from one place to another, is always less a permanent address.

 
At 9:46 PM, Blogger qinbincai123 said...

Someone who convinces you that there haoxiod81 really is an unlocked door just waiting for you to open it.
Cheap Snapback Hats
Snapback Hats Wholesale
Cheap New Era Hats
Wholesale Hats
New Era Fitted Hats
Cheap MLB Hats
Cheap NBA Hats
monster energy hats
Red Bull Hats
Superman Hats

 
At 4:39 PM, Anonymous pay per head said...

Wow great post very informative, all i can add is if you would like to read more on the subject, you should visit google and find relevent sources! hope it is helpful

 
At 6:27 AM, Blogger Anna Bennet said...

Your post will help me to solve my problem with coding. Many many thanks!
writing services

 

Post a Comment

<< Home