Solved

How to change the default menu font

Posted on 1998-05-11
6
463 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
while loop over for loop 7 115
only14 challenge 19 81
pre4 challenge 19 103
Sources to create infographic resume 2 17
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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…

809 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