MFC: EditBox in Toolbar of CDialog

  • Thread starter Thread starter itr_rrauch
  • Start date Start date
I

itr_rrauch

Guest
Hello,

in an MFC/C++ applikation I need to create a dialog, which has local Menue and Toolbar.

Menue and Toolbar I have solved already; seems to work 100%

Additionally I need to replace a dummy button with an EditBox. With this I have issues.

The dummy button in the toolbar disappears, but there is no EditBox visible.

Here is my code. All my initialisation is located in OnInitDialog()


//-------------------------
// .h:

CMFCToolBar m_ToolBar;
CMFCToolBarEditBoxButton* m_pEditBtnFrom;


//-----------
// .cpp :

BOOL CDlgDiagCCLink::OnInitDialog()
{
CDialogEx::OnInitDialog();

// Toolbar
if (m_ToolBar.Create(this, AFX_DEFAULT_TOOLBAR_STYLE, 100))
{
m_ToolBar.SetPaneStyle(m_ToolBar.GetPaneStyle()
& ~(CBRS_GRIPPER | CBRS_SIZE_DYNAMIC | CBRS_BORDER_ANY));

m_ToolBar.LoadToolBar(IDR_TOOLBAR_DIAG_CCLINK, 0, 0, TRUE /* Ist gesperrt */);

CSize sizeToolBar = m_ToolBar.CalcFixedLayout(FALSE, TRUE);
m_ToolBar.SetWindowPos(NULL, 0, 0, sizeToolBar.cx, sizeToolBar.cy,
SWP_NOACTIVATE | SWP_NOZORDER);
m_ToolBar.SetOwner(this);
m_ToolBar.SetRouteCommandsViaFrame(FALSE);

// Toolbar Edit Box, replace dummy button

CMFCToolBarEditBoxButton editBox(
ID_SEARCH_SEARCHCHANGES_FROM,
GetCmdMgr()->GetCmdImage(ID_SEARCH_SEARCHCHANGES_FROM, FALSE));
editBox.SetContents(_T("0"));
m_ToolBar.ReplaceButton(ID_SEARCH_SEARCHCHANGES_FROM, editBox);

CMFCToolBarEditBoxButton* m_pEditBtnFrom = dynamic_cast<CMFCToolBarEditBoxButton*>
(m_ToolBar.GetButton(m_ToolBar.CommandToIndex(ID_SEARCH_SEARCHCHANGES_FROM)));

if (m_pEditBtnFrom == nullptr)
{
AfxMessageBox(_T("failed to create EditBox"), MB_ICONERROR | MB_OK);
}
m_pEditBtnFrom->EnableWindow();
}

// ...

Continue reading...
 
Back
Top