Solved

How to change the default menu font

Posted on 1998-05-11
6
462 Views
Last Modified: 2013-12-02
I have an MFC app that uses a CFormView. The user needs to be able to see the menus from far away (I just write the app, I don't design them). So doing some prototyping in CBuilder they agreed upon using the standard system font for the menus, only bold. The only way I've seen to draw a menu is to override the DrawItem method in a CMenu object. Since the menu is a resource in my app I don't have a CMenu object to work with. How do I get the font changed for all menu items in my app? (or how do I derive a menu and attach it if that's the only way to change the menu font).
0
Comment
Question by:bsimser
6 Comments
 
LVL 1

Author Comment

by:bsimser
ID: 1309724
Adjusted points to 75
0
 
LVL 3

Expert Comment

by:byang
ID: 1309725
To get your menu object, just call CWnd::GetMenu.

You should derive a menu class, attach your main frame menu to it, then override DrawItem and MeasureItem.

0
 
LVL 7

Accepted Solution

by:
galkin earned 70 total points
ID: 1309726
Windows uses system menu font to draw text in all menus in all applications. You can query this font with SystemParametersInfo with SPI_GETNONCLIENTMETRICS flag and set it with SPI_SETNONCLIENTMETRICS flag. Menu font is lfMenuFont member of NONCLIENTMETRICS structure. If you want to use specific font for your application menus only you must  make your menu owner draw and draw text using your font


0
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
LVL 1

Author Comment

by:bsimser
ID: 1309727
Thanks to everyone. It's such a pain to change such a simple thing (IMHO). I still have a problem that I can't change the font on the top menu bar, only the popups but that's another issue...
0
 

Expert Comment

by:jit_sco
ID: 38249398
Hello

I am new in this community.The same task has given my cliente to me.I modiffy the
drawitem,i sucessfully done it ,but i could not able to change the color in the menubar.becuase the color of menu has not same color o same aspect as it has before.Please give me a solution.Help in level of coding
0
 

Expert Comment

by:jit_sco
ID: 38249405
Hereby i send the funtion of drawitem which i made
void CMyMenu::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
      CFont    *oldFont, MiFuente;
        LOGFONT logFuente;
      memset(&logFuente,0,sizeof(LOGFONT));
      
      logFuente.lfHeight =  16;
      logFuente.lfWidth = 7;
      logFuente.lfWeight = FW_BOLD;           //Negrita
      logFuente.lfOutPrecision = OUT_DEFAULT_PRECIS;
      logFuente.lfClipPrecision = CLIP_DEFAULT_PRECIS;
      logFuente.lfQuality = ANTIALIASED_QUALITY;
      logFuente.lfPitchAndFamily = FF_DONTCARE;
      strcpy(logFuente.lfFaceName,"Calibri"); //tipo letra
      
      MiFuente.DeleteObject();   /
      
      
      MiFuente.CreateFontIndirect(&logFuente);

      CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
      COLORREF colour = ::GetSysColor(COLOR_3DFACE);


      
      pDC->FillSolidRect(&lpDrawItemStruct->rcItem, colour);
      
      
      //if the menu item is selected
      //if ((lpDrawItemStruct->itemState & ODS_SELECTED) &&
            //(lpDrawItemStruct->itemAction & (ODA_SELECT | ODA_DRAWENTIRE)))
      //{
            //draw a blue background
            //pDC->FillSolidRect(&lpDrawItemStruct->rcItem, RGB(0,150,255));
      //}
      
      CMyMenuData* pMyMenuData = (CMyMenuData*)lpDrawItemStruct->itemData;
      CString str = pMyMenuData->m_strCaption;
 
      //draw the caption of the menu item
      pDC->TextOut(lpDrawItemStruct->rcItem.left,lpDrawItemStruct->rcItem.top, str);

      


}
0

Featured Post

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
font missing in acrobat 3 75
Gotham fonts and Office 2013 6 89
either24  challenge 19 97
moto 4g phone enable finger print 4 9
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question