Insert your Logo between Caption Bar and Menu Bar






4.33/5 (8 votes)
Jan 17, 2000

173784

2005
Give your apps a unique look by adding a logo to your menu
Introduction
The Real-Player program inserts its logo between the caption bar and menu bar. If you ever wanted to do this, then just follow me. :)
- Create a dialog based project (need not care whether SDI or MDI)
Project name: Fake Real Player
- Insert your Logo bitmap file in your project.
Logo name:
IDB_LOGO
- To make room for drawing your logo, insert a temporary menu item in your default menu resource like 'menu for Image' at the first position.
resource ID:
IDM_IMAGE
, no popup menu - Enlarge your
IDM_IMAGE
menu width to make room for logo in theOnMeasureItem()
method:void CFakeRealDlg::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct) { if (lpMeasureItemStruct->CtlType == ODT_MENU) { if (lpMeasureItemStruct->itemID == IDM_IMAGE) lpMeasureItemStruct->itemWidth = m_rectLogo.Width() + 5; } CDialog::OnMeasureItem(nIDCtl, lpMeasureItemStruct); }
- Load your Logo bitmap file in your
OnInitDialog()
method.m_hBmp = (HBITMAP)LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_LOGO), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION); BITMAP bm; GetObject(m_hBmp, sizeof(bm), &bm); m_rectLogo.left = 15; m_rectLogo.right = 15 + bm.bmWidth; m_rectLogo.top = 2 ; m_rectLogo.bottom = 2 + bm.bmHeight;
- Make a
DrawLogo()
method to paint your LogoBitmap
.void CFakeRealDlg::DrawLogo() { CDC* pdc= GetWindowDC(); CDC memdc; memdc.CreateCompatibleDC(pdc); memdc.SelectObject(m_hBmp); pdc->BitBlt(15, 2, m_rectLogo.Width(), m_rectLogo.Height(), &memdc, 0, 0, SRCCOPY); ReleaseDC(pdc); }
- Override your
OnInitMenu()
method andOnSystemMenu()
to protect Window draw line between the caption bar and the menu bar.void CFakeRealDlg::OnInitMenu(CMenu* pMenu) { CDialog::OnInitMenu(pMenu); // Important!! DrawLogo(); } void CFakeRealDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { // Important!!! DrawLogo(); CDialog::OnSysCommand(nID, lParam); } }
- Override your
OnNcPaint()
to paint your Logo whenever FakeReal is shown.void CRealDlg::OnNcPaint() { // Default is equal // 'CDialog::OnNcPaint()' .. :) Default(); // Important!!! DrawLogo(); }
Steps 1~8 show you what you must do, but you may want to perfect this sample. For example, you may want to add an owner-draw caption to hide the system icon. If you upgrade this sample, I'll be very happy. Have a nice day!!!
Member of Ajou University Computer Club - C.C.
License
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt, please contact the author via the discussion board below.
A list of licenses authors might use can be found here.