Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS General Discussion » Combo box in CExtToolControlBar Collapse All
Subject Author Date
Bacsó Gergely Jan 14, 2006 - 7:22 AM

Hello,

How can I put a combo box into a CExtToolControlBar?

nguyen hieu Mar 26, 2008 - 11:00 PM

I have download this sample to test.But when i type something in ComboBox,ex:a,b,c....,so this program was crashed.what i make to edit text in ComboBox


Best Regards,


Sorciere_vn

Technical Support Apr 2, 2008 - 5:56 AM

We have just downloaded this sample and tested it too. There are no crashes there. We used v.2.82. Would you start this sample in the Debug mode and copy the call stack when the crash occurs? Then send it to us so we can see what the crash is.

Technical Support Jan 15, 2006 - 12:47 PM

Just create a CExtComboBox (or CExtComboBoxBase or CComboBox) window as a child of the CExtToolControlBar window and assign the combo box window to some button in the toolbar by invoking the CExtToolControlBar::SetButtonCtrl() method. Please search for the SetButtonCtrl text in the ../Prof-UIS/Samples folder and find how the combo box window is assigned to the toolbar button.

Bacsó Gergely Jan 14, 2006 - 8:53 AM

OK, I found it, but

CExtCmdItem* pCmdItem = g_CmdManager->CmdAllocPtr(pApp->m_pszProfileName, ID_COMBOBOX_IN_TOOLBAR );
ASSERT( pCmdItem != NULL );
pCmdItem->m_sToolbarText = _T("Text in toolbar");


doesn’t seem to work here!

Technical Support Jan 15, 2006 - 12:49 PM

If the toolbar button is used as a container for HWND-based element like the combo box control, then this button will never draw any text in the area of the toolbar window. Please let us know details of what you want to do. Which text and were you need it?

Bacsó Gergely Jan 15, 2006 - 3:48 PM

My ToolBar should look like this:

-----------------------------------------
|                        -------------------  |
|  "Some Text"    | Combo box| -|  |
|                        -------------------  |
-----------------------------------------

And I don’t know how to put the "Some Text" label there.

Technical Support Jan 16, 2006 - 9:36 AM

The text next to the combo box window can be implemented as a standalone toolbar button or as a new CExtBarButton-derived class which overrides the CExtBarButton::SetRect(), CExtBarButton::CalculateLayout() and CExtBarButton::Paint() virtual methods. We can help you with this, but need more details. There is no problem with text before the combo box when the toolbar is docked horizontally or floating. But when the toolbar is docked horizontally, the text may be too wide. And a possible solution by placing the text above the combo box may lead to that this would look not good. What do you think about this?

Bacsó Gergely Jan 18, 2006 - 7:34 AM

http://ural2.hszk.bme.hu/~bg198/toolbarpic1.gif
You should replace this    ˆ  sign with normal tilde
                                     |

Bacsó Gergely Jan 18, 2006 - 7:29 AM

Thank you for your help, it almost works now!
I use CBRS_ALIGN_TOP|CBRS_ALIGN_BOTTOM, so vertical docking is no problem.

One thing is wrong with the toolbar: when it is floating, and I size it so, that it’s elements form one column, the text in the toolbar shifts under the caption:
http://ural2.hszk.bme.hu/~bg198/toolbarpic1.gif


I use the following code to paint text in the toolbar:


class
 CExtBarLabelButton : public CExtBarButton
{
public:
CExtBarLabelButton(CExtToolControlBar* pBar, UINT nCmdID, LPCTSTR lpszText);
public:
virtual CSize CalculateLayout(CDC & dc, CSize sizePreCalc, BOOL bHorz);
virtual void Paint(CDC & dc, bool bHorz);
protected:
CString strText;
}


CExtBarLabelButton::CExtBarLabelButton(CExtToolControlBar* pBar, UINT nCmdID, LPCTSTR lpszText)
: CExtBarButton(pBar, nCmdID), strText(lpszText)
{
}

CSize CExtBarLabelButton::CalculateLayout(CDC & dc, CSize sizePreCalc, BOOL bHorz)
{
return
CSize(dc.GetTextExtent(strText).cx+10, sizePreCalc.cy);
}

void CExtBarLabelButton::Paint(CDC & dc, bool
bHorz)
{
CFont* pOldFont = dc.SelectObject(&g_PaintManager->m_FontNormal);
dc.SetTextColor(g_PaintManager->GetColor(COLOR_WINDOWTEXT));
dc.DrawText(strText, m_ActiveRect, DT_CENTER|DT_SINGLELINE|DT_VCENTER);
dc.SelectObject(pOldFont);
}

I create the label button so:

CExtBarLabelButton* pLabelButton = new CExtBarLabelButton(&m_wndOutputToolBar, ID_TOOLBARLABEL, _RSTR(IDS_OUTPUT));
m_wndOutputToolBar.InsertSpecButton(-1, pLabelButton);

The creation of the combo boxes is the same as in the samples.

Technical Support Jan 20, 2006 - 1:54 PM

We coded a sample application for you. Please download it from our website.
The CMyBarButtonWithLabel class implements a combo box button with a label. Here is how it is initialized in the CMainFrame::OnCreate() method:

    if(       (! m_wndToolBar.Create( _T("Standard"), this, AFX_IDW_TOOLBAR ) )
        ||    (! m_wndToolBar.LoadToolBar( IDR_MAINFRAME ) )
        ||    (! m_wndComboInToolBar.Create(
                WS_CHILD|WS_VISIBLE
                    |WS_CLIPCHILDREN|WS_CLIPSIBLINGS
                    |CBS_DROPDOWN|CBS_HASSTRINGS,
                CRect( 0, 0, 100, 500 ),
                &m_wndToolBar,
                ID_COMBO_BUTTON_IN_TOOLBAR
                ) )
        )
    {
        TRACE0("Failed to create toolbar\n");
        return -1;      // fail to create
    }
int nButtonPos = m_wndToolBar.CommandToIndex( ID_COMBO_BUTTON_IN_TOOLBAR );
    ASSERT( nButtonPos >= 0 );
    m_wndToolBar.RemoveButton( nButtonPos );
CMyBarButtonWithLabel * pTBB =
        new CMyBarButtonWithLabel(
            &m_wndToolBar,
            ID_COMBO_BUTTON_IN_TOOLBAR
            );
    pTBB->SetLabelText( _T("Combo box:") );
    m_wndToolBar.InsertSpecButton(
        nButtonPos,
        pTBB,
        FALSE
        );
    m_wndToolBar.SetButtonCtrl( nButtonPos, &m_wndComboInToolBar );
    for( int nStringIdx = 0; nStringIdx < 10; nStringIdx++ )
    {
        CString s;
        s.Format( _T("String %d"), nStringIdx );
        m_wndComboInToolBar.AddString( LPCTSTR(s) );
    }
    m_wndComboInToolBar.SetCurSel( 0 );
    m_wndComboInToolBar.SetFont(
        CFont::FromHandle(
            (HFONT)::GetStockObject( DEFAULT_GUI_FONT )
            )
        );
The CMainFrame::OnComboButtonInToolbar() method handler for the ID_COMBO_BUTTON_IN_TOOLBAR command handles clicks on the combo box button when the toolbar window is docked vertically. This handler method is also needed to keep the combo box in enabled state.