CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2013
    Posts
    6

    Dynamic icons on CMFCRibbonStatusBarPane

    Hello everyone,

    The goal is to change the status bar (CMFCRibbonStatusBar) icons based on some events.
    (The old CMFCStatusBar class had the SetPaneIcon() member that easily solves the problem.)

    The "improved" CMFCRibbonStatusBarPane has no members to set the icon, other then the constructor. Being a subclass of CMFCRibbonButton, it has SetImageIndex() that sets the icon index in the image list. The MS online help does not mention how and where to set that "list of images". My understanding is that the list belongs to the Button's parent; in this case it is the CMFCRibbonStatusBar, which has no methods to set any image list.
    Can anyone please explain shortly how and where am I supposed to set that list of images for the status bar? Or another way to solve the problem?

    Second related question:
    I have tried to set the pane icon with the CMFCRibbonStatusBarPane() constructor by loading it from an icon resource. The icon appears shortly and then it is replaced by a gray patch. (for tests I also used one of the icons given by the MFC wizard, with the same result)

    The code is:

    Code:
    int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
    ..........
    
    	if (!m_wndStatusBar.Create(this))
    	{
    		TRACE0("Failed to create status bar\n");
    		return -1;      // fail to create
    	}
    
    	HICON icon = LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(IDR_ICON1));
    	DWORD error = GetLastError();
    	TRACE1("%i\n", error);
    	ASSERT(icon);
    
    	CString strTitlePane2;
    	bNameValid = strTitlePane1.LoadString(IDS_STATUS_PANE2);
    	ASSERT(bNameValid);
    
    	CMFCRibbonStatusBarPane* pane = new CMFCRibbonStatusBarPane(ID_STATUSBAR_PANE2, strTitlePane2, TRUE, icon);
    	m_wndStatusBar.AddExtendedElement(pane, strTitlePane2);
    
    ..............
    }

    This code was placed within a program created by the MFC wizard that does nothing else.
    I absolutely do not "touch" the status bar after it is created here in CMainFrame::OnCreate().
    Apparently the icon is "erased" after OnCreate() exits. Where, how?
    I have made HICON icon; a member of my CMainFrame class, with the same result.
    Can anyone please suggest where to look for a solution to this problem?

    Thank you.
    Cris.

  2. #2
    Join Date
    Apr 2013
    Posts
    1

    Re: Dynamic icons on CMFCRibbonStatusBarPane

    Quote Originally Posted by Cristi View Post
    Hello everyone,

    The goal is to change the status bar (CMFCRibbonStatusBar) icons based on some events.
    (The old CMFCStatusBar class had the SetPaneIcon() member that easily solves the problem.)

    The "improved" CMFCRibbonStatusBarPane has no members to set the icon, other then the constructor. Being a subclass of CMFCRibbonButton, it has SetImageIndex() that sets the icon index in the image list. The MS online help does not mention how and where to set that "list of images". My understanding is that the list belongs to the Button's parent; in this case it is the CMFCRibbonStatusBar, which has no methods to set any image list.
    Can anyone please explain shortly how and where am I supposed to set that list of images for the status bar? Or another way to solve the problem?

    Second related question:
    I have tried to set the pane icon with the CMFCRibbonStatusBarPane() constructor by loading it from an icon resource. The icon appears shortly and then it is replaced by a gray patch. (for tests I also used one of the icons given by the MFC wizard, with the same result)

    The code is:

    Code:
    int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
    ..........
    
    	if (!m_wndStatusBar.Create(this))
    	{
    		TRACE0("Failed to create status bar\n");
    		return -1;      // fail to create
    	}
    
    	HICON icon = LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(IDR_ICON1));
    	DWORD error = GetLastError();
    	TRACE1("%i\n", error);
    	ASSERT(icon);
    
    	CString strTitlePane2;
    	bNameValid = strTitlePane1.LoadString(IDS_STATUS_PANE2);
    	ASSERT(bNameValid);
    
    	CMFCRibbonStatusBarPane* pane = new CMFCRibbonStatusBarPane(ID_STATUSBAR_PANE2, strTitlePane2, TRUE, icon);
    	m_wndStatusBar.AddExtendedElement(pane, strTitlePane2);
    
    ..............
    }

    This code was placed within a program created by the MFC wizard that does nothing else.
    I absolutely do not "touch" the status bar after it is created here in CMainFrame::OnCreate().
    Apparently the icon is "erased" after OnCreate() exits. Where, how?
    I have made HICON icon; a member of my CMainFrame class, with the same result.
    Can anyone please suggest where to look for a solution to this problem?

    Thank you.
    Cris.
    Add ON_COMMAND(ID_STATUSBAR_PANE2,&CMainFrame::OnStatusbarPane2) to enable your status bar icon which is disabled (gray).

Tags for this Thread

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