Solved

How to change the default menu font

Posted on 1998-05-11
6
458 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Replacement selected text 2 47
Change owner from userA to server Local Administrators 7 51
sum67 challenge 35 89
no14 challenge 14 56
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: 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…
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now