MDI current active view: how to?
-
Hi I have an MDI application which deal with 3 types of document: let's say IMAGE, TEXT, SHEET. this is a classical doc/view architecture with multidoct emplate. I'd like to have an modeless dialog which execute (when a button in this dialog is clicked) an action on the current topmost visible mdi child, only if it is an image. That means, if the current open window is a TEXT window, the button does nothing. But if it is a IMAGE window, it runs the process. How to get the actual topmost MDI view and its type? (in fact, I need a pointer to the actual topmost ImageView window) BTW I've tried to maintain a ImageView pointer, called *currentView, which is set to the actual active ImageView but it does not work well because when the user closes the ImageView, the pointer is not set to the next open ImageView window (in this case we suppose there are several imageview window open). Please, Help, I can't find a solution for those pb. Thank you very much in advance regards Guy LECOMTE
-
Hi I have an MDI application which deal with 3 types of document: let's say IMAGE, TEXT, SHEET. this is a classical doc/view architecture with multidoct emplate. I'd like to have an modeless dialog which execute (when a button in this dialog is clicked) an action on the current topmost visible mdi child, only if it is an image. That means, if the current open window is a TEXT window, the button does nothing. But if it is a IMAGE window, it runs the process. How to get the actual topmost MDI view and its type? (in fact, I need a pointer to the actual topmost ImageView window) BTW I've tried to maintain a ImageView pointer, called *currentView, which is set to the actual active ImageView but it does not work well because when the user closes the ImageView, the pointer is not set to the next open ImageView window (in this case we suppose there are several imageview window open). Please, Help, I can't find a solution for those pb. Thank you very much in advance regards Guy LECOMTE
The line
CView* pView=((CMDIFrameWnd*)AfxGetApp()->m_pMainWnd)->MDIGetActive()->GetActiveView();
gives you a pointer to the active view. Then, you can check wether the view is of IMAGE type with something like:
if(pView->IsKindOf(RUNTIME_CLASS(CImageView))){
//...
}For this last check to work,
CImageView
must have a runtime-type declaration usingDECLARE_DYNAMIC
or a similar macro from several MFC provides you with: possibly, the MFC wizard has already done that for you (I don't remember), but in any case you'd better check it out. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo Want a Boost forum in Code Project? Vote here[^]! -
The line
CView* pView=((CMDIFrameWnd*)AfxGetApp()->m_pMainWnd)->MDIGetActive()->GetActiveView();
gives you a pointer to the active view. Then, you can check wether the view is of IMAGE type with something like:
if(pView->IsKindOf(RUNTIME_CLASS(CImageView))){
//...
}For this last check to work,
CImageView
must have a runtime-type declaration usingDECLARE_DYNAMIC
or a similar macro from several MFC provides you with: possibly, the MFC wizard has already done that for you (I don't remember), but in any case you'd better check it out. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo Want a Boost forum in Code Project? Vote here[^]!Thanks a lot! That helped me and it solved my problem...partially. I explain: when I click the dialog button, now, everything is ok. I get the good window pointer etc...Fine.;) I call this sollution "from dialog to CView". Now I have the other problem "From CView to dialog". A modeless dialog is open and displays automatically some info of the current active topmost CImageView. What I need is to automatically maintain the current CImageView pointer and notify the dialog when this pointer changes. For example, when the user closes a CImageView window (and assuming there are several open CImageView and other CView windows) I'd like my dialog to be automatically notified by the new CView window and if it is a CImageView window the dialog should update its info. It is longer to explain than to see, but I'm sure you get it.:wtf: Thank a lot in advance Guy LECOMTE