How to load resource dialog template into my FormView Application?

Posted on 2003-02-26
Medium Priority
Last Modified: 2013-11-20
I Write a SDI Formview App.and I put a "Next" button on the FormView.I wanna user click the button and goto next page:A new FormView,Step2 dialog.
I have design this step 2 dialog in resource.and how to load it when click "Next" button????
Question by:suvcon
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 8028340
Create a CFormView class for the Step2 Dialog.

The following is a function I wrote in MainFrame which will switch the view corresponding to menu command.  You can associate that this function with your "next" button action.

CView* CMainFrame::SwitchView(CView* pNewView)
  CView* pActiveView =GetActiveView();
  // Exchange view window ID's so RecalcLayout() works.
  #ifndef _WIN32
  UINT temp = ::GetWindowWord(pActiveView->m_hWnd, GWW_ID);
  ::SetWindowWord(pActiveView->m_hWnd, GWW_ID,
    ::GetWindowWord(pNewView->m_hWnd, GWW_ID));
  ::SetWindowWord(pNewView->m_hWnd, GWW_ID, temp);
  UINT temp = ::GetWindowLong(pActiveView->m_hWnd, GWL_ID);
  ::SetWindowLong(pActiveView->m_hWnd, GWL_ID,
    ::GetWindowLong(pNewView->m_hWnd, GWL_ID));
  ::SetWindowLong(pNewView->m_hWnd, GWL_ID, temp);


  return pActiveView;

Accepted Solution

su185 earned 400 total points
ID: 8038674
You can build your dialogue to a viewclass and,do some works in your Frame_class .
The key is some functions as AddView and SetWindowsLong(and other same usage function is setdlgid),etc.
In fact,you can find your anwser in MSDN.
this will help you very much. :)
Call this function to attach a view to the document.

void AddView(
   CView* pView
Points to the view being added.
This function adds the specified view to the list of views associated with the document; the function also sets the view's document pointer to this document. The framework calls this function when attaching a newly created view object to a document; this occurs in response to a File New, File Open, or New Window command or when a splitter window is split.

Call this function only if you are manually creating and attaching a view. Typically you will let the framework connect documents and views by defining a CDocTemplate object to associate a document class, view class, and frame window class.

// The following example toggles two views in an SDI (single document
// interface) frame window. A design decision must be made as to
// whether to leave the inactive view connected to the document,
// such that the inactive view continues to receive OnUpdate
// notifications from the document. It is usually desirable to
// keep the inactive view continuously in sync with the document, even
// though it is inactive. However, doing so incurs a performance cost,
// as well as the programming cost of implementing OnUpdate hints.
// It may be less expensive, in terms of performance and/or programming,
// to re-sync the inactive view with the document only with it is
// reactivated. This example illustrates this latter approach, by
// reconnecting the newly active view and disconnecting the newly
// inactive view, via calls to CDocument::AddView and RemoveView.

BOOL CMainFrame::OnViewChange(UINT nCmdID)
// There is an ON_COMMAND_RANGE message map entry associated with
// OnViewChange:
 CView* pViewAdd;
 CView* pViewRemove;
 CDocument* pDoc = GetActiveDocument();

 if((nCmdID == ID_VIEW_VIEW1) && (m_currentView == 1))
 if((nCmdID == ID_VIEW_VIEW2) && (m_currentView == 2))

 if (nCmdID == ID_VIEW_VIEW2)
  if (m_pView2 == NULL)
   m_pView1 = GetActiveView();
   m_pView2 = new CMyView2;

//Note that if OnSize has been overridden in CMyView2
//and GetDocument() is used in this override it can
//cause assertions and, if the assertions are ignored,
//cause access violation.
   m_pView2->Create(NULL, NULL, AFX_WS_DEFAULT_VIEW,
      rectDefault, this, AFX_IDW_PANE_FIRST + 1, NULL);
   pViewAdd = m_pView2;
   pViewRemove = m_pView1;
   m_currentView= 2;
  pViewAdd = m_pView1;
  pViewRemove = m_pView2;
  m_currentView= 1;
// Set the child i.d. of the active view to AFX_IDW_PANE_FIRST,
// so that CFrameWnd::RecalcLayout will allocate to this
// "first pane" that portion of   the frame window's client area
// not allocated to control   bars.  Set the child i.d. of the
// other view to anything other than AFX_IDW_PANE_FIRST; this
// examples switches the child id's of the two views.

 int nSwitchChildID = pViewAdd->GetDlgCtrlID();

 // Show the newly active view and hide the inactive view.


 // Connect the newly active view to the document, and
 // disconnect the inactive view.



Author Comment

ID: 8038796
I Get it~!!!Thank you!!

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses
Course of the Month14 days, 5 hours left to enroll

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question