Question

Je veux gérer les événements de déplacement de la fenêtre. Mon premier essai était de gérer les événements DWebBrowserEvents2::WindowSetHeight, WindowSetLeft, WindowSetTop et WindowSetWidth, mais pour certaines raisons, ces événements n'a pas viré du tout. J'ai manipulé Redimensionner la fenêtre en manipulant HTMLWindowEvents2::onresize. Comment puis-je gérer lorsque la fenêtre se déplace?

J'ai aussi essayé la mise en œuvre IHTMLOMWindowServices, mais ses membres ne sont pas appelés lors du changement de position de la fenêtre. Y a-t-il des suggestions quant à ce qui serait une bonne interface pour mettre en œuvre? Je crée une extension IE en utilisant ATL dans Visual C ++.

Était-ce utile?

La solution 2

Handled la situation en utilisant la minuterie. Pas trop élégant, mais fonctionne!

Autres conseils

fenêtre HTML est pas le bon endroit. Vous devez remonter d'un niveau au niveau de la fenêtre du navigateur, par exemple:.

            // Get a handle for the IE window and set a hook for the window resize/move events
        m_spWebBrowser->get_HWND(reinterpret_cast<SHANDLE_PTR*>(&m_pWebBrowserHwnd));
        if(m_pWebBrowserHwnd)
        {
            int idHook = WH_CALLWNDPROC; // Type of hook: all Window calls
            HOOKPROC hookProc = MyClass::OnWindowMessage; // Procedure to be called
            HINSTANCE hMod = NULL; // DLL to monitor
            DWORD dwThreadId = GetWindowThreadProcessId(m_pWebBrowserHwnd,NULL); // IE Thread to monitor
            m_ResizeHook = SetWindowsHookEx(idHook, hookProc, hMod, dwThreadId); 
            Trace (L"Hook for window move/resize is set up");
        }

Alors onWindowMessage gère le bon message:

LRESULT CALLBACK MyClass::OnWindowMessage(int nCode, WPARAM wParam, LPARAM lParam)
{

LRESULT result = CallNextHookEx(NULL, nCode, wParam, lParam);

if( (lParam!=NULL) && (nCode == HC_ACTION))
{
    CWPSTRUCT *CwpStruct = (CWPSTRUCT *) lParam;
    switch(CwpStruct->message)
    {
    case WM_MOVE:
        HWND manipluatedHWND = CwpStruct->hwnd;
            //Code to execute when window moves
        break;
    }
}

Enjoy:)

D'accord, voici un code rude

    class ATL_NO_VTABLE CHelloWorldBHO :
       public CComObjectRootEx<CComSingleThreadModel>,
       public CComCoClass<CHelloWorldBHO, &CLSID_HelloWorldBHO>,
       public IObjectWithSiteImpl<CHelloWorldBHO>,
       public IDispatchImpl<IHelloWorldBHO, &IID_IHelloWorldBHO, &LIBID_HelloWorldLib, /*wMajor =*/ 1, /*wMinor =*/ 0>,
       public IDispEventImpl<1, CHelloWorldBHO, &DIID_DWebBrowserEvents2, &LIBID_SHDocVw, 1, 1>, 
      //Other interfaces here
{

             BEGIN_SINK_MAP(CHelloWorldBHO)
                SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_DOCUMENTCOMPLETE, OnDocumentComplete)//Do stuff OnDocumentComplete
             END_SINK_MAP()

         void STDMETHODCALLTYPE OnDocumentComplete(IDispatch *pDisp, VARIANT *pvarURL){
             //Do other stuff here
             SetUpWindowsHook();//This calls a function that sets a window hook, similar to the code that you've posted
         }

}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top