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 » Problem with Buttons in Toolbar Collapse All
Subject Author Date
Robert Hauck Nov 18, 2004 - 1:25 AM

Hi

I have a strange problem with the toolbars. I have several toolbars where only one button can be pressed at time, for example to choose witch GUI-Layout we want to use. If I start the application, it is correct, but if I press another button, the old doesn’t get released and both are pressed.
I don’t know if it is important, but the application is a OpenGL-application, with consumes most of the CPU-time...


This is the corresponding code in the mainframe:


CMainFrame::eGUIStyle CMainFrame::GetGuiStyle()
{
    if (g_PaintManager->IsKindOf( RUNTIME_CLASS(CExtPaintManagerStudio2005)))
        return GUISTYLE_2005;
    else if (g_PaintManager->IsKindOf( RUNTIME_CLASS(CExtPaintManagerOffice2003)))
        return GUISTYLE_2003;
    else if (g_PaintManager->IsKindOf( RUNTIME_CLASS(CExtPaintManagerXP)))
        return GUISTYLE_2002;
    else if (g_PaintManager->IsKindOf( RUNTIME_CLASS(CExtPaintManager)))
        return GUISTYLE_2000;

    ASSERT(0);
    return GUISTYLE_2000;
}

void CMainFrame::EnableGuiStyleCommand(CCmdUI *pCmdUi, eGUIStyle nGuiStyle)
{

    CWinApp * pApp = ::AfxGetApp();

    g_CmdManager->CmdGetPtr(pApp->m_pszProfileName, ID_HIRES_GUI2000)->StateSetCheck(FALSE);
    g_CmdManager->CmdGetPtr(pApp->m_pszProfileName, ID_HIRES_GUI2002)->StateSetCheck(FALSE);
    g_CmdManager->CmdGetPtr(pApp->m_pszProfileName, ID_HIRES_GUI2003)->StateSetCheck(FALSE);
    g_CmdManager->CmdGetPtr(pApp->m_pszProfileName, ID_HIRES_GUI2005)->StateSetCheck(FALSE);

    pCmdUi->Enable();
    pCmdUi->SetRadio(nGuiStyle == GetGuiStyle());
}

void CMainFrame::SetGuiStyle(eGUIStyle nGuiStyle)
{
    if (GetGuiStyle() == nGuiStyle)
        return;

    CRuntimeClass *pRuntimeClass = NULL;
    switch (nGuiStyle)
    {
    case GUISTYLE_2000:
        pRuntimeClass = RUNTIME_CLASS(CExtPaintManager);
        break;
    case GUISTYLE_2002:
        pRuntimeClass = RUNTIME_CLASS(CExtPaintManagerXP);
        break;
    case GUISTYLE_2003:
        pRuntimeClass = RUNTIME_CLASS(CExtPaintManagerOffice2003);
        break;
    case GUISTYLE_2005:
        pRuntimeClass = RUNTIME_CLASS(CExtPaintManagerStudio2005);
        break;
    default:
        ASSERT(0);
    }

    VERIFY(g_PaintManager.InstallPaintManager((CExtPaintManager*)pRuntimeClass->CreateObject()));


    RecalcLayout();
    RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN);
    CExtControlBar::stat_RedrawFloatingFrames( this );
    CExtControlBar::stat_RecalcBarMetrics( this );
    Invalidate();
    UpdateWindow();


}


void CMainFrame::OnGuiTheme2000()
{
    SetGuiStyle(GUISTYLE_2000);
}

void CMainFrame::OnUpdateGuiTheme2000(CCmdUI* pCmdUI)
{
    EnableGuiStyleCommand(pCmdUI, GUISTYLE_2000);
}

The eGUIStyle is an enumerator. This is how I create the toolbar in the oncreate-method:


if((! m_wndHiResVSToolBar.Create(_T("Visualstyle Toolbar"), this, IDR_HIRES_VSTOOLBAR)) || (! m_wndHiResVSToolBar.LoadToolBar(IDR_HIRES_VSTOOLBAR)))
    {
        TRACE0("Visual Style Toolbar\n");
        return -1; // fail to create
    }
    m_wndHiResVSToolBar.EnableDocking(CBRS_ALIGN_ANY);
    CRect wrAlreadyDockedToolBar;
    m_wndHiResDSToolBar.GetWindowRect( &wrAlreadyDockedToolBar );
    wrAlreadyDockedToolBar.OffsetRect( 0, 1 );
    DockControlBar(&m_wndHiResVSToolBar, AFX_IDW_DOCKBAR_TOP, &wrAlreadyDockedToolBar);

Can somebody give me a hint?
Thank you very much

Technical Support Nov 18, 2004 - 3:59 AM

The source code looks correct, but the following files are needless:

g_CmdManager->CmdGetPtr(pApp->m_pszProfileName, 
ID_HIRES_GUI2000)->StateSetCheck(FALSE);
g_CmdManager->CmdGetPtr(pApp->m_pszProfileName,
ID_HIRES_GUI2002)->StateSetCheck(FALSE);
g_CmdManager->CmdGetPtr(pApp->m_pszProfileName,
ID_HIRES_GUI2003)->StateSetCheck(FALSE);
g_CmdManager->CmdGetPtr(pApp->m_pszProfileName,
ID_HIRES_GUI2005)->StateSetCheck(FALSE);
Besides, even if your application consumes too much CPU time, you should let the windows to be repainted. We guess your application performs OpenGL rendering periodically in the same thread in which the mainframe and Prof-UIS toolbars were created. After finishing the OpenGL output, you may invoke the following method:
CExtPopupMenuWnd::PassMsgLoop(false);
This line will deliver all pending messages in the thread’s message queue to their receivers so that the toolbar windows can be updated when the state of the buttons has been changed. Besides, forceful processing of the messages makes mouse/keyboard input alive.

Robert Hauck Nov 18, 2004 - 5:23 AM

Thank you for your response, but adding it to the onDraw-method didn’t change much...

Could it be that I initialized something wrong with the g_CmdManager? Does this Manager somehow affect the drawing of the buttons?

My onDraw looks like this:

void CVirtualSpiritPrototypeView::OnDraw(CDC*)
{
    CVirtualSpiritPrototypeDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    if (!pDoc)
        return;

    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    glPushMatrix();
    glTranslatef(0.0, 2.0, 0.0);
    glPushMatrix();
    RenderScene();
    RenderCharacter(*m_pCharacter->GetRoot());
    glPopMatrix();
    glPopMatrix();

    if ( FALSE == ::SwapBuffers( m_pDC->GetSafeHdc() ) )
    {
        SetError(7);
    }
}

Technical Support Nov 18, 2004 - 8:16 AM

We guess the problem hides somewhere outside the usage of OpenGL and the scene rendering code. Could you send us your test project? We need only the GUI-related source code (the application, frame, view, dialogs, and windows in resizable bars) and resources.