Skip to main content
Email Password   helpLost your password?

Introduction

Sometimes, it may be useful to have a modal window with Doc/View architecture, toolbars/statusbar support (i.e. base features implemented in MFC frame windows). How to get these without implementing all of these features in a CDialog-derived class? The CModalFrame utility class presented here helps you implement a modal dialog's behavior for any CFrameWnd-derived window class in an easy way.

If you have to use it and have a bit of time, please add a comment at the bottom of this page and tell, in which context you decided to use this code. I would be interested.

Background

Some basic facts:

Brief implementation description:

  1. The utility code uses only the CFrameWnd class interface and does not make any suggestions about the internal implementation details of any CFrameWnd-derived classes.
  2. CModalFrame::Run creates an instance of the internal CModalDialogLock class which:
  3. CModalDialogLock subclasses the created frame window to provide:
  4. You should not use WS_CHILD window style for a frame. Because its parent window is disabled during modal loop. So child frame window also will be disabled (for example, MDI child frame)!

Using the code

Sample of usage:

void CMyView::OnRunModalFrame()
{
    CCreateContext context;
    context.m_pNewViewClass = RUNTIME_CLASS(CMyOtherView);
    context.m_pCurrentDoc = GetDocument();
    context.m_pNewDocTemplate = GetDocument()->GetTemplate();
    context.m_pLastView = this;
    context.m_pCurrentFrame = GetParentFrame();

    CRuntimeClass * pFrameClass = RUNTIME_CLASS(CMyModalFrame);

    if (!CModalFrame::Run(*pFrameClass, false, IDR_MYFRAMERESOURCE,
                          WS_OVERLAPPEDWINDOW | 
                          FWS_ADDTOTITLE, this, &context))
    {
        AfxMessageBox(AFX_IDP_COMMAND_FAILURE);
    }
}

// don't forget close modal frame like a modal dialog box!

void CMyModalFrame::OnClose()
{
    int nModalResult = -1;
    CModalFrame::End(this, nModalResult);
}

See demo project code for more details.

History

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralThank you for your simple project Pin
Li Shu
20:50 23 Oct '08  
GeneralIs it possible to pass parameters to my view or frame after doModal and how! Pin
chiheb zak
12:10 27 Feb '07  
AnswerRe: Is it possible to pass parameters to my view or frame after doModal and how! Pin
Alexey Nikitin
8:52 12 Mar '07  
GeneralRe: Is it possible to pass parameters to my view or frame after doModal and how! Pin
chiheb zak
4:36 13 Mar '07  
GeneralWorks well but crashes when opening folder on desktop Pin
Wolfram Rösler
4:22 31 Jan '07  
GeneralRe: Works well but crashes when opening folder on desktop Pin
Alexey Nikitin
13:00 15 Feb '07  
GeneralRe: Works well but crashes when opening folder on desktop Pin
Wolfram Rösler
23:19 19 Feb '07  
GeneralVery useful and practical code Pin
skywalkerking
8:57 28 Nov '06  
Generalaccess violation error with modal in modal Pin
Brad Ulrich
9:07 17 May '05  
Hey, first off, great work to start with, windows should have this from the beginning, I don't know why it is not more prevelant.

However, when I add a new function in that lets me create a new modal frame "on top of" the existing frame, by calling a function from within that modal frame, i get an assertion failure.

It happens after i open a few successive modal frames, and then start closing them down.

It occurs in CModalFrame::FromHandle() on this line:
if (c->m_hWnd == hwnd)


Also, separately, if I set the parent of the frame to be null, it does not show up as system level top window (i.e., does not show up in the taskbar) as it does with a normal CFrameWnd

Thanks in advance for any help. I would be glad to work on a solution for this if you can get me started.

Thanks.

Brad Ulrich
Sign In·View Thread·PermaLink2.00/5
GeneralRe: access violation error with modal in modal Pin
Alexey Nikitin
0:32 22 May '05  
GeneralRe: access violation error with modal in modal Pin
Brad Ulrich
5:19 2 Aug '05  
GeneralRe: access violation error with modal in modal Pin
Anonymous
11:12 11 Aug '05  
GeneralRe: access violation error with modal in modal Pin
Alexey Nikitin
11:15 11 Aug '05  
GeneralHow to embody Modeless Frame Window ? Pin
UriDokDo
3:20 31 Mar '05  
GeneralModal CMDIFrameWnd Pin
Urban Olars
12:17 17 Dec '04  
GeneralRe: Modal CMDIFrameWnd Pin
dirtcooker
3:48 25 May '05  
GeneralPassing parameters to my frame class Pin
Urban Olars
10:25 8 Dec '04  
GeneralRe: Passing parameters to my frame class Pin
Alexey Nikitin
23:27 10 Dec '04  
GeneralRe: Passing parameters to my frame class Pin
Urban Olars
9:26 13 Dec '04  
Generalmodal from modal? Pin
bagsmode
7:42 3 Aug '03  
GeneralGood work, some remarks Pin
FransB
21:33 23 Jun '03  


Last Updated 9 Aug 2005 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2009