Click to See Complete Forum and Search --> : CComboBox in a CDialogBar


Brian Budge
June 25th, 1999, 11:58 AM
I am currently using a CDialogBar which contains only a CComboBox in my application. It looks great, but there is one slight problem - I have no handle on the CComboBox.

So basically, my CComboBox is, at present, useless. Does anybody know how I can set this up so that I have access to the ComboBox?

June 25th, 1999, 12:32 PM
If you create the DialogBar in your CMainFrame class, you can declare a data member (maybe public for other class use), *m_pCombobox (CComboBox), and assign it after the dialogbar is created. For example, you create the dialogbar in CMainFrame:



int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;

if (!m_wndToolBar.Create(this) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}

if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}

// TODO: Remove this if you don't want tool tips or a resizeable toolbar
m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);

// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);

// TODO: Add a menu item that will toggle the visibility of the
// dialog bar named "My Dialog Bar":
// 1. In ResourceView, open the menu resource that is used by
// the CMainFrame class
// 2. Select the View submenu
// 3. Double-click on the blank item at the bottom of the submenu
// 4. Assign the new item an ID: CG_ID_VIEW_MYDIALOGBAR
// 5. Assign the item a Caption: My Dialog Bar

// TODO: Change the value of CG_ID_VIEW_MYDIALOGBAR to an appropriate value:
// 1. Open the file resource.h
// CG: The following block was inserted by the 'Dialog Bar' component
{
// Initialize dialog bar m_wndMyDialogBar
if (!m_wndMyDialogBar.Create(this, CG_IDD_MYDIALOGBAR,
CBRS_TOP | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_HIDE_INPLACE |CBRS_TOOLTIPS, CG_ID_VIEW_MYDIALOGBAR))
{
TRACE0("Failed to create dialog bar m_wndMyDialogBar\n");
return -1; // fail to create
}

m_wndMyDialogBar.EnableDocking(CBRS_ALIGN_TOP | CBRS_ALIGN_BOTTOM);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndMyDialogBar);

}

// assume the ComboBox ID is IDC_MYCOMBOBOX
m_pCombobox = (CComboBox *) m_wndMyDialogBar.GetDlgItem(IDC_MYCOMBOBOX);

return 0;
}





Once, you set the pointer to the combobox, other classes can access this variable and change/set the combobox in the dialogbar. For example,

((CmainFrame*)AfxGetMainWnd())->m_pCombobox->SetWindowText("New Selection");




Hope this helps.

Allen

Octavian
June 25th, 1999, 12:36 PM
Just set up a message map in your frame to your combo box...

ON_CBN_SETFOCUS(IDC_SEARCHCOM, OnSetfocusSearchcom)

for example.

IDC_SEARCHCOM in my app is on a dialogbar.

Brian Budge
June 25th, 1999, 02:18 PM
Thanks so much!!! If I had been smart enough to snoop around in the CWnd functions for GetDlgItem, this would have been no problem!

Dallex
August 26th, 1999, 07:52 AM
I tried to implement your code but it doesn't work. I have a staic text box as well. Idid the following:

CString m_pCString
m_pCString = (CString *) m_BpauDialogBar.GetDlgItem(IDC_DISK_SPACE);

How do I set the string item on the dialog bar?