Click here to Skip to main content
15,912,205 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: CFONTDialog usage Pin
ForNow17-Feb-09 13:07
ForNow17-Feb-09 13:07 
GeneralRe: CFONTDialog usage Pin
frx9617-Feb-09 14:50
frx9617-Feb-09 14:50 
GeneralRe: CFONTDialog usage Pin
David Crow18-Feb-09 3:02
David Crow18-Feb-09 3:02 
GeneralRe: CFONTDialog usage Pin
ForNow18-Feb-09 12:41
ForNow18-Feb-09 12:41 
AnswerRe: CFONTDialog usage Pin
Iain Clarke, Warrior Programmer18-Feb-09 0:27
Iain Clarke, Warrior Programmer18-Feb-09 0:27 
GeneralRe: CFONTDialog usage Pin
ForNow18-Feb-09 2:09
ForNow18-Feb-09 2:09 
GeneralRe: CFONTDialog usage Pin
ForNow18-Feb-09 17:09
ForNow18-Feb-09 17:09 
GeneralRe: CFONTDialog usage Pin
Iain Clarke, Warrior Programmer18-Feb-09 22:17
Iain Clarke, Warrior Programmer18-Feb-09 22:17 
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->SelectObject (fOld); // always put the DC back the way it was. 99%of the time it won;t matter. 1% of the time it will kill you in your bed. With a kipper.

    ReleaseDC (pDC); // give the DC back to the OS for some other window to draw on

    return sz;
}


When you're more used to it, you could have used CClientDC dc (this);, as it wraps the GetDC and ReleaseDC calls to make it harder for you to make mistakes.

I hope that provides some enlightenment! It sounds like you've got quite a long way to go - but people here will be happy to help with specific questions (ie, we can't teach you MFC in two or three replies) as long as you ask well phrased questions and can show you've tried yourself already. (which you did)

Iain.

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

GeneralRe: CFONTDialog usage Pin
ForNow18-Feb-09 23:04
ForNow18-Feb-09 23:04 
GeneralRe: CFONTDialog usage Pin
Iain Clarke, Warrior Programmer18-Feb-09 23:17
Iain Clarke, Warrior Programmer18-Feb-09 23:17 
QuestionReturn Code from EM_GETCHARFORMAT Pin
ForNow17-Feb-09 6:36
ForNow17-Feb-09 6:36 
QuestionRe: Return Code from EM_GETCHARFORMAT Pin
David Crow17-Feb-09 6:38
David Crow17-Feb-09 6:38 
AnswerRe: Return Code from EM_GETCHARFORMAT Pin
ForNow17-Feb-09 7:14
ForNow17-Feb-09 7:14 
AnswerRe: Return Code from EM_GETCHARFORMAT Pin
krmed18-Feb-09 0:39
krmed18-Feb-09 0:39 
Questionadaptive niblack algorithm Pin
Bindas Samanta17-Feb-09 4:14
Bindas Samanta17-Feb-09 4:14 
AnswerRe: adaptive niblack algorithm Pin
Stuart Dootson17-Feb-09 4:31
professionalStuart Dootson17-Feb-09 4:31 
JokeRe: adaptive niblack algorithm Pin
SandipG 17-Feb-09 4:54
SandipG 17-Feb-09 4:54 
GeneralRe: adaptive niblack algorithm Pin
Stuart Dootson17-Feb-09 6:02
professionalStuart Dootson17-Feb-09 6:02 
JokeRe: adaptive niblack algorithm Pin
CPallini17-Feb-09 22:07
mveCPallini17-Feb-09 22:07 
Questioncreate file directly Pin
josip cagalj17-Feb-09 2:04
josip cagalj17-Feb-09 2:04 
AnswerRe: create file directly Pin
«_Superman_»17-Feb-09 2:26
professional«_Superman_»17-Feb-09 2:26 
AnswerRe: create file directly Pin
Stuart Dootson17-Feb-09 2:44
professionalStuart Dootson17-Feb-09 2:44 
GeneralRe: create file directly Pin
josip cagalj17-Feb-09 3:23
josip cagalj17-Feb-09 3:23 
GeneralRe: create file directly Pin
«_Superman_»17-Feb-09 4:05
professional«_Superman_»17-Feb-09 4:05 
GeneralRe: create file directly Pin
Stuart Dootson17-Feb-09 4:15
professionalStuart Dootson17-Feb-09 4:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.