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

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read