Solved

Get  Frame pointer in the View

Posted on 2000-03-02
11
532 Views
Last Modified: 2013-11-20
I have created a SDI interface application and in that application with the class wizard have added two more views

and in each view's on draw function have code to textout three diff strings.

Now what i have done is that i have defined a pointer each for the 3 views in the CMain Frame class

like,

CMainFrame ....
{

public:

CComdirView * view1;
BriefView  * view2;
DescView * view3;

...

}

Now in the
OnInitialUpdate()

for each views
i have written

XXX::OnInitialUpdate()
{
///N is 1 2 3
GetParentFrame()->viewN=this;
}

Now i have created  menu and comands for each three views in the frame window


in each command function


CMainFrame::OnXXX()
{
//n=1,2,3
SetActiveWindow(viewN,TRUE);
}

but it says you can't convert from
CComdirView
or
DescView
or
BriefView

to Cview

What is the prob?

How can i solve it?




Now the prob is
0
Comment
Question by:ghimireniraj
11 Comments
 
LVL 1

Expert Comment

by:MFCAnswer
ID: 2577722
try
viewN->SetAvtivwWindow();
0
 
LVL 1

Expert Comment

by:MFCAnswer
ID: 2577773
here is some code to switch views in sdi

CView* pOldView = GetActiveView();
CView* newView = new UrnView();

CCreateContext context;
context.m_pCurrentDoc = pOldView->GetDocument();
newView->Create(NULL,NULL,WS_BORDER,CFrameWnd::rectDefault,this,n,&context);
newView->OnInitialUpdate();
SetActiveView(newView);
newView->ShowWindow(SW_SHOW);
RecalcLayout();

here n is ur nth view and
put this code in CMainFrame

0
 
LVL 8

Expert Comment

by:VinExpert
ID: 2579074
Hi,

Where exactly that error is coming?. Is it in
SetActiveWindow(viewN,TRUE);?

Then I think MFCAnswer's solution will work.

VinExpert
0
 
LVL 3

Expert Comment

by:MDarling
ID: 2579337
Have you tried

SetActiveWindow((CView *)viewN,TRUE);

?


regards,
Mike.
0
 
LVL 3

Author Comment

by:ghimireniraj
ID: 2580505
I have tried to switch between views and have done it sucessfully between 3/4 views and it works fine but i wanted to do that in the structure i described in this question .

The reason being that if i can store the pointers of all the views in my main frame class on their first construct i can switch between them
with with just two lines when ever i want

ie
SetActiveView(...stored view pointer);
...xx->ShowWindow(..);

and further more if i can acess my main frame pointer from my views i can switch between views from buttons in my view window.

Well but i think there are some fundamental mistakes in my structure
(architecture)   .

Can you figure out what it is?


Niraj






0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 4

Expert Comment

by:pagladasu
ID: 2580673
Have you tried Mike's solution?
0
 
LVL 1

Accepted Solution

by:
MFCAnswer earned 20 total points
ID: 2580901
XXX::OnInitialUpdate()
{
///N is 1 2 3                       GetParentFrame()->viewN=this;
}

here oninitialupdate of the views is not called by default for your 2nd and 3rd views because they are not created and
activated by documenttemplate.

do you  think when you call the follwing handler the viewn is pointing to valid memory ?
CMainFrame::OnXXX()                      {
                    //n=1,2,3
                      SetActiveWindow(viewN,TRUE);
}
0
 
LVL 3

Author Comment

by:ghimireniraj
ID: 2580969
Thanks MFCanswers for you comment .


Are views created every time  i want to view them and destroyed every time i switch to next view.

If that is the case i think the pointers will be no use storing.

So what do you think is the solution  when i want to switch to a another view from say a command from a button in the client are a of the view that i am currently in ?

May be like making use of self generated messages.

Thank you.

0
 
LVL 1

Expert Comment

by:MFCAnswer
ID: 2581163
In MDI u can have many document templates created at a time and
u can keep switching between them.
I do not know how to do it in SDI.

For the functionality you are looking for. jus add the button in the view and then put the handler in mainframe so that u can change views from one to another. Yes, u have to create it every
time in the handler.
0
 
LVL 1

Expert Comment

by:MFCAnswer
ID: 2606551
what happened ?
0
 
LVL 3

Author Comment

by:ghimireniraj
ID: 2631586
thx
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Include multiple hostnames in this command? 3 53
Expand macro to ask for filename column 8 37
NotAlone Challenge 20 80
SQUD PROXY SERVER, UNIX, SLL/HTTPS 5 74
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now