CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 1999
    Location
    SLC, Utah
    Posts
    155

    CComboBox in a CDialogBar

    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?


  2. #2
    Guest

    Re: CComboBox in a CDialogBar

    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


  3. #3
    Join Date
    Jun 1999
    Posts
    9

    Re: CComboBox in a CDialogBar

    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.


  4. #4
    Join Date
    Jun 1999
    Location
    SLC, Utah
    Posts
    155

    Re: CComboBox in a CDialogBar

    Thanks so much!!! If I had been smart enough to snoop around in the CWnd functions for GetDlgItem, this would have been no problem!


  5. #5
    Join Date
    Apr 1999
    Posts
    76

    Re: CComboBox in a CDialogBar

    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?


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured