Placing Logo on the Top DockBar of the Frame Window

Some time ago I participated in a project. We had to place our logo at some place in the right top corner of the frame window. I decided to place it on the top dockbar and created CLogo class for this purpose. This class is used for handling logo's location, tooltips and the message line in the status bar. Logo positions itself in the top right corner within parent dockbar. If the logo intersects with any toolbar then CLogo hides and otherwise it becomes visible. CLogo uses a string resource with the integer identifier of the logo window for displaying tooltips and the message line in the status bar. Besides, CLogo sends ON_LOGO_CLICK registered window message to the application main window when a user clicks on the logo window.

Sample Image

In the demo project I put in this article I derived CLogo from MFC CBitmapButton class. But you could change my code and derive CLogo from any class derived from CWnd. I use the class, from which CLogo is derived, for visual representation of logo.

Step 1: Create a new Single document or Multiple document project by using MFC AppWizard.

Step 2: Add Logo.cpp and Logo.h files to the project.

Step 3: Change the base class of CLogo to any class derived from CWnd you want. Be sure that you have replaced all occurrences of CBitmapButton in Logo.cpp and Logo.h files.

Step 4: Add #include statement to StdAfx.h file for CDockBar support.

Step 5: Add a member variable of CLogo type to CMainFrame:

protected:
 CLogo m_wndLogo;

Step 6: Add creation code for the CLogo base class at the end of OnCreate handler of CMainFrame. Be sure that you have used the top dockbar as a parent window for the logo. Since I use CBitmapButton, I added the next lines:

// LOGO SUPPORT
CControlBar* pTopDockBar = GetControlBar(AFX_IDW_DOCKBAR_TOP);
if (pTopDockBar 
&& m_wndLogo.Create(NULL,
                    WS_CHILD | WS_VISIBLE | BS_OWNERDRAW,
                    CRect(0,0,0,0),
                    pTopDockBar,
                    IDC_LOGO_BUTTON))
{	
 m_wndLogo.LoadBitmaps(IDB_LOGO_BITMAP, IDB_LOGOSEL_BITMAP);
 m_wndLogo.SizeToContent();
}
// LOGO SUPPORT

Step 7: Add the string resource with the integer identifier of the logo window for displaying tooltips and the message line in the status bar. I added the next string resource:

IDC_LOGO_BUTTON "Go to Sunbay's home page\nGo to Sunbay's Home Page"

Step 8: Add the handler of ON_LOGO_CLICK registered window message to CMainFrame. You could handle this message as you want. For example, my demo application launches a registered internet browser and goes to the home page of my company.

That is all. Now you could compile your project and try out how the program behaves.

Downloads

Download demo project - 36 Kb
Download source - 3 Kb


Comments

  • Destroy all tooltip of windows

    Posted by Legacy on 07/19/2002 12:00am

    Originally posted by: Dylan

    When I implement the CLogo, it work good but all the tooltips of any application were destroy....

    Have you a suggestion to undestroy tooltip

    Thanks...

    Reply
  • what's new in your article?

    Posted by Legacy on 07/15/2002 12:00am

    Originally posted by: Nguyen minh Tam

    I think this article is very normal. and if you want to send an article you should see back to know what you done ok?
    

    Reply
  • Optimization and avoid flickering

    Posted by Legacy on 06/13/2002 12:00am

    Originally posted by: Avi Dahan


    In order to upadte the position of the logo - no need to set timer.

    So do the following:

    void CMainFrame::OnSize(UINT nType, int cx, int cy)
    {
    CFrameWnd::OnSize(nType, cx, cy);

    // update the position of logo.
    m_wndLogo.SetPosition();
    }


    In logo.cpp - you don't have to set timer.

    int CLogo::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
    if (CBitmapButton::OnCreate(lpCreateStruct) == -1)
    return -1;

    ASSERT(GetParentDockBar());

    //SetTimer(nLogoTimer,100,NULL);

    EnableToolTips();

    return 0;
    }


    By doing so, no more flickering in release mode.

    Thanks
    And have a Bug-Free day.

    Reply
  • Another way to add logo to the main frame

    Posted by Legacy on 11/27/2001 12:00am

    Originally posted by: Ali

    The easiest way to add your logo to the main frame :
    
    

    int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
    if (!m_wndToolBar.CreateEx(this) ||
    !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
    {
    TRACE0("Failed to create toolbar\n");
    return -1; // fail to create
    }
    // create a logo bar, m_wndLogo is a CDialogBar object, IDR_MAINFRAME is a dialog resource
    if (!m_wndLogo.Create(this, IDR_MAINFRAME, CBRS_ALIGN_TOP, AFX_IDW_DIALOGBAR))
    {
    TRACE0("Failed to create logobar\n");
    return -1; // fail to create
    }

    // finally, create the rebar and it's bands with m_wndReBar is a CRebar object
    if (!m_wndReBar.Create(this))
    {
    TRACE(_T("Failed to create rebar\n"));
    return -1; // fail to create
    }
    // let the rebar own the toolbar
    m_wndToolBar.SetOwner(&m_wndReBar);
    // add rebar bands
    if( !m_wndReBar.AddBar(&m_wndLogo, NULL, GetSysColor(COLOR_3DFACE), NULL, RBBS_FIXEDSIZE | RBBS_FIXEDBMP)||
    !m_wndReBar.AddBar(&m_wndToolBar, NULL, NULL, RBBS_FIXEDBMP | RBBS_BREAK))
    {
    TRACE(_T("Failed to add rebar bands\n"));
    return -1; // fail to add bands
    }

    .....
    .....
    return 1;
    }

    Reply
  • toolbar

    Posted by Legacy on 11/11/2001 12:00am

    Originally posted by: harish

    hey how do i use it in sdk. :O

    Reply
  • VB

    Posted by Legacy on 07/18/2001 12:00am

    Originally posted by: Shihan

    I Want VB Project With Coding

    Reply
  • It does not work under Windows 2000

    Posted by Legacy on 07/06/2001 12:00am

    Originally posted by: Carlos A.

    The logo does not work properly under Windows 2000. It appears and dissapears. Do you know why?

    Carlos A.

    Reply
  • Does not flicker any more...

    Posted by Legacy on 06/03/2001 12:00am

    Originally posted by: Jakub

    What to do to avoid flickering:
    change line 71 of CLogo.cpp from:
    CRect UnionToolbarRect;
    to
    CRect UnionToolbarRect(0,0,0,0);

    I hope it works.
    Jakub

    Reply
  • Why does the logo fickle??

    Posted by Legacy on 04/27/2001 12:00am

    Originally posted by: pipi

    I notice that the logo fickle in a undesirable way in release build?? any suggestion?

    Reply
  • suggestion

    Posted by Legacy on 03/22/2001 12:00am

    Originally posted by: Romdles

    Having a create function take a set of parameters not needing change (the null, the style, and a rect of dimensions 0) seems silly to me. Rather, I would suggest you have some overloaded constructors or overloaded create functions:
    one that takes the string, and control bar
    another that takes string, control bar, and two uint bitmap identifiers

    This makes the whole thing easier and more obvious to implement. Just a suggestion.


    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • On-demand Event Event Date: December 18, 2014 The Internet of Things (IoT) incorporates physical devices into business processes using predictive analytics. While it relies heavily on existing Internet technologies, it differs by including physical devices, specialized protocols, physical analytics, and a unique partner network. To capture the real business value of IoT, the industry must move beyond customized projects to general patterns and platforms. Check out this webcast and join industry experts as …

  • Today's agile organizations pose operations teams with a tremendous challenge: to deploy new releases to production immediately after development and testing is completed. To ensure that applications are deployed successfully, an automatic and transparent process is required. We refer to this process as Zero Touch Deployment™. This white paper reviews two approaches to Zero Touch Deployment--a script-based solution and a release automation platform. The article discusses how each can solve the key …

Most Popular Programming Stories

More for Developers

RSS Feeds