Announcement

Collapse
No announcement yet.

How can you set the font of a menu?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How can you set the font of a menu?

    It is simple to set a specific font in a dialog or in a control using the %WM_SETFONT message. That does not seem to work for menus. Is there a simple way to set the font of a menu?

    Thanks in advance for your help.

  • #2
    No. You have owner-draw the item or use a bitmap (with the caption text as a graphic) instead of text for the menu item.
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Actually, you can.
      SystemParametersInfo(SPI_SETNONCLIENTMETRICS). This is a system setting, therefore, leave it alone.
      You can either use owner-draw as Micheal suggested, or use a menubar control.
      Dominic Mitchell
      Phoenix Visual Designer
      http://www.phnxthunder.com

      Comment


      • #4
        Thanks.

        Yes it seems not that simple. There are a few source code examples around in the Forum. However, I cannot get them to work properly. I found this link, where the technique is explained. It may be worth studying.

        Comment


        • #5
          Dominic,

          Would it be possible to 1) save the system data obtained using SystemParametersInfo(SPI_GETNONCLIENTMETRICS) in the program, 2) then change the menu-font in the program using SystemParametersInfo(SPI_SETNONCLIENTMETRICS), and finally on termination of the program using the WM_DESTROY message 3) reset the original system data using SystemParametersInfo(SPI_SETNONCLIENTMETRICS) once more? You say this method should not be used, but is it dangerous in any way for the future operation of the system?

          Comment


          • #6
            You say this method should not be used, but is it dangerous in any way for the future operation of the system?
            If "dangerous " includes the user coming after you with a large blunt object and intent to main because you changed his system setttings and now his other programs are screwed up, then yes, it is dangerous.

            BTW if you can find the Petzold conversions (I know they are here somewhere), one of the example programs is all about owner-drawn menus including bit-map menu items.

            MCM
            Michael Mattias
            Tal Systems (retired)
            Port Washington WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #7
              Forum: http://www.jose.it-berater.org/smfforum/index.php

              Comment


              • #8
                You can use code similar to that shown below. The problem is that changing the menu font
                on the system might make your users very unhappy. I would certainly be miffed if when I started an app, the menu font on all windows that are open suddenly changed.

                At start.
                Code:
                  LOCAL tncm        AS NONCLIENTMETRICS
                  STATIC tlf        AS LOGFONT
                  
                  tncm.cbSize = SIZEOF(tncm)
                  SystemParametersInfo %SPI_GETNONCLIENTMETRICS, SIZEOF(tncm), BYVAL VARPTR(tncm), 0
                  tlf = tncm.lfMenuFont
                  ' Menu bold font   
                  tncm.lfMenuFont.lfHeight = -15
                  tncm.lfMenuFont.lfWeight = %FW_BOLD
                  SystemParametersInfo %SPI_SETNONCLIENTMETRICS, SIZEOF(tncm), BYVAL VARPTR(tncm), 0
                At shutdown
                Code:
                  tncm.cbSize = SIZEOF(tncm)
                  SystemParametersInfo %SPI_GETNONCLIENTMETRICS, SIZEOF(tncm), BYVAL VARPTR(tncm), 0
                  tncm.lfMenuFont.lfHeight = tlf.lfHeight
                  tncm.lfMenuFont.lfWeight = tlf.lfWeight
                  SystemParametersInfo %SPI_SETNONCLIENTMETRICS, SIZEOF(tncm), BYVAL VARPTR(tncm), 0
                0 can be replaced with one or more of SPIF_UPDATEINIFILE, SPIF_SENDCHANGE and SPIF_SENDWININICHANGE.
                Dominic Mitchell
                Phoenix Visual Designer
                http://www.phnxthunder.com

                Comment


                • #9
                  Thanks a lot for your very fine comments and help.

                  The problem is that changing the menu font on the system might make your users very unhappy. I would certainly be miffed if when I started an app, the menu font on all windows that are open suddenly changed.
                  I agree, but I guess the problem could be reduced somewhat, if you also restore the system font when your program is being minimized or loses focus. Upon reactivation your program could change back to its own menu font. In any case you should only use a font slightly different from the systems menu font.
                  Last edited by Erik Christensen; 5 Jan 2008, 05:58 AM.

                  Comment


                  • #10
                    José,

                    The #RESOURCE "GRAFMENU.PBR" file seems not available in your link.

                    Comment


                    • #11
                      I managed to have a code working. It is a slightly modified code based on an example by Semen Matusovski. His code was probably inspired by the code in the Microsoft link presented previously in this thread. I posted the code in the source code forum:



                      Thanks again for your assistance.

                      Comment


                      • #12
                        I haven't tried this and I'm just thinking out loud but how about creating a registry key and then use RegOverridePredefKey. Any changes made will be process specific. Of course, we need to know which keys to map.

                        Comment


                        • #13
                          I made some small changes in the code in the source code forum referred to in my previous post. Now the menu BAR font is also user defined. The code can be further refined by conforming in greater detail with the Microsoft example referred to previously.

                          The resulting code is a lot simpler than if bitmaps would also be needed in the menu. The secret is the 'ExtTextOut' function.

                          Concerning Bitmaps Borje Hagsten has made a fine code some years back. See this link:

                          Look for: 'DrawMenu' under the heading: Samples and Utilities - Public Domain
                          Last edited by Erik Christensen; 6 Jan 2008, 03:30 PM.

                          Comment


                          • #14
                            >... managed to have a code working

                            PLEASE say, "You know, once I actually tried owner-drawing the menu items , it really was not all that difficult. It took a little experimentation to figure out when to do certain things, but in retrospect it all makes sense now."
                            Michael Mattias
                            Tal Systems (retired)
                            Port Washington WI USA
                            [email protected]
                            http://www.talsystems.com

                            Comment


                            • #15
                              A new - perhaps slightly improved - example is posted in the source code forum, see this link, second post:

                              Comment


                              • #16
                                See also the very fine last code in this link:

                                Comment

                                Working...
                                X