Click here to Skip to main content
12,511,494 members (53,452 online)
Click here to Skip to main content
Add your own
alternative version

Stats

158.2K views
1.8K downloads
68 bookmarked
Posted

Insert your Logo between caption bar and menu bar

, 16 Jan 2000
Rate this:
Please Sign up or sign in to vote.
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. :)

  1. Create a dialog based project ( need not care whether SDI or MDI )

    Project name : Fake Real Player.

  2. Insert your Logo bitmap file in your project.

    Logo name : IDB_LOGO

  3. 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)

  4. Enlarge your IDM_IMAGE menu width to make room for logo in the OnMeasureItem() 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);
    }
  5. 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;
  6. Make a DrawLogo() method to paint your Logo Bitmap.
    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);    
    }
  7. Override your OnInitMenu() method and OnSystemMenu() 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);
        }
    }
  8. 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

Share

About the Author

Wooseok Seo
Software Developer (Senior)
Korea (Republic of) Korea (Republic of)
Woo Seok Seo have been a Microsoft MVP for 7 years and have translated several books into Korean. Author of C# Programming for Beginner (DevPress, 2001), he is interested in Debugging techniques and .NET technology. Get in touch with Woo Seok Seo at wooseok.seo@gmail.com

You may also be interested in...

Pro
Pro

Comments and Discussions

 
GeneralWindows VISTA 64 bit issue Pin
Neptunex10-Jun-07 0:03
memberNeptunex10-Jun-07 0:03 
GeneralRe: Windows VISTA 64 bit issue Pin
The Dogcow Farmer2-Oct-08 11:42
memberThe Dogcow Farmer2-Oct-08 11:42 
GeneralOn the other hand.... Pin
GuyLeckyT10-Jun-05 3:58
memberGuyLeckyT10-Jun-05 3:58 
GeneralSDI Pin
fouadfana21-Apr-04 2:41
memberfouadfana21-Apr-04 2:41 
Generallogo doesn't always appear Pin
seeking answer7-Sep-03 19:08
sussseeking answer7-Sep-03 19:08 
GeneralDC not Delete In DrawLogo() Pin
Anonymous19-Mar-02 15:48
memberAnonymous19-Mar-02 15:48 
GeneralPut the icon in a different place Pin
The Eclypse21-Oct-01 8:28
memberThe Eclypse21-Oct-01 8:28 
Generalthe line between titlebar and menubar in SDI after modifying SysMenu Pin
rk3218-Jun-01 3:52
memberrk3218-Jun-01 3:52 
GeneralAdding A bitmap to a popup menu Pin
guy24-Aug-00 4:59
sussguy24-Aug-00 4:59 
Generalyou can find resource at Pin
Smile Seo24-Aug-00 13:30
sussSmile Seo24-Aug-00 13:30 
GeneralRe: you can find resource at Pin
guy28-Aug-00 22:13
sussguy28-Aug-00 22:13 
GeneralRe: you can find resource at Pin
Smoogle28-Oct-00 16:49
sussSmoogle28-Oct-00 16:49 
GeneralGreat, but... Pin
Alan17-Jul-00 16:26
sussAlan17-Jul-00 16:26 
Generalvery easy, make it on SDI and MDI project!!! Pin
Elton LAU10-Jul-00 16:47
sussElton LAU10-Jul-00 16:47 
GeneralThanks.. Pin
Smile Seo10-Jul-00 18:06
sussSmile Seo10-Jul-00 18:06 
GeneralRe: very easy, make it on SDI and MDI project!!! Pin
Matt Philmon9-Nov-00 8:53
memberMatt Philmon9-Nov-00 8:53 
GeneralI have succeeded to make this work on a SDI Project Pin
Adun4-Jul-00 5:40
sussAdun4-Jul-00 5:40 
GeneralThanks Adun.. Pin
Smile Seo4-Jul-00 7:52
sussSmile Seo4-Jul-00 7:52 
GeneralRe: I have succeeded to make this work on a SDI Project Pin
angel_10-Jan-02 20:55
memberangel_10-Jan-02 20:55 
GeneralRe: I have succeeded to make this work on a SDI Project Pin
Janapriya28-Mar-04 5:00
memberJanapriya28-Mar-04 5:00 
QuestionI can't get the project to work for an SDI application? Pin
Erich J. Ruth8-Jun-00 12:22
sussErich J. Ruth8-Jun-00 12:22 
GeneralSDI Menu, not dialog based. Pin
Mark Janveaux11-Feb-00 8:37
sussMark Janveaux11-Feb-00 8:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160929.1 | Last Updated 17 Jan 2000
Article Copyright 2000 by Wooseok Seo
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid