Quantcast
Channel: Internet Explorer Web Development forum
Viewing all articles
Browse latest Browse all 3527

WM_CLOSE message not coming to ActiveX with IE 10

$
0
0

Hi,

In one of my applications, I am running an ActiveX control within IE.
The ActiveX sets a hook for trapping Windows Messages for that IE instance.

Following APIs are used in the ActiveX control during initialization:

HHOOK hKeyboardHook = ::SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC) KeyboardProc, NULL, ::GetCurrentThreadId() ); // To disable Alt+F4 close of IE
HHOOK hMsgHook = ::SetWindowsHookEx(WH_GETMESSAGE, (HOOKPROC) MessageProc, NULL, ::GetCurrentThreadId() ); // To hook in to Windows Messages

In the Windows Message Hook handle code the ActiveX is filtering for WM_CLOSE message and then forwarding that to java script (the initializer of ActiveX). Following API is used to do that.

::SendMessage(hWnd, WINMGRCTL_CLOSEWINDOW_MESSAGE, (WPARAM) WINMGRCTL_CLOSEWINDOW_ACTION_GENERIC, MAKELPARAM(0,0));

Upon getting that message the java script pops up a message box to IE user for confirming the close window action.
If the user chooses 'Yes' then java scrips calls another method of ActiveX requesting to terminate the IE instance.
If the user chooses 'No' then just the confirmation message box gets dissapear.

This solution was working fine with IE 6, IE 7 and IE 8.
When we moved to IE 9, the behaviour was different. With IE 9, the main IE Window was getting dissapear the moment ActiveX was getting WM_CLOSE on user action. And after that only the confirmation message box from java script was visible.
The issue with IE 9 got fixed with following KB article:

2587178 - Add-ons that intercept the WM_CLOSE message may fail in Internet Explorer 9 (http://support.microsoft.com/kb/2587178/EN-US)

As explained in the above KB, we added following code in the java script and after that the IE window was not getting dissapear with WM_CLOSE message hooking by ActiveX.

function myHandler() {
 // do nothing
}
window.onbeforeunload = myHandler;


Now, we are testing our ActiveX with IE 10 and if in the javascript window.onbeforeunload is not registered, then the behaviour is same as of IE 9.
After adding window.onbeforeunload handler, things are working but with a new behaviour.

With IE 10 and window.onbeforeunload handler registered in java script, the ActiveX is getting WM_CLOSE message when user is tring to close IE window for the first time. At this moment ActiveX is forwarding this to java script as explained above and then java script is poping the confirmation message box. The user selects 'No' here and the confirmation message box gets dissapear as expected. Everything is fine till here. The issue is that now if user tries to close IE once again i.e. second time, the ActiveX is not getting WM_CLOSE message again and hence nothing happens. The only way to close IE now is to kill it from task manager.

This new issue explained for IE 10 above is not happening on any earlier IE versions i.e. IE 6, 7, 8 & 9.

Additional information:

Our ActiveX is 32-bit and we are running IE 10 in 32 bit mode by setting HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main --> TabProcGrowth to 1.

For earlier IE versions we are running 32 bit IE version directly.

This introduces one more new behaviour with IE 10.

When our application starts within IE, we can see two IE processes in task manager. One is 64 bit IE and another is 32 bit IE. Our ActiveX is loaded within 32 bit IE process.

When the user gets confirmation message box on WM_CLOSE message and selects 'Yes', the ActiveX kills the IE by calling exit(0). This just kills 32 bit IE. The 64 bit IE is still present in task manager.

OS used is Windows 7 SP 1.

Any help on this would be greatly appreciated.

Thanks,
Rajeev


Viewing all articles
Browse latest Browse all 3527

Trending Articles