• Advertisement
Sign in to follow this  

C++ - win32: can i change the menu font?

This topic is 541 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i did these code for try change the menu font, without OWNERDRAW it:

CHOOSEFONT ShowSelectFont()
{
    HWND hwnd=GetForegroundWindow();
    CHOOSEFONT cf = {sizeof(CHOOSEFONT)};
    LOGFONT* lf = new LOGFONT;
    HDC hdc=GetDC(hwnd);

    HFONT hlf =(HFONT) GetCurrentObject(hdc,OBJ_FONT);
    GetObject(hlf,sizeof(LOGFONT),lf);
    cf.Flags = CF_EFFECTS | CF_INITTOLOGFONTSTRUCT | CF_SCREENFONTS;
    cf.hwndOwner = hwnd;
    cf.lpLogFont = lf;
    cf.rgbColors =GetTextColor(hdc);
    ChooseFont(&cf);
    ReleaseDC(hwnd,hdc);
    cf.lpLogFont = lf;
    return cf;
}

//.......
CHOOSEFONT cf={0};
NONCLIENTMETRICS theMetrics;

cf=ShowSelectFont();//font dialog
            theMetrics.cbSize = sizeof(NONCLIENTMETRICS);

            SystemParametersInfo(SPI_GETNONCLIENTMETRICS,sizeof(NONCLIENTMETRICS),
                            (PVOID) &theMetrics,0);
            blnFirst=true;
            theMetrics.lfMenuFont=*cf.lpLogFont;
            SystemParametersInfo(SPI_SETNONCLIENTMETRICS,sizeof(NONCLIENTMETRICS),
                            (PVOID) &theMetrics,0);

the menu font is changed, but SystemParametersInfo() it's the system font(it's changed for all windows menu bar, all aplications.

can anyone advice me more?

i need just change on the window(HWND) and not all windows

Edited by cambalinho

Share this post


Link to post
Share on other sites
Advertisement

i'm trying it without sucess :(

on my form class i have:

void setFont(HFONT font)
        {
            if(SendMessage(hwnd, WM_SETFONT, (WPARAM) font, TRUE)!=WM_SETFONT)
                MessageBox(NULL, to_string(GetLastError()).c_str(), "error: font not chnaged", MB_OK);
        }

now see how i use it:

CHOOSEFONT ChFont={0};
ChFont=ShowSelectFont();
fb.setFont(CreateFontIndirect(ChFont.lpLogFont));//fb it's my form class object

the message box, on setFont, it's showed with zero. so no error? strange.

what i'm doing wrong?

Share this post


Link to post
Share on other sites

if(SendMessage(...) != WM_SETFONT)


...I'm not sure what you're trying to compare there.


https://msdn.microsoft.com/en-us/library/windows/desktop/ms644950(v=vs.85).aspx

"The return value specifies the result of the message processing; it depends on the message sent."

https://msdn.microsoft.com/en-us/library/windows/desktop/ms632642(v=vs.85).aspx

"This message does not return a value."



As for why it's not working, I can't remember whether menus do this or not, but forms are frequently composed of several nested HWNDs, each with its own settings. You may want to see if the menu itself has an HWND, whether the menu items inside it have HWNDs, etc. It's been ages since I've messed with Win32 so I don't remember if you're even allowed to change the font or not. Edited by Nypyren

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement