Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
platform
active.directory
adsi
adsi.iis-admin
base
com_ole
complus_mts
component_svcs
database
directx
gdi
graphics_mm
internet.client
internet.server
internet.server.isapi-dev
localization
mapi
messaging
msi
mslayerforunicode
multimedia
networking
networking.ipv6
sdk_install
security
shell
telephony.tapi_2
telephony.tapi_3
telephony.tsp
telephony.wte
tools
ui
ui_shell
win_base_svcs
win16
  
 
date: 4 May 2006 02:41:31 -0700,    group: microsoft.public.platformsdk.com_ole        back       


Events are being handled twice   
Hi all,

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);
	}
}
date: 4 May 2006 02:41:31 -0700   author:   Ehud_A

Re: Events are being handled twice   
"Ehud_A"  wrote in message
news:1146735691.746665.211070@y43g2000cwc.googlegroups.com
> 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.
>
> if (bw != NULL) {
> bw->handleMessage(&msg);
> }
>
> DispatchMessage(&msg);
> }

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
date: Thu, 4 May 2006 07:50:58 -0400   author:   Igor Tandetnik

Re: Events are being handled twice   
Thanks Igor, it worked!
date: 6 May 2006 23:15:31 -0700   author:   Ehud_A

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us