Displaying a Company Logo on the Menu Bar

Click here for a larger image.
Environment: VC6 SP5, NT4
I have searched the entire Web and tried every resource at my disposal to display a company logo on the Menu Bar, but all my efforts went in vain. Finally, I did R&D and came out with a new and simple way to display a company logo on the Menu Bar without subclassing CControlBar.
It is always possible to find out the coordinate of the Menu Bar by calculating the position of placing the company logo on the Menu Bar. But, calculating coordinates and drawing a bitmap at that position needs to called every time a view is maximized or restored. And, also particularly, when the main windows width is reduced, the company logo needs to be moved to the next line in the Menu Bar if it doesn't fit in the first line.
Following is the procedure to overcome the preceding problems.
- Create a menu item in the view's menu resource and mainframe's menu resource with a unique ID (let's say ID_HARIKRISHNA). Uncheck the Popup menu check box.
- Now, open the resource file (yourproject.rc file), go to the menu resource block, and add following flags for the above menu item.
Ex. For the menuitem named "harikrishna"
MENUITEM "harikrishna", ID_HARIKRISHNA, MFT_STRING | MFT_OWNERDRAW | MFT_RIGHTJUSTIFY,MFS_ENABLED - Now, override the OnMeasureItem CMainfrm class.
- Add the following code in OnMeasureItem:
- Add the following code in the OnDrawItem method.
void CMainFrame::OnMeasureItem(int nIDCtl,
LPMEASUREITEMSTRUCT lpMeasureItemStruct)
{
if (ID_HARIKRISHNA == lpMeasureItemStruct->itemID
&& ODT_MENU
== lpMeasureItemStruct->CtlType )
{
CBitmap bitmap;
bitmap.LoadBitmap(IDB_BITMAP1);
// IDB_BITMAP1 is the bitmap resource that you want to
// display on the Menu Bar
CSize size = bitmap.GetBitmapDimension();
BITMAP bm;
GetObject(bitmap.GetSafeHandle(), sizeof(bm), &bm);
lpMeasureItemStruct->itemWidth = bm.bmWidth;
lpMeasureItemStruct->itemHeight = bm.bmHeight;
}
else
{
CMDIFrameWnd::OnMeasureItem(nIDCtl, lpMeasureItemStruct);
}
}
void CMainFrame::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT
lpDrawItemStruct)
{
if (ID_HARIKRISHNA == lpDrawItemStruct ->itemID
&& ODT_MENU
== lpDrawItemStruct ->CtlType )
{
CBitmap bitmap;
bitmap.LoadBitmap(IDB_BITMAP1);
// IDB_BITMAP1 points to the BMP resource of your company
// logo.
HDC hTempDC = ::CreateCompatibleDC(lpDrawItemStruct->hDC);
::SelectObject(hTempDC,bitmap.GetSafeHandle());
BitBlt(lpDrawItemStruct->hDC,
lpDrawItemStruct->rcItem.left,
lpDrawItemStruct->rcItem.top,
lpDrawItemStruct->rcItem.right,
lpDrawItemStruct->rcItem.bottom,hTempDC,
0,0,SRCCOPY);
}
else
CMDIFrameWnd::OnDrawItem(nIDCtl, lpDrawItemStruct);
}
That's it. You are done.
There are some points that need to be taken care of:
- You need to add an extra menu item in all resources that you use in your project.
- The ID of the menu item resource needs to be unique, particularly if you are merging code with already existing projects. Make sure the ID of company logo menu item doesn't contradict already existing IDs.
And the environment in which the following code was tested is Window 2000 and WinNT 4.0. It should also work in on operating systems greater than Windows 95 because the Menu flags MFT_RIGHTJUSTIFY exist only those operating systems. And I have built the above code only on VC6.0.

Comments
Fix "not recognized" JUSTIFYRIGHT etc.
Posted by Legacy on 11/19/2003 12:00amOriginally posted by: Brian
Open the .rc file in note pad. In an MDI app, only add to the MDI CHILD menu area. after the END of the last "regular" menu. but before the END of the menu area.
END
MENUITEM "", ID_MYMENUITEMID, OWNERDRAW
END
Just use OWNERDRAW nothing else required. You should probably add this as last thing you do with menu, if you edit your menu with the menu wizard, you will likely have to reopen the .rc and append , OWNERDRAW again and again.
if you want the item to be right justified. go into the menu wizard, right click the blank area that represents this new menu item, click properties, in the menuitem properties, just choose true for right justified. thow agian likely have to go into note pad and append , OWNERDRAW as your final step.
read my next entry for good tip on avoiding drawing issues.
Replyfonts in menu bar
Posted by Legacy on 05/18/2003 12:00amOriginally posted by: Bui Tan Duoc
How can I change font in the main menu bar of my application only ? Please help me, thanks much !
Replydon't recognize MFT_STRING | MFT_OWNERDRAW | MFT_RIGHTJUSTIFY,MFS_ENABLED
Posted by Legacy on 05/01/2003 12:00amOriginally posted by: Dafna Zamir
I use sdi application. After adding the types MFT_STRING | MFT_OWNERDRAW | MFT_RIGHTJUSTIFY,MFS_ENABLED closing the .rc file and the resource (in an automatic mannar) visual 6 prompt the message: unkown menu subtype.
How can I resolve this?
-
-
Reply
ReplyMENUEX
Posted by wolfgangjia on 09/13/2005 11:39pmUse MENUEX resource language instead of MENU
ReplyModifyMenu
Posted by David Smulders on 07/06/2004 11:07amDoes this work for an SDI
Posted by Legacy on 12/18/2002 12:00amOriginally posted by: JM
Can't seem to get this to work for an SDI application. Any thoughts?
Replycompany logo on the menubar
Posted by Legacy on 12/16/2002 12:00amOriginally posted by: rajasekar
Replyhello
Posted by Legacy on 12/14/2002 12:00amOriginally posted by: BARADHI
ReplyLogo on Menubar.
Posted by Legacy on 12/12/2002 12:00amOriginally posted by: Srinivasa Raju Bhairraju
Reply