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 » Loading Toolbar bitmaps Collapse All
Subject Author Date
Bob Sherman Apr 4, 2006 - 8:39 PM

Is there a way to load a bitmap into a toolbar? I have code that I’m trying to make use Prof-UIS. It is set up this way:

// toolbar buttons - IDs are command buttons
static UINT BASED_CODE toolbar[] =
{
    ID_FILE_NEW,
    ID_FILE_OPEN,
    ID_FILE_SAVE,
ID_SEPARATOR,
    ID_FILE_PRINT_DIRECT,
    ID_FILE_PRINT_PREVIEW,
ID_SEPARATOR,
    ID_EDIT_FIND,
ID_SEPARATOR,
    ID_EDIT_CUT,
    ID_EDIT_COPY,
    ID_EDIT_PASTE,
    ID_EDIT_UNDO,
ID_SEPARATOR,
    ID_INSERT_DATE_TIME,
ID_SEPARATOR,
    ID_PEN_TOGGLE,
    ID_PEN_PERIOD,
    ID_PEN_SPACE,
    ID_PEN_BACKSPACE,
    ID_PEN_NEWLINE,
    ID_PEN_LENS
};
#define NUM_PEN_ITEMS 7
#define NUM_PEN_TOGGLE 5
...
BOOL CMainFrame::CreateToolBar()
{
    int nPen = GetSystemMetrics(SM_PENWINDOWS) ? NUM_PEN_TOGGLE :
        NUM_PEN_ITEMS;

    if (!m_wndToolBar.Create(this,
        WS_CHILD|WS_VISIBLE|CBRS_TOP|CBRS_TOOLTIPS|CBRS_FLYBY|CBRS_SIZE_DYNAMIC)||
        !m_wndToolBar.LoadBitmap(nID) ||
        !m_wndToolBar.SetButtons(toolbar, sizeof(toolbar)/sizeof(UINT) - nPen))
    {
        TRACE0("Failed to create toolbar\n");
        return FALSE; // fail to create
    }

    CString str;
    str.LoadString(IDS_TITLE_TOOLBAR);
    m_wndToolBar.SetWindowText(str);
    return TRUE;
}
/////////////////////////////////

This I make into:

m_wndToolBar.Create(NULL, this, ID_VIEW_TOOLBAR);
m_wndToolBar.SetButtons(toolbar, sizeof(toolbar)/sizeof(UINT) - nPen);


But how would I load the bitmaps into the toolbar like the original?

Thanks in advance!

Technical Support Apr 5, 2006 - 11:59 AM

All the toolbar button images are stored in the global command manager. You can create a toolbar resource which contains all the commands with images and invoke the g_CmdManager->UpdateFromToolBar method -- the command manager will be updated with information about the commands images. Most of our samples follow this approach.

VERIFY(
  g_CmdManager->UpdateFromToolBar(
   pApp->m_pszProfileName,
   IDR_TOOLBAR
   )
  );

Bob Sherman Apr 7, 2006 - 4:53 PM

Thanks a lot! Now I’m trying to get a more complicated toolbar to display. I have replaced the GetItemRects with GetButtonRect, and changed everything to the correct classes, but now when my application loads, it crashes. When I run debug it stops at line 459 of ExtToolControlBar.cpp, where ASSERT( pCmdItem != NULL ); is. Do you know what would be causing this?

Bob Sherman Apr 7, 2006 - 5:07 PM

I also get Prof-UIS: CExtControlBar::ProfileBarStateLoad() failed to load bar state in the trace window...

Technical Support Apr 9, 2006 - 8:21 AM

Please check if you did not forget to perform the command profile initialization somewhere at the beginning of the CMainFrame::OnCreate() method:

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
        return -1;
 
    . . .
    
CWinApp * pApp = ::AfxGetApp();
    ASSERT( pApp != NULL );
    ASSERT( pApp->m_pszRegistryKey != NULL );
    ASSERT( pApp->m_pszRegistryKey[0] != _T(’\0’) );
    ASSERT( pApp->m_pszProfileName != NULL );
    ASSERT( pApp->m_pszProfileName[0] != _T(’\0’) );
    ASSERT( pApp->m_pszProfileName != NULL );
 
    . . .
    
    g_CmdManager->ProfileSetup(
        pApp->m_pszProfileName,
        GetSafeHwnd()
        );
 
    . . .
This is an essential step and you can look at how it is done in any Prof-UIS frame-based application. Unit 3.5 of this article may also be helpful with this.

Bob Sherman Apr 9, 2006 - 8:35 AM

No, I did not forget that part. I made sure that I did that first thing. The profile seems to be fine until the bar that one toolbar loads. The toolbar is the Format toolbar in the Microsoft WORDPAD example. (I’m trying to get Prof-UIS in other apps before I work on mine so I can get the hang of it.) I don’t know if its something I did or not. But that should hep a lot.

Technical Support Apr 10, 2006 - 1:18 AM

Would you send us a test project that demonstrates the problem or at least the .cpp and .h files of both your CWinApp-derived class and your main frame class? That would allow us to help you more effectively.

Bob Sherman Apr 10, 2006 - 9:30 AM

There you go... I just sent it...

Technical Support Apr 11, 2006 - 2:51 AM

We found one critical error in your CMainFrame::OnCreate() method. Please replace

    EnableDocking(CBRS_ALIGN_ANY);
with
    if( ! CExtControlBar::FrameEnableDocking( this ) )
    {
        ASSERT( FALSE );
        return -1;
    }