Print Page | Close Window

MFC. Edit Control inside RibbonBar.

Printed From: Codejock Forums
Category: General
Forum Name: Articles and Tutorials
Forum Description: Articles and Tutorials
URL: http://forum.codejock.com/forum_posts.asp?TID=18057
Printed Date: 05 May 2024 at 4:07am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: MFC. Edit Control inside RibbonBar.
Posted By: Oleg
Subject: MFC. Edit Control inside RibbonBar.
Date Posted: 15 March 2011 at 2:31am

When Ribbonbar has CXTPControlComboBox or CXTPConrtolEdit inside, developer should synchronize its text with internal variable. In this case if user add this Edit control to Quick Access both of them will show same text if user change it.




Steps

1. Add Edit to group

pGroupClipborad->Add(xtpControlEdit, ID_EDIT_PARAM);

2. We need add member variable that will hold actual value of Edit - in case we need check edit text, we don't have to find edit and check its current value, we just use this variable directly

CString m_strParam
...
m_strParam = _T("Parameter");


3. Add Handler fired when Edit is changed:

ON_XTP_EXECUTE(ID_EDIT_PARAM, OnEditParam)

void CMainFrame::OnEditParam(NMHDR* pNMHDR, LRESULT* pResult)
{
NMXTPCONTROL* tagNMCONTROL = (NMXTPCONTROL*)pNMHDR;
CXTPControlEdit* pEdit = DYNAMIC_DOWNCAST(CXTPControlEdit, tagNMCONTROL->pControl);
if (pEdit)
{
m_strParam = pEdit->GetEditText();

// m_strParam contains actual text of edit. don't call GetEditText inside application. just use m_strParam instead.

*pResult = TRUE; // Handled
}
}

4.  Add Update Handler for our Edit:

void CMainFrame::OnUpdateEditParam(CCmdUI* pCmdUI)
{
CXTPControlEdit* pEdit = DYNAMIC_DOWNCAST(CXTPControlEdit, CXTPControl::FromUI(pCmdUI));
if (pEdit && !pEdit->HasFocus())
{
pEdit->SetEditText(m_strParam);
}
pCmdUI->Enable(TRUE);
}

Now all edit with same ID_EDIT_PARAM id will always show same text


Sample project:
uploads/37/EditSample.zip - EditSample.zip


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS



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