IE7 and issue with TrackPopupMenu(Win32) within ActiveX-control

Hello.

I have a trouble with calling win32-function TrackPopupMenu from ActiveX in new Interner Explorer 7 (RC1 and all betas).

The situation is:

I have some ActiveX-control - "MyPopupMenu". This control is being used to show context popup menu. To do it, it used win32 function from winuser.h. There's an issue with one of them - TrackPopupMenu.

Control has worked fine in IE6, but in IE7 it doesn't.

When TrackPopupMenu is called in non-dialog window, nothing happens! There's no popup menu (it was constructed by calling CreatePopupMenu and InsertMenuItem previously). But popup menu still works fine in dialog windows (ones that created in script by window.showModalDialog).

Can anybody help me THX.




Answer this question

IE7 and issue with TrackPopupMenu(Win32) within ActiveX-control

  • ProjectDev

    Yes, this is the exact behaviour that we are experiencing. We too have disappearing dialogs without any pattern to when it happens. It's time for Microsoft to address this issue, isn't it


  • Adam Miles

    We are seeing the same problem with Modal dialogs. They appear behind the IE window. They also are not modal now since the user can do anyting on the IE page w/o closing the modal dialog. We've gone into our code and added some simple message boxes just before we popup the modal dialog and even the message boxes appear behind the IE window. Even more perplexing is the fact that sometimes (but not consistenly and we see no pattern), the first message box appear for an instant on the page and is closed without any user interaction and then the second message box appears (behind the IE page).
  • Jkumar

    Actually, there is one possibility for those failure we experienced.

    Look at this blog, http://blogs.msdn.com/ie/archive/2006/02/09/528963.aspx. There is new protected model to ActiveX in IE7.

    I doubt if those new protected models screw up previous workflow as IE6, as currently Microsoft is very sensitive to activex inside IE. The reason is that an activex component could access full resource dll within IE process space. This is very risky to user. If your application happened to be the same category, please read the article.

    For IE developer, any idea


  • leclerc9

    Hi, Dave.

    I compose simple ActiveX control (TestPopUpMenu) with one method (Test). I create popup menu (CreatePopupMenu), append one item (InsertMenuItem) and show menu (TrackPopupMenu):

    TestPopUpMenu.h:

    #include <atlbase.h>
    #include <atlcom.h>
    #include <atlwin.h>
    #include <atltypes.h>
    #include <atlctl.h>
    #include <atlhost.h>
    
    [object, dual,library_block, uuid(2C567042-F256-43fe-928B-44429666071F), pointer_default(unique)]
    __interface ITestPopUpMenu : public IDispatch
    {
     [id(1)]
     HRESULT Test();
    };
    
    [coclass, threading("apartment"), uuid("5D303927-4DED-454B-828B-389A87DE4B7E"), 
     vi_progid("TestPopUpMenu"), progid("TestPopUpMenu.1"), version(1.0)
    ]
    class ATL_NO_VTABLE CTestPopUpMenu :
     public IDispatchImpl<ITestPopUpMenu, &__uuidof(ITestPopUpMenu)>,
     public IOleControlImpl<CTestPopUpMenu>,
     public IOleObjectImpl<CTestPopUpMenu>,
     public IOleInPlaceObjectWindowlessImpl<CTestPopUpMenu>,
     public CComControl<CTestPopUpMenu>,
     // Make control safe for scripting
     public IObjectSafetyImpl<CTestPopUpMenu, INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACESAFE_FOR_UNTRUSTED_DATA>
    {
    protected:
     void _Test();
    
    public:
     STDMETHOD(Test)()
     {
     _Test();
     return S_OK;
     }
    };
    
    [ module(type= "dll", name = "TestPopUpMenu", uuid = "{42CABCAA-B15D-4ccc-BB9A-EBFAAA584BFA}", version = "1.0") ];
    

    TestPopUpMenu.cpp:
    #include "TestPopUpMenu.h"
    
    #include <winuser.h>
    
    void CTestPopUpMenu::_Test()
    {
     HMENU hMenu;
    
     hMenu = CreatePopupMenu();
     if (NULL == hMenu)
     throw L"Can't create popup menu";
    
     BSTR bstrItem;
     bstrItem = SysAllocString(L"Test");
     CW2A strItem(bstrItem);
    
     MENUITEMINFO mii = {0};
     mii.cbSize = sizeof(MENUITEMINFO);
     mii.fMask = MIIM_TYPE | MIIM_ID | MIIM_STATE;
     mii.fType = MFT_STRING;
     mii.fState = MFS_ENABLED;
     mii.wID = 101;
     mii.dwTypeData = (LPSTR)strItem;
    
     if(FALSE == InsertMenuItem(hMenu, 0, TRUE, &mii))
     throw L"Can't insert menu item";
    
     HWND hWnd = ::GetForegroundWindow();
    
     short nX;
     short nY;
     POINT pnt;
     GetCursorPos( &pnt);
     nX = (short) pnt.x;  
     nY = (short) pnt.y;
    
     UINT nID = TrackPopupMenu(
     hMenu, 
     TPM_LEFTALIGN | TPM_TOPALIGN | TPM_NONOTIFY | TPM_RETURNCMD | TPM_RIGHTBUTTON, 
     nX, nY, 0, hWnd, NULL);
    }
    


    Then I create test HTML-page:
    <html>
    <body>
    <script language="VBScript">
    
    Sub Test
     Dim oMenu
     Set oMenu = CreateObject("TestPopUpMenu")
     oMenu.Test
    End Sub
    
    Sub openDialog
     window.showModalDialog(document.location.href)
    End Sub
    
    </script>
    <button onclick="test" language="VBScript">TEST</button><BR>
    <button onclick="openDialog" language="VBScript">Open this page in dialog</button>
    
    </body>
    </html>


    In IE6 everything works fine.

    In IE7 when I've clicked "TEST" button nothing happens, but in dialog window (click "Open this page in dialog" button and then click "TEST") menu has been shown .

    If you want I can mail you full solution...

    With best regards.



  • Bart Vercauteren

    Hi,

    Can you post full details on how we can reproduce the issue There are documents at http://msdn.microsoft.com/ie and specifically a document at http://msdn.microsoft.com/library/default.asp url=/library/en-us/IETechCol/cols/dnexpie/activex_security.asp about changes to ActiveX handling in IE7.

    To report bugs and issues with IE7 please see the feedback links at http://www.microsoft.com/windows/ie/support/default.mspx

    Thanks
    -Dave



  • JasonG271009

    Hi Dave.

    I submit bug report with ID 196739.

    With best regards.



  • Pipz


    We have a similar problem with modal dialogs in ActiveX-controls that are hidden behind IE7 when shown. Despite being modal. Maybe that's what's happening with the popup menus

    Our application works perfectly in IE6 but this happens in IE7. Was there any solution to your popup menu-problem

  • pangitko79

    Hi Sergei,

    Can you submit the control in a bug report through connect at http://www.microsoft.com/windows/ie/support/default.mspx so we can reproduce the issue. It's difficult to say what change might have affected this. There is documentation on compatibility at http://msdn.microsoft.com/ie that may help. For menuing systems we generally advocate the use of DHTML and script rather than ActiveX controls.

    Thanks
    -Dave



  • SQLme

    Thanks Amlgc for the reply. If nothing else works, we will use your workaround to disable processes.

    We have been playing around with a test application to recreate the problems and determine when and why this happens. Turns out that the disappearing modal dialogs is a side-effect of the bug that modal dialogs are not modal. The dialogs only disappear if there is code in the owner window that is run after the modal dialog is shown.
    For example: if you have a button that shows a modal dialog when clicked, and nothing else, the dialog will not disappear from start, but if that button click does something with the owner window just after showning the dialog, the dialog disappears forever. This is just a side-effect from the dialog not being modal, the code continues to execute in the owner window.

    It would be nice if someone from Microsoft could tell us if this behaviour will be corrected, or is this new non-modal behaviour of modal dialogs going to remain

    /Rickard




  • Mach1

    Hi,

    Is there any update on this thread I had the same problem as sergei's.


  • redshock

    I think that the problem is related to IE7 thread structure. In IE7, main window (the one with IEFrame class) does not belong to the same ActiveX thread, as in IE6. You can see this with Spy++. This causes TrackPopupMenu to fail, when is called with GetForegroundWindow (which returns IEFrame’s window).

    Sergei, you have to use other handle than GetForegroundWindow when calling TrackPopupMenu. In Delphi, when I used the ActiveForm handle and it worked fine.

    Richard and Rick, I had the same problem of yours. An ActiveForm Delphi application that worked fine under IE6, and, under IE7 all modal forms became modeless. I found that the problem was in Delphi ShowModal method. It disables all thread windows, shows the form, and, when the form is closed, re-enables them. Unfortunately,t his does not work under IE7, once the main window belongs to other thread.

    My solution was to, before calling ShowModal, disable all process windows, re-enabling then after. I did that using EnumWindows and GetWindowThreadProcessId. I put the code below. It was adapted from Delphi run-time. EnableTaskWindow is, also, from Delphi run-time.

    I hope that can help you.

    Andre

    type pWindowList = ^tWindowList;
    tWindowList = record
    Next : pWindowList;
    Window : HWnd;
    end;

    type
    pDisableProcessWindows = ^tDisableProcessWindows;
    tDisableProcessWindows = record
    ActiveWindow : hWnd;
    ProcessId : DWORD;
    WindowList : pWindowList;
    end;

    function DoDisableWindow(Window: HWnd; Data: Longint): Bool; stdcall;
    var
    P: PWindowList;
    WinProcessId : DWORD;
    begin
    with pDisableProcessWindows(Data)^
    do begin
    GetWindowThreadProcessId(Window,@WinProcessId);
    if (ProcessId=WinProcessId)
    and (Window <> ActiveWindow)
    and IsWindowVisible(Window)
    and IsWindowEnabled(Window)
    then begin
    New(P);
    P^.Next := WindowList;
    P^.Window := Window;
    WindowList := P;
    EnableWindow(Window, False);
    end;
    end;
    Result := True;
    end;

    function DisableProcessWindows(ActiveWindow: HWnd): Pointer;
    var rec : tDisableProcessWindows;
    begin
    Result := nil;
    rec.ActiveWindow := ActiveWindow;
    rec.WindowList := nil;
    rec.ProcessId := GetCurrentProcessId;
    try
    try
    EnumWindows(@DoDisableWindow, integer(@rec));
    Result := rec.WindowList;
    except
    EnableTaskWindows(rec.WindowList);
    raise;
    end;
    finally
    end;
    end;

    function FormShowModal(Form:tCustomForm):integer;
    var WindowList:pointer;
    begin
    WindowList:=nil;
    try
    WindowList:=DisableProcessWindows(0);
    result:=Form.ShowModal;
    finally
    EnableTaskWindows(WindowList);
    end;
    end;


  • Anand Raman - MSFT

    I was also facing the same problem. But after disabling the tool tip I was able to get rid of this error. However I have another problem while clicking on the parent window after the popup window is displayed . In IE 6.0, if I click the parent window after the popup window is displayed, the focus is retained on the popup window. But in IE 7.0 focus is transferred to the parent window and the popup window goes behind the parent window. Is there any way to retain the modal window property for the popup window



  • Francisco Vicente

    Hi guys

    I'm glad that i've finally sound some other people experiencing a similar problem to me.

    Our software product uses a series of ActiveX DLLS created with VB6.0. These dll's expose a number of public functions which replicate data from central servers and display this information in "thick client" interfaces which are scripted to appear (VBScript and Javascript) from actions in IE. These are modal vb forms which are part of the activeX dll. (Our software runs as a trusted site with elevated priviledges). In IE7Beta3 onward, these windows briefly appear and then disappear (completely repeatably up to the final release version). This then locks the IE window so that it cannot be closed without "ending task". This problem did not occur in Beta 2 or Beta 1.

    Looks like you have been describing a very similar problem, only that my version of the problem occurs sporadicaly.

    Having read your reports, we've done a little more investigation and made changes to a skeleton ActiveX control to mimic your idea that it is code running after a show modal event that causes the problem.

    I've been lucky enough to be in email contact with Dave Massy about this problem, and to his credit he has been quite helpful. I will post any future replies I get on this thread. If any of you hear anything could you also do the same.

    Richard


  • wadnerk

    It looks like this issue is being investigated by the IE team. I had an email from the IE dev team to say that the issue is being worked on.
    A further update here. We have identified the issue and it is one that is already being worked on. The issues is that the tooltip becomes the root of the new window and when the tooltip goes away the entire thing falls apart. 
    
    There is a fix in the works but it is obviously too late for IE7 and will also not make the final release of Vista. The VB team is currently working through how to deliver the fix as soon as they can. 
    
    In the meantime the best advice we can give is to avoid tooltips. I’m following up with the VB team to find out if there is any other solution that would work until the fix is available.
    
    I’m giving you these details almost as they happen so I can’t guarantee the accuracy of any of the above as some things might change as investigation continues

  • IE7 and issue with TrackPopupMenu(Win32) within ActiveX-control