Print Page | Close Window

How to get event that selected tab is change

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Command Bars
Forum Description: Topics Related to Codejock Command Bars
URL: http://forum.codejock.com/forum_posts.asp?TID=23211
Printed Date: 21 November 2024 at 10:35pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: How to get event that selected tab is change
Posted By: hiro-ta
Subject: How to get event that selected tab is change
Date Posted: 28 November 2016 at 1:13am
Hi,

Please teach me how to get event that current ribbon tab is changed.



Replies:
Posted By: olebed
Date Posted: 29 November 2016 at 8:49am
Hello,

See our RibbonSample  Samples\Ribbon\RibbonSample\MainFrm.cpp
BEGIN_MESSAGE_MAP(CMainFrame, CXTPFrameWnd)
    ....
    ON_NOTIFY(TCN_SELCHANGE, XTP_ID_RIBBONCONTROLTAB, OnRibbonTabChanged)
    ON_NOTIFY(TCN_SELCHANGING, XTP_ID_RIBBONCONTROLTAB, OnRibbonTabChanging)
    ....
END_MESSAGE_MAP()

void CMainFrame::OnRibbonTabChanged(NMHDR* pNMHDR, LRESULT* pRes) 
{
    NMXTPTABCHANGE* pNMTabChanged = (NMXTPTABCHANGE*)pNMHDR;

    if (pNMTabChanged->pTab)
    {
        TRACE(_T("Tab Changed, Caption = %s\n"), (LPCTSTR)pNMTabChanged->pTab->GetCaption());
    }
    
    *pRes = 0;
}

void CMainFrame::OnRibbonTabChanging(NMHDR* /*pNMHDR*/, LRESULT* pRes) 
{

    *pRes = 0;    
}

Code which handle these messages is
BOOL CXTPRibbonBar::OnTabChanging(CXTPRibbonTab* pTab)
{
    NMXTPTABCHANGE nm;
    nm.pTab = pTab;

    return (BOOL)m_pControlTab->NotifySite(TCN_SELCHANGING, &nm);
}

void CXTPRibbonBar::OnTabChanged(CXTPRibbonTab* pTab)
{
    NMXTPTABCHANGE nm;
    nm.pTab = pTab;

    m_pControlTab->NotifySite(TCN_SELCHANGE, &nm);
}

Regards,
 Oleksandr Lebed


Posted By: hiro-ta
Date Posted: 30 November 2016 at 5:34am
Thanks.

But not get the event that [File] tab is selected.
Is there a way?


Posted By: olebed
Date Posted: 30 November 2016 at 8:05am
[File] is not ribbon's tab, it is "systemButton"  which call BackStage.

I can't find how catch that event, but can offer to handle message of changing backstage tab, which also raised when backstage became visible.
BEGIN_MESSAGE_MAP(CMainFrame, CXTPFrameWnd)
    ...
    ON_MESSAGE(WM_XTP_COMMAND, OnBackstageTabChanged)
END_MESSAGE_MAP()

LRESULT CMainFrame::OnBackstageTabChanged(WPARAM wParam, LPARAM lParam)
{
    UNUSED_ALWAYS(wParam);

    NMXTPCONTROL* tagNMCONTROL = (NMXTPCONTROL*)lParam;
    if (tagNMCONTROL && tagNMCONTROL->hdr.code == XTP_BS_TABCHANGED)
    {
        CXTPRibbonBackstageTab* pNewTab = DYNAMIC_DOWNCAST(CXTPRibbonBackstageTab, tagNMCONTROL->pControl);
    }

    return 0;
}


Posted By: hiro-ta
Date Posted: 30 November 2016 at 8:47pm
Hi, 
Thank you for your response. It works well.
Problem solved.


Posted By: olebed
Date Posted: 01 December 2016 at 6:12am
I have tested and unfortunately found that CMainFrame::OnBackstageTabChanged() isn't raised when backstage have only commands, without tabs.
Take this into account.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net