CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2012
    Posts
    2

    Question Mfc..how to change font of string with menu button

    I need some help.i want create menu button to change font of CString displyed in main window.
    We can see string "SAMPLE",and when i press menu button that i created i want to string "SAMPLE" to display with difrent font,i alreday created CFont object and added italic style with CreateFont;


    this is my menu function:and CString m_text and CFont font1 are declared in FesbDoc.h

    ON_COMMAND(ID_EDIT_FONT, &CFesbView::OnEditFont)

    void CFesbView::OnEditFont()
    {
    CFesbDoc* pDoc = GetDocument();
    ::::WHAT TO ADD HERE:::::::


    Invalidate();
    }
    Thanks.

  2. #2
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,042

    Re: Mfc..how to change font of string with menu button

    Have a look at the CFontDialog class.
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

  3. #3
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    Re: Mfc..how to change font of string with menu button

    vatralaus
    Could you please clarify?
    Are you having problem with changing font of the displayed text or you have a problem with font typeface selection?
    What is the type (class) of the window you use to display text?
    Could you post a snippet of the code you have a problem with?
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  4. #4
    Join Date
    Dec 2012
    Posts
    2

    Re: Mfc..how to change font of string with menu button

    I am haveing problem changing font of the displayed text.
    it is MFC aplication.
    In the big white window "not dialog" we can see just text (just simple string object) lets say """CODE GURU""".so what i whant is to create simple toolbox button and when i press it """CODE GURU""" text that is already displayed to change font.
    Here is my button action.
    Code:
    ON_COMMAND(ID_EDIT_FONT, &CFesbView::OnEditFont)
    
    void CFesbView::OnEditFont()
    {
    CFesbDoc* pDoc = GetDocument();
    
    //this is my button action.
    //so what woud go here
    
    
    Invalidate();
    }

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Mfc..how to change font of string with menu button

    To change a font for a window you have to:
    1. create a new font (CFont object)
    2. set this new font object to the window (using CWnd::SetFont method)
    3. note that CFont object must "live" until your window lives (or until you set another font to this window)
    Victor Nijegorodov

  6. #6
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    Re: Mfc..how to change font of string with menu button

    Is your view derived from CRichEditView?
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured