CEdit View Headache 
Author Message
 CEdit View Headache

I'm new to MFC and have banged my head for days trying to figure out this
obviously simple problem. Please help, I'm running out of aspirin. I simply
want to change the font displayed by the CEditView object. I've done this so
far:

// Add member variables to CEditView
CFont m_MyFont
CEdit& m_EditCtrl GetEditCtrl()

// This code added to CEditView ctor
// Create font
m_MyFont.CreateFont(...)
// Set font
m_EditCtrl.SetFont(&m_MyFont)

Everything compiles fine. When I run the program, I receive an assertion
failure message. Ignoring the message, the program executes, but with the
default system font, not my custom font.

Thanks for your help,

Thomas



Fri, 10 Aug 2001 03:00:00 GMT  
 CEdit View Headache
    Where was this code of yours included ?
    What assertion is displayed ?
    Jacques

Quote:

>I'm new to MFC and have banged my head for days trying to figure out this
>obviously simple problem. Please help, I'm running out of aspirin. I simply
>want to change the font displayed by the CEditView object. I've done this
so
>far:

>// Add member variables to CEditView
>CFont m_MyFont
>CEdit& m_EditCtrl GetEditCtrl()

>// This code added to CEditView ctor
>// Create font
>m_MyFont.CreateFont(...)
>// Set font
>m_EditCtrl.SetFont(&m_MyFont)

>Everything compiles fine. When I run the program, I receive an assertion
>failure message. Ignoring the message, the program executes, but with the
>default system font, not my custom font.

>Thanks for your help,

>Thomas



Sat, 11 Aug 2001 03:00:00 GMT  
 CEdit View Headache
Thomas:

Usually if you go into the de{*filter*}, and look at the line which ASSERTed, you
can see what is wrong. Usually something is NULL, which shouldn't be, and you
can figure what went wrong. Very often is due to doing things in the wrong order
(like sending messages to a window before creating it).

I think that is the problem here. You should put the following code in
OnCreate() (WM_CREATE handler)

// Create font
m_MyFont.CreateFont(...);
// Set font
m_EditCtrl.SetFont(&m_MyFont);

(call the base class OnCreate() first).

Another thing: are you sure you have initialized your m_EditCtrl reference
correctly? Aren't you supposed to do this in the initialization list of the
constructor? It would be simpler to forget about the reference and just do

GetEditCtrl().SetFont(&m_MyFont);

HTH,

David Wilkinson

============

Quote:

> I'm new to MFC and have banged my head for days trying to figure out this
> obviously simple problem. Please help, I'm running out of aspirin. I simply
> want to change the font displayed by the CEditView object. I've done this so
> far:

> // Add member variables to CEditView
> CFont m_MyFont
> CEdit& m_EditCtrl GetEditCtrl()

> // This code added to CEditView ctor
> // Create font
> m_MyFont.CreateFont(...)
> // Set font
> m_EditCtrl.SetFont(&m_MyFont)

> Everything compiles fine. When I run the program, I receive an assertion
> failure message. Ignoring the message, the program executes, but with the
> default system font, not my custom font.

> Thanks for your help,

> Thomas



Sat, 11 Aug 2001 03:00:00 GMT  
 CEdit View Headache

Quote:

> // This code added to CEditView ctor
> // Create font
> m_MyFont.CreateFont(...)
> // Set font
> m_EditCtrl.SetFont(&m_MyFont)

> Everything compiles fine. When I run the program, I receive an assertion
> failure message. Ignoring the message, the program executes, but with the
> default system font, not my custom font.

Move your code to OnInitialUpdate and make sure it is after the call to the
base class.  The edit control doesn't exist yet in the ctor.

Jim
Jim [VC/MFC MVP]
To send mail, change spam-me-not to msn



Sun, 12 Aug 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. CEdit box ** CEdit box ** CEdit box

2. select CEdit to view left part of text

3. CEdit in a mdi static splitter view

4. Problems with CEdit out of View Class

5. CRichEdit and CEdit views

6. CEdit View Style

7. CEdit used as old dos style status view

8. CEdit view background

9. Multiple CEdit-Views with one scrollbar

10. Need help with CEdit(View): send multiple lines?

11. CEdit control in a view

12. CEdit value variables in non-dialog view ??????????

 

 
Powered by phpBB® Forum Software