Top DevX Stories
Creating Custom Export Filters for StarOffice with XSLT
WPF Wonders: Using DataTemplates
Crystal Reports Family Offers Options for Developers
Avaya Aura Session Manager video
Avaya Aura Overview video
Search the forums:

Go Back   DevX.com Forums > DevX Developer Forums > C++

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old 08-20-2000, 12:09 PM
N. Jothi
Guest
 
Posts: n/a
Switching between views in SDI doc-view using Button


HI

How to switch between two views in SDI using a button control. That is I
have a button on each views. When I press the button in one view the other
view should be displayed & vice-versa. Please response to this.

N. Jothi
Reply With Quote
  #2  
Old 08-21-2000, 02:04 PM
Christopher Thomas McGinlay
Guest
 
Posts: n/a
Re: Switching between views in SDI doc-view using Button

"N. Jothi" wrote:
>
> HI
>
> How to switch between two views in SDI using a button control. That is I
> have a button on each views. When I press the button in one view the other
> view should be displayed & vice-versa. Please response to this.
>
> N. Jothi


Hello N.

I've been working on the same problem and have so far come up with the
following function in my CMainFrame class. I've used the IDD_ resource
symbols for the views to identify and exchange them. This function
appears to work, but I'm sure our fellows here in the newsgroup can
suggest alternatives. I call SwitchToView() from an OnMyButtonClick()
handler function in the already-open view, although you could equally
use a menu handler.

As I say, it works, but I'm not a 100% happy with it - I don't like
using 'new' to create the view since the views are supposed to have
protected constructors - let me know if you find a way round this!!!!
(By the way, if you try my horrible hack here, you'll have to change the
specifier for your view constructors as public: instead of protected:

It's a shameful hack I suspect!

Regards

Chris

//returns ID of previous view. 0 if fails
UINT CMainFrame::SwitchToView(UINT nID)
{
CView* pOldView = GetActiveView();
CView* pNewView = (CView*) GetDlgItem(nID); //view to switch to

//Test to see whether view needs to be created or if it already exists
if (pNewView==NULL)
{
switch(nID)
{
case IDD_PUPIL_FORM: //pupil view
pNewView = (CView*) new CPupilView;
break;
case IDD_REPORT_FORM: //report view
pNewView = (CView*) new CReportView;
break;
case IDD_MARK_FORM: //mark view
pNewView = (CView*) new CMarkView;
break;
case IDD_ENROLLMENT_FORM:
pNewView = (CView*) new CEnrollmentView; //enrollment view
break;
default:
AfxMessageBox("Switch to view: View doesn't exist!");
return NULL; //failure
}

//Switching code for new view (once only for each view)
CCreateContext context;
context.m_pCurrentDoc = pOldView->GetDocument();

pNewView->Create(NULL,NULL,0L,CFrameWnd::rectDefault,this,nID,&context);
pNewView->OnInitialUpdate();
}

SetActiveView(pNewView,TRUE);
pOldView->ShowWindow(SW_HIDE);
pNewView->ShowWindow(SW_SHOW);
CRuntimeClass* pRTC = pOldView->GetRuntimeClass();
pOldView->SetDlgCtrlID(
pRTC == RUNTIME_CLASS(CPupilView) ? IDD_PUPIL_FORM :
pRTC == RUNTIME_CLASS(CReportView) ? IDD_REPORT_FORM :
pRTC == RUNTIME_CLASS(CMarkView) ? IDD_MARK_FORM :
pRTC == RUNTIME_CLASS(CEnrollmentView) ? IDD_ENROLLMENT_FORM : NULL );
ASSERT(pOldView->GetDlgCtrlID());

UINT nOld = m_nCurrentViewID;

pNewView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
m_nCurrentViewID = nID;
RecalcLayout(TRUE);
return nOld;
}


--
Ascent Software Limited Registered in Scotland: SC201671
ascent@zetnet.co.uk Bank Of Scotland Buildings
01950 422 431 Lerwick, Shetland, ZE1 0EB
Reply With Quote
  #3  
Old 10-31-2000, 12:07 PM
Mike Ramirez
Guest
 
Posts: n/a
Re: Switching between views in SDI doc-view using Button


Christopher Thomas McGinlay <ascent@zetnet.co.uk> wrote:
>"N. Jothi" wrote:
>>
>> HI
>>
>> How to switch between two views in SDI using a button control. That is

I
>> have a button on each views. When I press the button in one view the other
>> view should be displayed & vice-versa. Please response to this.
>>
>> N. Jothi

>
>Hello N.
>
>I've been working on the same problem and have so far come up with the
>following function in my CMainFrame class. I've used the IDD_ resource
>symbols for the views to identify and exchange them. This function
>appears to work, but I'm sure our fellows here in the newsgroup can
>suggest alternatives. I call SwitchToView() from an OnMyButtonClick()
>handler function in the already-open view, although you could equally
>use a menu handler.
>
>As I say, it works, but I'm not a 100% happy with it - I don't like
>using 'new' to create the view since the views are supposed to have
>protected constructors - let me know if you find a way round this!!!!
>(By the way, if you try my horrible hack here, you'll have to change the
>specifier for your view constructors as public: instead of protected:
>
>It's a shameful hack I suspect!
>
>Regards
>
>Chris
>
>//returns ID of previous view. 0 if fails
>UINT CMainFrame::SwitchToView(UINT nID)
>{
>CView* pOldView = GetActiveView();
>CView* pNewView = (CView*) GetDlgItem(nID); //view to switch to
>
>//Test to see whether view needs to be created or if it already exists
>if (pNewView==NULL)
>{
> switch(nID)
> {
> case IDD_PUPIL_FORM: //pupil view
> pNewView = (CView*) new CPupilView;
> break;
> case IDD_REPORT_FORM: //report view
> pNewView = (CView*) new CReportView;
> break;
> case IDD_MARK_FORM: //mark view
> pNewView = (CView*) new CMarkView;
> break;
> case IDD_ENROLLMENT_FORM:
> pNewView = (CView*) new CEnrollmentView; //enrollment view
> break;
> default:
> AfxMessageBox("Switch to view: View doesn't exist!");
> return NULL; //failure
> }
>
> //Switching code for new view (once only for each view)
> CCreateContext context;
> context.m_pCurrentDoc = pOldView->GetDocument();
>
>pNewView->Create(NULL,NULL,0L,CFrameWnd::rectDefault,this,nID,&context);
> pNewView->OnInitialUpdate();
> }
>
> SetActiveView(pNewView,TRUE);
> pOldView->ShowWindow(SW_HIDE);
> pNewView->ShowWindow(SW_SHOW);
> CRuntimeClass* pRTC = pOldView->GetRuntimeClass();
> pOldView->SetDlgCtrlID(
> pRTC == RUNTIME_CLASS(CPupilView) ? IDD_PUPIL_FORM :
> pRTC == RUNTIME_CLASS(CReportView) ? IDD_REPORT_FORM :
> pRTC == RUNTIME_CLASS(CMarkView) ? IDD_MARK_FORM :
> pRTC == RUNTIME_CLASS(CEnrollmentView) ? IDD_ENROLLMENT_FORM : NULL );
> ASSERT(pOldView->GetDlgCtrlID());
>
> UINT nOld = m_nCurrentViewID;
>
> pNewView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
> m_nCurrentViewID = nID;
> RecalcLayout(TRUE);
> return nOld;
>}
>
>
>--
>Ascent Software Limited Registered in Scotland: SC201671
>ascent@zetnet.co.uk Bank Of Scotland Buildings
>01950 422 431 Lerwick, Shetland, ZE1 0EB


I found a class on CodeGuru (http://codeguru.earthweb.com/) which added a
class derived from CDocTemplate that was designed to work with multiple views
related to one document.

I was real happy with it. If you dig around there you'll be able to find
it. (BTW, there is a sample with the class that doesn't work with VC++ 5.0)
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 12:20 AM.


Sponsored Links



Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.