Solved

How to change the default menu font

Posted on 1998-05-11
6
465 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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 77
Looking for a specific application/software 2 119
if loop in java 3 161
maven archtype selection in eclipse 1 58
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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…

756 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