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 Tech Support » Insert and remove buttons with control Collapse All
Subject Author Date
Andrew Nanopoulos Apr 10, 2006 - 4:39 PM

What is the propper way to insert and remove a button with a control on it and be able to do the insert/remove cycle over and over... What I want to do is keep the contol alive and show it in the toolbar on demand. If I just call RemoveButton the control stays on the toolbar. I tried using DestoryWindow() but when I call CreateWindow for the second time contol shows up as a grey inactive box.

My code seems to work with a CStatic but not with a CExtEdit.

Any Ideas?

For Example:


CExtEdit *m_wndPinEditBox;

void SomeClass::RemoveButton(UINT nCmdID)
{
    int nButtonIndex =
        m_wndToolBar->CommandToIndex( nCmdID );
    if( nButtonIndex >= 0 ){
        //if it is a control we need to hide the window
        CWnd* ctl = m_wndToolBar->GetButtonCtrl(nButtonIndex);
        if(ctl != NULL){
            ictl->DestroyWindow();        
        }
        m_wndToolBar->RemoveButton( nButtonIndex );
    }
    RecalcLayout();
}


bool SomeClass::InsertEditBox(int index)
{

    if(!m_wndPinEditBox->GetSafeHwnd( )) //Is this the correct way to test if the window is created?
    {
        if( !m_wndPinEditBox->CreateEx(
            WS_EX_CLIENTEDGE ,
            _T("EDIT"),
            NULL,
            WS_CHILD|WS_VISIBLE|WS_TABSTOP|ES_AUTOHSCROLL|ES_LEFT|ES_PASSWORD,
            CRect( 0, 0, 50, 21 ),
            m_wndToolBar,
            ID_PIN_EDIT
            )
            
            )
        {
            TRACE0("Failed to create help search combobox\n" );
            return false;
        }
    }
if(!m_wndToolBar->InsertButton
        (
        index,
        nID,TRUE
        )
        )return false;
    
    
    VERIFY(
        m_wndToolBar->SetButtonCtrl(
        m_wndToolBar->CommandToIndex(
        nID ),
        m_wndPinEditBox
        )
        );
}

Andrew Nanopoulos Apr 10, 2006 - 4:42 PM

nID in the example is ID_PIN_EDIT...

Andrew Nanopoulos Apr 11, 2006 - 9:35 AM

I think I figured it out.