Click here to Skip to main content
16,011,711 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralWhat's up? My hook works but my program doesn't work Pin
raul10-Jan-01 2:36
raul10-Jan-01 2:36 
GeneralPlay one video file in several windows simultaneously Pin
10-Jan-01 2:32
suss10-Jan-01 2:32 
GeneralUrgent Exception in GetString of ADODB.Recordsset Pin
Alpesh10-Jan-01 1:24
Alpesh10-Jan-01 1:24 
GeneralSound Pin
10-Jan-01 0:58
suss10-Jan-01 0:58 
QuestionCListCtrl and noresize columns ???? Pin
10-Jan-01 0:33
suss10-Jan-01 0:33 
AnswerRe: CListCtrl and noresize columns ???? Pin
10-Jan-01 21:50
suss10-Jan-01 21:50 
QuestionActiveX controls belong in Doc or View? Pin
Brendan Tregear9-Jan-01 11:01
Brendan Tregear9-Jan-01 11:01 
AnswerRe: ActiveX controls belong in Doc or View? Pin
Erik Funkenbusch9-Jan-01 12:20
Erik Funkenbusch9-Jan-01 12:20 
There are lots of solutions to this problem actually.

The most efficient is probably to derive your classes from a common CImageView class. Then you can override these functions in the actual view class to do what you want.

Now, instead of using the Doc/Vew mechanism for calling functions, which is inherantly error prone, you can instead create a publish/subscribe handler, also called Observer Pattern.

In your CDocument derived class, you create and instance of an Observer class. This is a class which simply takes a pointer to some other kind of class (CImageView in this case) and stores it in a list. Then, when you go to update, you need only get each item in the list (and since they're already stored as CImageView pointers, you need only do this pListItem->SetImage(...).

This avoids all the issues your dealing with by calling the functions directly, and then only for the objects which are actually CImageView's.

example (off the top of my head, so it may not compile):

#include <list>
class CImageViewObserver {
    std::list<CImageView*> imageList;
public:
    AddView(CImageView* pView){imageList.push_back(pView);}:
    RemoveView(CImageView* pView){imageList.remove{pView);};
    Update(CString s){/*iterate over list and call SetImage() for each one*/};
}


Then, in your CThumbView or whatever simply put a call to AddView in your OnCreate(), or OnInitialUpdate() (but be sure to clear out your Observer in OnNew() to make sure you don't leave anything hanging around):

CMyDoc *pDoc = (CMyDoc*)GetActiveDocument();
pDoc->m_ivObserver.AddView(this);


Then, wherever you update, you need only pass the image path to the Observer::Update function.
Generalstd::string and unicode Pin
Anders Molin9-Jan-01 8:52
professionalAnders Molin9-Jan-01 8:52 
GeneralRe: std::string and unicode Pin
Chad Plautz9-Jan-01 9:32
Chad Plautz9-Jan-01 9:32 
GeneralRe: std::string and unicode Pin
Chad Plautz9-Jan-01 9:38
Chad Plautz9-Jan-01 9:38 
GeneralRe: std::string and unicode Pin
Anders Molin9-Jan-01 21:02
professionalAnders Molin9-Jan-01 21:02 
QuestionHow do I force my program to check the message queue? Pin
Paul Auger9-Jan-01 6:35
Paul Auger9-Jan-01 6:35 
AnswerRe: How do I force my program to check the message queue? Pin
9-Jan-01 7:10
suss9-Jan-01 7:10 
GeneralCWnd - HWnd Map Related problem Pin
9-Jan-01 2:54
suss9-Jan-01 2:54 
GeneralHICON to .ico File Pin
8-Jan-01 23:17
suss8-Jan-01 23:17 
Questionhow to display a GIF image by programming? Pin
8-Jan-01 20:02
suss8-Jan-01 20:02 
AnswerRe: how to display a GIF image by programming? Pin
Jim Howard9-Jan-01 7:52
Jim Howard9-Jan-01 7:52 
GeneralRe: how to display a GIF image by programming? Pin
Marc Richarme9-Jan-01 9:01
Marc Richarme9-Jan-01 9:01 
GeneralRe: how to display a GIF image by programming? Pin
Christian Graus9-Jan-01 9:23
protectorChristian Graus9-Jan-01 9:23 
GeneralRe: how to display a GIF image by programming? Pin
Masoud Samimi9-Jan-01 9:59
Masoud Samimi9-Jan-01 9:59 
GeneralRe: how to display a GIF image by programming? Pin
Christian Graus9-Jan-01 13:14
protectorChristian Graus9-Jan-01 13:14 
GeneralRe: how to display a GIF image by programming? Pin
Masoud Samimi9-Jan-01 23:53
Masoud Samimi9-Jan-01 23:53 
AnswerRe: how to display a GIF image by programming? Pin
Juan Carlos Cobas9-Jan-01 10:23
Juan Carlos Cobas9-Jan-01 10:23 
Answerthank you very much Pin
9-Jan-01 22:57
suss9-Jan-01 22:57 

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.