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

Started by
5 comments, last by cambalinho 7 years, 5 months ago

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

Advertisement

The WM_SETFONT message can set the font of a specific window.

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

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?

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.

i'm trying testing if the SendMessage() is done sucess... without errors. but the window font isn't changed :(

You might have to resort to owner draw menus:

https://msdn.microsoft.com/en-us/library/ms647558.aspx#_win32_Creating_Owner_Drawn_Menu_Items

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

yes. for change the font, i must do:

1 - on control creation(if realy works);

2 - when we draw the controls.

This topic is closed to new replies.

Advertisement