I posted a thread here about this issue and got a helpful response, so
I believe you could help me again.
the original post was this:
http://groups.google.com/group/microsoft.public.platformsdk.com_ole/browse_thread/thread/ba6e92731e53b992
In my current implementation I am caching some object like
IHTMLDocument2*, IOleInPlaceActiveObject* pointers instead of using
queryInterface(), release() every time I need to use them.
I am delivering every window message to be handled by ny webbrowser
My problem:
Some events are being handled twice: when a user clicks the delete
button focused on a text box, two characters are deleted. When he
presses left/right arrow on a text box, he skips two characters instead
of one, etc.
thanks
this is the code:
//////////////////////////////////////
from WinMain():
.....
MSG msg ;
while(GetMessage(&msg, NULL , NULL, NULL) != 0) {
TranslateMessage(&msg);
HWND parent = msg.hwnd ;
// search up until the top is reached
while(GetParent(parent)){
parent = GetParent(parent) ;
}
// All the browser windows are held in a map, the key is the HWND
BrowserWindow* bw = BrowserWindow::getByHwnd(parent);
if (bw != NULL) {
bw->handleMessage(&msg);
}
DispatchMessage(&msg);
}
....
//////////////////////////////////////
void BrowserWindow::handleMessage(MSG* msg) {
InitDoc();// document may not exist when the message arrives
if (doc!=NULL){
initIOIPAO();
if (pIOIPAO!= NULL) {// pIOIPAO is a cached IOleInPlaceActiveObject*
HRESULT hr = pIOIPAO->TranslateAccelerator(msg);
}
}
}
//////////////////////////////////////////////////////////////////////
/*
cache the html document.
*/
IHTMLDocument2* BrowserWindow::InitDoc(){
if (this->doc==NULL){
HRESULT hr = spBrowser->get_Document(&dispatch);// dispatch is an
IDispatch*
if (!SUCCEEDED(hr) || dispatch==NULL) {
return NULL;
}
dispatch->QueryInterface(IID_IHTMLDocument2,(void**)&(this->doc));
dispatch->Release();
}
return this->doc;
}
//////////////////////////////////////////////////////////////////////
/*
cache the IOleInPlaceActiveObject.
*/
void BrowserWindow::initIOIPAO() {
InitDoc();// doc may not be initialized yet
if (doc!=NULL){
doc->QueryInterface(IID_IOleInPlaceActiveObject,
(void**)&pIOIPAO);
}
}
You are forwarding messages to the browser twice - once with
TranslateAccelerator and again with regular DispatchMessage. If
TranslateAccelerator returns S_OK, do not dispatch the message.
--
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