I developed a webbrowser based on the webbrowser activeX control. When
I noticed that it doesn't respond to keys like tab,delete and others, i
googled a bit and found that when adding the code below to the WinMain
message handle loop it works.
The important class is named BrowserWindow and it holds pointers to
IWebBrowser2 interface and a CAxWindow object.
My question:
is it necessary to do in every round of the loop the queryInterface(),
release() stuff to get the objects i need, including the
IOleInPlaceActiveObject pointer?
Can't they be saved as a class member?
In every example i saw they are queried each time, i don't understand
why.
thanks for your help
========================================
this code is taken from the WinMain()
MSG msg ;
while(GetMessage(&msg, NULL , NULL, NULL) != 0) {
TranslateMessage(&msg);
LPDISPATCH lpDispatch = NULL;
HWND parent = msg.hwnd ;
// climb up until you find the top parent
while(GetParent(parent)){
parent = GetParent(parent) ;
}
// get the BrowserWindow that is saved in a map with its handle
BrowserWindow* bw = BrowserWindow::getByHwnd(parent);
if (bw != NULL) {
lpDispatch = bw->GetDoc();
if (lpDispatch!=NULL){
IOleInPlaceActiveObject* pIOIPAO = NULL;
lpDispatch->QueryInterface(IID_IOleInPlaceActiveObject,
(void**)&pIOIPAO);
lpDispatch->Release();
if (pIOIPAO!= NULL) {
pIOIPAO->TranslateAccelerator(&msg);
pIOIPAO->Release();
}
}
}
DispatchMessage(&msg);
}
....
====================================
IHTMLDocument2* BrowserWindow::GetDoc(){
IDispatch *dispatch;
HRESULT hr = spBrowser->get_Document(&dispatch);
if (!SUCCEEDED(hr) || dispatch==NULL) {
return NULL;
}
IHTMLDocument2 *doc;
dispatch->QueryInterface(IID_IHTMLDocument2,(void**)&doc);
dispatch->Release();
return doc;
}
====================================
No, you can get the pointer once and cache it.
> Can't they be saved as a class member?
They can.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925