Dealing with IVsTextView
Some tips regarding the use of IVsTextView:
-
If you hook IVsTextManager::OnRegisterView() to act on all TextViews in the environment, your hook function will be called before the actual window is created. This means that calling GetWindowHandle() on the view will always return 0.
-
A very useful VS-specific hook that IVsTextView provides are its OLE command filters. You can add one with AddCommandFilter(), and later remove it with the corresponding RemoveCommandFilter() function.
-
Hint hint... if you want to actually subclass the window from OnRegisterView(), you cannot do it directly (as the HWND is not available), but you can add a command filter that will try to hook the window later (say: when you receive the first OLE command Exec() call). GetWindowHandle() is bound to return something valid not very far in the future.