Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CFONTDialog usage

CFONTDialog usage

Scheduled Pinned Locked Moved C / C++ / MFC
question
12 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    ForNow
    wrote on last edited by
    #1

    Hi, I would like to to display a certin amount of Characters om a line of a Rich Edit Dialog Box Seems line the EM_SETFORMAT message with the Charaformat Structure doesn't give me as much flexibility as the data in thr Logfont sturcture It seems Like CFONTdialog object give you more flexbility in setting a font of a dialog box My quetion is does the CFONTDialog OBJECT Actually display a Dialog Box ??? As it seems after Creating the Object The User needs to invoke the DoModal method to inquire or set the Font Values ???

    D I 2 Replies Last reply
    0
    • F ForNow

      Hi, I would like to to display a certin amount of Characters om a line of a Rich Edit Dialog Box Seems line the EM_SETFORMAT message with the Charaformat Structure doesn't give me as much flexibility as the data in thr Logfont sturcture It seems Like CFONTdialog object give you more flexbility in setting a font of a dialog box My quetion is does the CFONTDialog OBJECT Actually display a Dialog Box ??? As it seems after Creating the Object The User needs to invoke the DoModal method to inquire or set the Font Values ???

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      ForNow wrote:

      My quetion is does the CFONTDialog OBJECT Actually display a Dialog Box ???

      Only if you call its DoModal() method.

      "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

      F 1 Reply Last reply
      0
      • D David Crow

        ForNow wrote:

        My quetion is does the CFONTDialog OBJECT Actually display a Dialog Box ???

        Only if you call its DoModal() method.

        "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        F Offline
        F Offline
        ForNow
        wrote on last edited by
        #3

        IS there anything to get width of a charcter in a Rich Edit Control as Logfong has lfWidth

        F D 2 Replies Last reply
        0
        • F ForNow

          IS there anything to get width of a charcter in a Rich Edit Control as Logfong has lfWidth

          F Offline
          F Offline
          frx96
          wrote on last edited by
          #4

          CDC::GetTextExtent BOOL ok = FALSE; int richeditwidth = CRichEditCtrl::GetRect get richeditwidth CFont font = CRichEditCtrl::GetFont do{ 1.CDC::GetTextExtent get stringwidth 2.if(stringwidth < richeditwidth) { ok = TRUE; } else { font size -- CRichEditCtrl::SetFont } }while(!ok); hope this can help u .

          1 Reply Last reply
          0
          • F ForNow

            Hi, I would like to to display a certin amount of Characters om a line of a Rich Edit Dialog Box Seems line the EM_SETFORMAT message with the Charaformat Structure doesn't give me as much flexibility as the data in thr Logfont sturcture It seems Like CFONTdialog object give you more flexbility in setting a font of a dialog box My quetion is does the CFONTDialog OBJECT Actually display a Dialog Box ??? As it seems after Creating the Object The User needs to invoke the DoModal method to inquire or set the Font Values ???

            I Offline
            I Offline
            Iain Clarke Warrior Programmer
            wrote on last edited by
            #5

            This is a lot like the question you asked two days ago: http://www.codeproject.com/script/Forums/View.aspx?fid=1647&msg=2926253[^] You can't just stab in the dark guessing at things. If your question is: "I have a window X pixels wide. Given a certain font, how many characters can I fit in the window?" Unless the font is fixed width, then you have to ask the question the other way around. "I have a string. I have a font. How many pixels on the screen will it take up". That question you've had answered twice.

            GetTextExtent

            is your friend. I wish you luck - I'm sure you're getting very frustrated by now. Iain.

            Codeproject MVP for C++, I can't believe it's for my lounge posts...

            F 2 Replies Last reply
            0
            • I Iain Clarke Warrior Programmer

              This is a lot like the question you asked two days ago: http://www.codeproject.com/script/Forums/View.aspx?fid=1647&msg=2926253[^] You can't just stab in the dark guessing at things. If your question is: "I have a window X pixels wide. Given a certain font, how many characters can I fit in the window?" Unless the font is fixed width, then you have to ask the question the other way around. "I have a string. I have a font. How many pixels on the screen will it take up". That question you've had answered twice.

              GetTextExtent

              is your friend. I wish you luck - I'm sure you're getting very frustrated by now. Iain.

              Codeproject MVP for C++, I can't believe it's for my lounge posts...

              F Offline
              F Offline
              ForNow
              wrote on last edited by
              #6

              I am A Assembler MainFrame Programmer By Day I have always wanted to Move to Newer Things OO e.g. CRichEditCtrl pixels.... Are a whole new way thinking thankx for Being Patient with me .......................

              1 Reply Last reply
              0
              • F ForNow

                IS there anything to get width of a charcter in a Rich Edit Control as Logfong has lfWidth

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #7

                ForNow wrote:

                as Logfong has lfWidth

                You can still use the LOGFONT structure by first calling the GetLogFont() method. Something like:

                CFont* font = richeditctrl.GetFont();
                if (font)
                {
                LOGFONT lf;
                font>GetLogFont(&lf);
                TRACE("%ld", lf.lfWidth);
                }

                "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                F 1 Reply Last reply
                0
                • D David Crow

                  ForNow wrote:

                  as Logfong has lfWidth

                  You can still use the LOGFONT structure by first calling the GetLogFont() method. Something like:

                  CFont* font = richeditctrl.GetFont();
                  if (font)
                  {
                  LOGFONT lf;
                  font>GetLogFont(&lf);
                  TRACE("%ld", lf.lfWidth);
                  }

                  "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                  "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                  F Offline
                  F Offline
                  ForNow
                  wrote on last edited by
                  #8

                  I have been coding most this app in C seems like this might be a good time be a good time to go C++ OO MFC Cricheditctrl, etc

                  1 Reply Last reply
                  0
                  • I Iain Clarke Warrior Programmer

                    This is a lot like the question you asked two days ago: http://www.codeproject.com/script/Forums/View.aspx?fid=1647&msg=2926253[^] You can't just stab in the dark guessing at things. If your question is: "I have a window X pixels wide. Given a certain font, how many characters can I fit in the window?" Unless the font is fixed width, then you have to ask the question the other way around. "I have a string. I have a font. How many pixels on the screen will it take up". That question you've had answered twice.

                    GetTextExtent

                    is your friend. I wish you luck - I'm sure you're getting very frustrated by now. Iain.

                    Codeproject MVP for C++, I can't believe it's for my lounge posts...

                    F Offline
                    F Offline
                    ForNow
                    wrote on last edited by
                    #9

                    Hi, I wanted to do research before asking CRichEditCtr is a derived Class wHose Base Class is Cwnd GetTextExtent is a member of Class CDC thankx again I am on my way to MFC

                    I 1 Reply Last reply
                    0
                    • F ForNow

                      Hi, I wanted to do research before asking CRichEditCtr is a derived Class wHose Base Class is Cwnd GetTextExtent is a member of Class CDC thankx again I am on my way to MFC

                      I Offline
                      I Offline
                      Iain Clarke Warrior Programmer
                      wrote on last edited by
                      #10

                      There are many sources of confusion here. CRichEditCtrl is a C++ object, whose base class is CWnd - true. But both of these are just handy C++ abstractions of the underlying Windows types. CWnd wraps a generic HWND handle. CRichEditCtrl wraps up an HWND handle of a RICHEDIT window type, so it accepts extra messages. A DC is a Device Context, and is a windows thingy that represents a drawing surface - whether that's a screen, a printer, or a pure memory area. A CDC is the MFC C++ class that wraps up an HDC (handle to DC) variable from windows. If you look at the code for almost any CDC member function, you'll find it calls window functions pretty immediately. In order to show things on the screen, the OS passes messages to WNDS asking them to draw on a DC. So, the main message for this is WM_PAINT. The OS knows that a window needs to redraw on the screen, and send this message to a window - and the message handler will call BeginPaint to get a drawing surface ready to draw on to. All of this work is wrapped up for you in MFC, and your CView derived class has an OnDraw member function with a CDC* parameter all ready fot you to work on. I'm not going into much more detail - that's what books are for, not replies on this forum, but I hope it gives you some direction for your research. Now on to your specifics... If I understand you correctly, you want to know if a bit of text using a specific font will fit into a certain area. You've guessed at CRichEditCtrl, and you've guessing at CFontDialog, and neither have helped all that much. There is no "throw away letters until this fits" routine - largely because windows has no idea which words / letters will be important to you. That's *your* job. But you can reverse the problem and find out how much room a given string will take up. Then chops bits away yourself until it fits. Have a look at the following code, and make sure you look up the functions, as this is from memory...

                      CSize CMyDialog::GetSizeOfString (CString sTest, CLogFont *lf) // passing a string, and a logfont struct to define the font we're testing
                      {
                      CDC *pDC = GetDC (); // calls CWnd::GetDC
                      CFont fTest;
                      fTest.CreateFontIndirect (lf); // make a CFont object from our logfont.

                      CFont \*fOld = pDC->SelectObject (&fTest); // tell the surface to use our font - but keep track of the font it had before
                      
                      CSize sz = pDC->GetTextExtent (sTest); // ask windows to calculate how much room this text / font will take up if it was to be drawn.
                      
                      pDC->
                      
                      F 1 Reply Last reply
                      0
                      • I Iain Clarke Warrior Programmer

                        There are many sources of confusion here. CRichEditCtrl is a C++ object, whose base class is CWnd - true. But both of these are just handy C++ abstractions of the underlying Windows types. CWnd wraps a generic HWND handle. CRichEditCtrl wraps up an HWND handle of a RICHEDIT window type, so it accepts extra messages. A DC is a Device Context, and is a windows thingy that represents a drawing surface - whether that's a screen, a printer, or a pure memory area. A CDC is the MFC C++ class that wraps up an HDC (handle to DC) variable from windows. If you look at the code for almost any CDC member function, you'll find it calls window functions pretty immediately. In order to show things on the screen, the OS passes messages to WNDS asking them to draw on a DC. So, the main message for this is WM_PAINT. The OS knows that a window needs to redraw on the screen, and send this message to a window - and the message handler will call BeginPaint to get a drawing surface ready to draw on to. All of this work is wrapped up for you in MFC, and your CView derived class has an OnDraw member function with a CDC* parameter all ready fot you to work on. I'm not going into much more detail - that's what books are for, not replies on this forum, but I hope it gives you some direction for your research. Now on to your specifics... If I understand you correctly, you want to know if a bit of text using a specific font will fit into a certain area. You've guessed at CRichEditCtrl, and you've guessing at CFontDialog, and neither have helped all that much. There is no "throw away letters until this fits" routine - largely because windows has no idea which words / letters will be important to you. That's *your* job. But you can reverse the problem and find out how much room a given string will take up. Then chops bits away yourself until it fits. Have a look at the following code, and make sure you look up the functions, as this is from memory...

                        CSize CMyDialog::GetSizeOfString (CString sTest, CLogFont *lf) // passing a string, and a logfont struct to define the font we're testing
                        {
                        CDC *pDC = GetDC (); // calls CWnd::GetDC
                        CFont fTest;
                        fTest.CreateFontIndirect (lf); // make a CFont object from our logfont.

                        CFont \*fOld = pDC->SelectObject (&fTest); // tell the surface to use our font - but keep track of the font it had before
                        
                        CSize sz = pDC->GetTextExtent (sTest); // ask windows to calculate how much room this text / font will take up if it was to be drawn.
                        
                        pDC->
                        
                        F Offline
                        F Offline
                        ForNow
                        wrote on last edited by
                        #11

                        Hi, I have always been a sync (mispelled) but if I were to pay for course on MFC it WOULD cost quite a lot of money it nice to see some people helping out others for Free Again My Background is MainFrame Assembler Internals worked for IBM in poughkeepsie on the MainFrame OS This is a different way of thinking ....OO I am going to do research on what you just sent I am also going to read MFC C++ CLasses Book by Shirley Wodtke thankx so much for your help BTW the Window / Control I am inquiring about is a Edit Class of a Dialog Box all the Messages mentioned above e.g. WM_PAINT I have seen in Controls Were the Parent Window is a Regular Window Not were the parent Window IS dailog Box Hope my next question will be more intellgient PS quite Early Here in the US on the East Coast White Plains NY off to the GYM and then work (MainFrame PRog) will do research on what you just sent Thankx Again

                        I 1 Reply Last reply
                        0
                        • F ForNow

                          Hi, I have always been a sync (mispelled) but if I were to pay for course on MFC it WOULD cost quite a lot of money it nice to see some people helping out others for Free Again My Background is MainFrame Assembler Internals worked for IBM in poughkeepsie on the MainFrame OS This is a different way of thinking ....OO I am going to do research on what you just sent I am also going to read MFC C++ CLasses Book by Shirley Wodtke thankx so much for your help BTW the Window / Control I am inquiring about is a Edit Class of a Dialog Box all the Messages mentioned above e.g. WM_PAINT I have seen in Controls Were the Parent Window is a Regular Window Not were the parent Window IS dailog Box Hope my next question will be more intellgient PS quite Early Here in the US on the East Coast White Plains NY off to the GYM and then work (MainFrame PRog) will do research on what you just sent Thankx Again

                          I Offline
                          I Offline
                          Iain Clarke Warrior Programmer
                          wrote on last edited by
                          #12

                          The edit control still has code handling WM_PAINT... it just does it on your behalf. Same with a BUTTON control. The principles are the same. And yes, this message driven stuff does take a mental shift. Good luck with it though! Iain.

                          Codeproject MVP for C++, I can't believe it's for my lounge posts...

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups