Font wechseln bei Edit Control Fenster?



  • Hallo zusammen,

    ich habe mir eine MFC-Anwendung erstellt und nun möchte ich gerne
    den Font von einem "Edit Control" Fenster ändern.

    Standardmäßig ist es ja "Microsoft Sans Serif" und ich würde ihn gerne auf
    "Courier New" ändern...

    Kann mir da jemand weiterhelfen??

    Bitte um eure Tipps/Ratschläge...

    Danke und liebe Grüße Reinki :p



  • Schreib sowas in der Art in Dein OnInitDialog():

    int const point_size = 14;
        char const * font_name = "Arial";
    
    	CClientDC dc(::AfxGetMainWnd());
    	LOGFONT	logfont;
    	::ZeroMemory(&logfont, sizeof(LOGFONT));
    	logfont.lfHeight = -::MulDiv(point_size, dc.GetDeviceCaps(LOGPIXELSX), 72);
    	logfont.lfWeight = FW_BOLD;
    	logfont.lfItalic = TRUE;
    	logfont.lfOutPrecision = OUT_DEFAULT_PRECIS;
    	logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
    	logfont.lfQuality = DEFAULT_QUALITY;
    	logfont.lfPitchAndFamily = VARIABLE_PITCH | FF_SWISS;
    	strcpy(logfont.lfFaceName, font_name);
    	m_font.CreateFontIndirect(&logfont);
    
        .....
    
        GetDlgItem(IDC_EDIT1)->SetFont(&m_font);
    

    Wichtig ist, dass m_font eine Membervariable Deines Dialoges sein sollte, damit das Teil mit Beendigung von OnInitDialog() nicht "out of scope" geht. Sonst gibts Probleme 😃


Anmelden zum Antworten