Override OnClose ()

I got this class

class CWebBrowser2 : public CWnd

And I want to override OnClose. What I have done so far, in the header file I have added void OnClose (); and in the .cpp file I added

void CWebBrowser2::OnClose ()
{
        int i=0;
        i++;
}

But OnClose is never called.

Then I tried changing the header file to

afx_msg void OnClose();
DECLARE_MESSAGE_MAP()

And added this to the .cpp file

BEGIN_MESSAGE_MAP(CWebBrowser2, CWnd)
    //{{AFX_MSG_MAP(CBrowserDlg)
    ON_WM_CLOSE()
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

But still, OnClose is never called. I tried to switch to OnClose in OnDestroy, but this is not called either.

Any ideas on what I'm doing wrong?

+3
source share
2 answers

After adding ON_WM_CLOSE()it should work. How do you close the window?

In your class header file, do you have this line? DECLARE_MESSAGE_MAP()

+4
source

, , ( ), . OP , ActiveX ( CWebBrowser2), HWND, . http://support.microsoft.com/kb/156051.

// This is how the control is normally created (i.e., dynamically):

/* CWebBrowser2 * */ pBrowser = new CWebBrowser2;
CWebBrowser2 * pBrowser = new CWebBrowser2;
ASSERT(pBrowser);

if (!pBrowser->Create(_T("windowname"), _T("classname"), WS_VISIBLE, CRect(0,0,0,0), this, ID_OF_BROWSER))
{
    TRACE( _T("An error occurred creating the Map tab"), true, false );
    delete pBrowser;
    pBrowser = NULL;
    return 0;
}

// Add these two lines so your control receives Windows messages:
HWND hWnd = pBrowser->Detach();
pBrowser->SubclassWindow(hWnd);
+1

Source: https://habr.com/ru/post/1750481/


All Articles