CFONTDialog usage
-
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 ???
-
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 ???
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
-
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
-
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 .
-
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 ???
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...
-
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...
-
ForNow wrote:
as Logfong has lfWidth
You can still use the
LOGFONT
structure by first calling theGetLogFont()
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
-
ForNow wrote:
as Logfong has lfWidth
You can still use the
LOGFONT
structure by first calling theGetLogFont()
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
-
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...
-
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
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->
-
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->
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
-
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
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...