Loading ...
Sorry, an error occurred while loading the content.

Re: CTabbedChildWindow< / CDotNetTabCtrl

Expand Messages
  • Paul Selormey
    ... borrowed ... CTabbedChildWIndow (this way I don t have to worry about forwarding notifications, at least for now), and modifying the OnTabClose snippet so
    Message 1 of 4 , Nov 1, 2005
    • 0 Attachment
      --- In wtl@yahoogroups.com, Ellers <andrew@e...> wrote:
      >
      > >>Problem 1: what is the 'right' way to process a close event? I
      borrowed
      > >>this code from the tab source:
      > >
      > > [snip]
      > >
      > > I did it by making adding a handler for CTCN_CLOSE to
      CTabbedChildWIndow (this way I don't have to worry about forwarding
      notifications, at least for now), and modifying the OnTabClose
      snippet so that it hands the current tab's HWND to DeleteTab as well
      as sending it a WM_CLOSE:
      > >
      > > LRESULT OnTabClose(int /*idCtrl*/, LPNMHDR pnmh, BOOL&
      bHandled)
      > > {
      > > // Be sure the notification is from the tab control
      > > // (and not from a sibling like a list view control)
      > > if(pnmh && (m_TabCtrl == pnmh->hwndFrom))
      > > {
      > > LPNMCTCITEM pnmCustomTab = (LPNMCTCITEM)pnmh;
      > > if(pnmCustomTab)
      > > {
      > > if(pnmCustomTab->iItem >= 0)
      > > {
      > > TTabCtrl::TItem* pItem = m_TabCtrl.GetItem
      (pnmCustomTab->iItem);
      > > if(pItem)
      > > {
      > > RemoveTab(pItem->GetTabView());
      > > ::PostMessage(pItem->GetTabView(),
      WM_SYSCOMMAND, SC_CLOSE, 0L);
      > > }
      > > }
      > > }
      > > }
      > >
      > > bHandled = FALSE;
      > > return 0;
      > > }
      >
      > ok, thanks.
      >
      > does that take care of deleting the CMyView (or whatever) object
      that wraps the
      > HWND that gets put in the tab ctrl? Or do I need to take care of
      that
      > separately, e.g. in the WM_DESTROY handler of the view? Its
      probably automatic,
      > but I want to be sure...
      >

      Add this to your view

      void OnFinalMessage(HWND /*hWnd*/)
      {
      delete this;
      }

      and instead of the PostMessage(...) stuff, I normally do this
      HWND hwnd = pItem->GetTabView();
      RemoveTab(hwnd);
      ::ShowWindow(hwnd, SW_HIDE);
      ::DestroyWindow(hwnd);

      BTW, it is good that this stuff is not automatically handled, since
      even not all views must be destroy.

      Best regards,
      Paul.
    Your message has been successfully submitted and would be delivered to recipients shortly.