Advertisement

MFC-Probs

Started by June 05, 2000 08:56 AM
4 comments, last by CBA 24 years, 6 months ago
hi there.. i have probs with MFC... i have a CWinApp derived class with an OnIdle method.. in these mothod i have the call CFrame->CChildFront->RedrawWindow() CFrame is derived from CMDIFrameWnd an CChildFront is derived from CWnd... all pointers are public but if i want to execute this prog, i get an error, that says, that CChildFront is an protected member of CFrame...(Error Code: C2248 i dont know if it is the same error in the english version of VC++ 5.0)... why i get this error... there is no help in the onlinedocumentation...??? Need help!!
Let the Water burn!!!! WaterWORX
I should probably just ask up front why you''re doing this. It''s generally not a good idea to override the OnIdle in most MFC applications. The usual accepted way of forcing a window redraw is by calling Invalidate(); in MFC, which is much, much safer than what you''re trying to do. Invalidate takes a BOOL which will determine whether or not to redraw the background.

That aside, are you sure that it''s public?

-fel
~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~
Advertisement
hi there...
let me explain:
i have a ccamera object... everytime a bool property changes to true, i need to redraw all the windows, but i cant handle the windows from ccamera... how to do this??
Let the Water burn!!!! WaterWORX
Ah.

Well, classically in an MDI, view update control is handled from the CDocument. You do have one right? (I have to ask, I''ve seen some pretty bizarre implementations of "MDI Apps"). So, when you need an update, tell your document, and your document should iterate through the views using GetFirstViewPosition to get the first one, and then GetNextView for all the subsequent views. Alternatively, there is a function you can call in CDocument called UpdateAllViews if you''re sure you want to update them all, which will iterate and call OnUpdate for every view for you. Just make sure your update functions of your views know what they''re doing...

HTH
-fel
~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~
Like Fel said, if you have a document then it''s almost done for you already. Here''s a helpful method:

void CDocument::UpdateAllViews (CView* pSender, LPARAM lHint, CObject* pHint);

What this will do is call the CView::OnUpdate method for every view attached to the document with the parameters pSender, lHint and pHint. You shouldn''t do any drawing in the OnUpdate method; rather, you should invalidate areas to be redrawn, WM_PAINT message to be sent to your windows.

Here''s how I use my document to update my views:
First, I have a file called "hints.h", which I include in my document and view source files. This header file defines all of my hints and hint objects. For example:

// hints.h#define HINT_CHANGE_COLOR      1#define HINT_DO_SOMETHING_ELSE 2#define HINT_SOME_ACTION       3class HintColor : public CObject{public:  COLORREF color;// note, it''s generally bad to make classes with public members,// and this should really be a struct, but I MUST inherit from// CObject which is a class, so I''m stuck with using a class.}; 


Now, when I want to tell all the views to change their colors to blue, I do this:
void CMyDoc::OnChangeColor (COLORREF clr){  HintColor hint;  hint.color = clr;  UpdateAllViews (NULL, HINT_CHANGE_COLOR, &hint);} 


Finally, in each of my views, my override of OnUpdate is called:
void CMyView::OnUpdate (CView* pSender, LPARAM lHint, CObject* pHint){  switch (lHint)  {  case 0: // the redraw hint    Invalidate ();    break;  case HINT_CHANGE_COLOR:    m_newColor = ((HintColor*) pHint)->color; // store new color as member    Invalidate (); // demand to be redrawn    break;  // ...  default: break;  }} 


This is generally the MFC methodology for a document to broadcast messages to all views. Note that you cannot single out a single view only to receive the OnUpdate method.

Two notes:
1) The CView* pSender should only be set if you DON''T want a view to receive the OnUpdate. UpdateAllViews will call the OnUpdate method of all views EXCEPT pSender. The most common error I''ve seen in MFC is people think the CView* is the target view you want updated; instead, it''s the opposite. Use this if your view is generating the update and doesn''t need itself updated.
2) The lHint value of 0 is sent by the default MFC framework when the window is created, and the default handler of CView::OnUpdate will call Invalidate () if lHint is 0 and pHint is NULL. The easiest way to make your override compatible is to use lHint=0 to signify a "redraw all" message if you want to send one from your document.

BTW, the documentation suggests that any hint you can''t decode should be handled by invalidating your entire window. I disagree, and think this causes too much redrawing, so I take no action if I receive a hint I don''t understand.

Hope this helps.
You are confusing the poor boy. It should work if you change CFrame->CChildFront->RedrawWindow() to CFrame->CChildFront.RedrawWindow() you only unse -> for the first part in a pointer reference.

This topic is closed to new replies.

Advertisement