How to add support for switching the view ?
Hello everybody,
Im implementing an MDI application. Im usind a menu for displaying views. But not able to implement code for it.How i should add views to synchrinize with menu?
Any help would be appreciated,
pratibha.
[241 byte] By [
prati] at [2007-11-18 20:33:35]

# 1 Re: How to add support for switching the view ?
Are you adding views and frames for each or you add view to existing frame?
Are you creating frame with several views and want to swap views?
Are all views maintained by the same document?
JohnCz at 2007-11-11 1:12:19 >

# 2 Re: How to add support for switching the view ?
Hello sir !
Thanks a lot sir, that u have attended my problem.
Im implementing an MDI application with multiple views(form views) different different views are associated with a same document.
I wanted to switch to the views through the menu.
pratibha.
prati at 2007-11-11 1:13:22 >

# 3 Re: How to add support for switching the view ?
For each of the MDI child window, an item gets added to the Window menu. Do you want to do something similar ?
# 4 Re: How to add support for switching the view ?
Hello sir,
Actually all views are to be maintained by the same document in an MDI application. So child frame should be created with several views and want to swap views.
pratibha.
prati at 2007-11-11 1:15:30 >

# 5 Re: How to add support for switching the view ?
u mean, say there is one child frame window, and say it is showing View1 now. When you select the menu, you want the childframe to stay there, but replace View1 with View2 ?
# 6 Re: How to add support for switching the view ?
sir,
Exactly, i want the same thing that, when i click the menu item it will replace the existing view with a new one within same child frame.
pratibha.
prati at 2007-11-11 1:17:28 >

# 7 Re: How to add support for switching the view ?
Maybe this ( http://support.microsoft.com/default.aspx?scid= http://support.microsoft.com:80/support/kb/articles/q141/4/99.asp&NoWebContent=1) will take u in the right direction.
# 8 Re: How to add support for switching the view ?
Sir,
Thanks a lot sir, i got a solution .Now i'll try it in my code.
pratibha.
prati at 2007-11-11 1:19:31 >

# 9 Re: How to add support for switching the view ?
kirants,
That is very interesting project, but I think it is overkill for switching views.
prati,
See view menu in the sample app.
JohnCz at 2007-11-11 1:20:34 >

# 10 Re: How to add support for switching the view ?
U r right. I wouldn't use it as is. I would just borrow the technique and customize to optimize it. Possibly I would do the creation the first time a new view is invoked.
The point to be noted in this whole discussion is the importance of the ID of the view. This is the one which does all the work.
In general, when there is a need to switch views, say there is a splitter with 2 panes and you now want to replace one with a new one, the magic is to set the proper dlg ID for the new. I hope the poster will make note of that.
# 11 Re: How to add support for switching the view ?
Originally posted by kirants
The point to be noted in this whole discussion is the importance of the ID of the view. This is the one which does all the work. RIGHT! That is what I show in attached sample.
Originally posted by kirants
In general, when there is a need to switch views, say there is a splitter with 2 panes and you now want to replace one with a new one, the magic is to set the proper dlg ID for the new. I hope the poster will make note of that. If poster is using splitter window.:D
JohnCz at 2007-11-11 1:22:30 >

# 12 Re: How to add support for switching the view ?
Sir,
I have seen the attachment swapviews.zip sent by
you.Exactly i want the same thing and also got the
solution, but when i implemented it in my application it
gave me application error that is......
unhadled Exception -Access violation
AFXWIN_INLINE BOOL Cwnd::IsWindowVisible()const
{ASSERT(::IsWindow(m_hWnd));::ShowOwnedPopups(m_hWnd,hShow);}
Pratibha.
prati at 2007-11-11 1:23:36 >

# 13 Re: How to add support for switching the view ?
Sir,
Actually when i click on "View" at that time itself it gives me the application error, and not even let me chose the menu item which "View" menu contain.
Pratibha.
prati at 2007-11-11 1:24:30 >

# 14 Re: How to add support for switching the view ?
Before you find in a debugger what part of code causes that assertion it is impossible to resolve your problem.
Sample works.
See changes in the code that you introduced.
JohnCz at 2007-11-11 1:25:36 >

# 15 Re: How to add support for switching the view ?
Sir,
sorry sir ,without made a look i bother you. I got my mistake,it was a pin pointed mistake i had committed.But i came out from that problem and it is working same as your attachment sampleview does.
Now, when i proceed to my project , i got to know that......i don't want views to be overkill, i mean i don't wanna view to be destroy unless or untill i close it.
I want a view to be there while opening other view(different formview),i mean simultaneously open two or more different views.
Pratibha.
prati at 2007-11-11 1:26:31 >

# 16 Re: How to add support for switching the view ?
That is exactly what sample program does.
It does not destroy views.
If you want to make them visible simultaneously you can use splitter window.
JohnCz at 2007-11-11 1:27:39 >

# 17 Re: How to add support for switching the view ?
Sir,
As you told me about splitter window.In my project i have made a controlbar in which i have put a TreeCtrl at the left side of MainFrame window.
So now when i select a menu item i want views to be displayed at the right side of the window and now these views would be in child frame.
sir would you please tell me that, where to split a window.I have already two panes but not by splitting a window.I have so many views, Where i should put that views after splitting a window.
------------------
CSplitterWnd::CreateStatic
BOOL CreateStatic( CWnd* pParentWnd, int nRows, int nCols, DWORD dwStyle = WS_CHILD | WS_VISIBLE, UINT nID = AFX_IDW_PANE_FIRST );
------------------
Q. What to give at the place of second and third parameters (rows & cols)?
Pratibha.
prati at 2007-11-11 1:28:42 >

# 18 Re: How to add support for switching the view ?
I really would have to see your whole project to give you any intelligent advice. Would it be possible to post your entire project?
JohnCz at 2007-11-11 1:29:42 >

# 19 Re: How to add support for switching the view ?
Sir,
Sir my attachment contains size 2.56 MB.
How i can send my project? I have send it to webmaster
through my company's email id that is
"pratibha@dvsinfo.com".Sir Please collect it from web
master if you can.
Pratibha.
prati at 2007-11-11 1:30:40 >

# 20 Re: How to add support for switching the view ?
Probably the size of this project include debug/release directory that is not needed.
Also files like .ncb, .opt, .plg are not needed. all of the avove can be deleted and the rest should be compressed (winzip is preferable).
JohnCz at 2007-11-11 1:31:39 >

# 21 Re: How to add support for switching the view ?
Sir,
Here is the application, which i have build till now.
Pratibha.
prati at 2007-11-11 1:32:45 >

# 22 Re: How to add support for switching the view ?
Sir,
Sir, or you can see this updated sample application which had been sent by you.
Pratibha.
prati at 2007-11-11 1:33:46 >

# 23 Re: How to add support for switching the view ?
It is kind of simple. I thought that with hints you have already received you would be able to figure it out.
In updated sample I have disabled selection of the root item in the tree.
JohnCz at 2007-11-11 1:34:47 >

# 24 Re: How to add support for switching the view ?
Sir,
i was able to catch it out whatever you were told in sample program, i did it in swapviews_updated, which i have sent just in previous reply.
But i was trying to tell you that, i don't want exactly the same thing like sample program does else what i want is ,please again make a look to sample program.
when i click an item from view say "form 1", suppose i minimizes it and now opens a new form say "form 2", now total two forms should be there, "form 1" should be in minimized form and "form 2" should be in maximized.if i want to open so many forms at a time ,application would be able to open them so that i can see whatever process is going on simultaneously
Note:=>
--------------------------
so summary is that,want my application just like visual studio, it can open so many files at a time in childFrame but only one file on active state.
--------------------------
pratibha.
prati at 2007-11-11 1:35:40 >

# 25 Re: How to add support for switching the view ?
Originally posted by prati
But i was trying to tell you that, i don't want exactly the same thing like sample program does else what i want is ,please again make a look to sample program. :confused:
I am sorry but I am totally confused and I really do not understand your requirements.
If you are trying to explain something please stick to well defined vocabulary:
View is a child frame usually displayed in a frame window (MDI child frame) occupying frames client area. It typically is resized by frame window.
Frame is a window that hosts view windows generally derived from CView, but other classes are occasionally used too.
JohnCz at 2007-11-11 1:36:43 >

# 26 Re: How to add support for switching the view ?
Sir,
Sorry sir, i confused you and also took your precious time.simply i can say that i want my application like "visual studio ", Number of form views should be open at a time just like visual studio can open so many files at a time without cosing others.
sir,i request you that ,if i don't able to make you understand my problem,please don't irritate or let me know that you are not able to understand.......just like that you have prevoiusly described.
Sir ,please try to sort uot my problem.Without solving it , i can't proceed my project.
Thanks for your quick response. I'm glad there are still people willing to help .
Pratibha.
prati at 2007-11-11 1:37:44 >

# 27 Re: How to add support for switching the view ?
This is another attempt to resolve your dilema.
JohnCz at 2007-11-11 1:38:52 >

# 28 Re: How to add support for switching the view ?
Sir,
referred to sample program->
------------------------
When we select more than one document template to choose
from bring up dialog prompting user then it displays seperate views for each document tempelate.
------------------------
Though that was the thing that i wanted so far.
But i don't want to go through this way, i mean via applications File menu.Instead of this i want to display seperate views, when i click to corresponding menu item. Like form 1, form 2......so on.
In last sample program when we click on corresponding view menu item it overrides the views.i want these views to be there only just like applications file menu does with each template.
pratibha.
prati at 2007-11-11 1:39:52 >

# 29 Re: How to add support for switching the view ?
You really have unique way of complicating things starting with thread name: How to add support for switching the view ?
Your problem has nothing to do with views switching neither it has anything to do with frames activation.
You just need to open new document when tree items are selected. Each document (with its view and child frame) is created using different document template.
With all the code I have already provided you should have an idea how to do it.
I will see if I have time to show it to you. Try it yourself. Try to find what registering templates do and how new files are created starting with simple template and advancing to multiple.
JohnCz at 2007-11-11 1:40:53 >

# 30 Re: How to add support for switching the view ?
In addition to my previous post:
You should use terms that are common, known to everybody and follow meaning of terms: view is a view frame is a frame and you cannot use term swap views instead create new document file.
I have rewritten code in a attached sample. I hope that even it is not what you are looking for you have gotten enough hints an sample code to continue.
JohnCz at 2007-11-11 1:41:50 >

# 31 Re: How to add support for switching the view ?
Sorry, attachment follows.
JohnCz at 2007-11-11 1:42:47 >

# 32 Re: How to add support for switching the view ?
Sir,
i found one way to solve my problem.Make look to MDI.zip, it opens new document when menu items are selected. Each document (with its view and child frame) is created using different document template.
shall i implement in this way,or it will creat any problem in future.
following is my program:
prati at 2007-11-11 1:43:51 >

# 33 Re: How to add support for switching the view ?
Sir,
i found one way to solve my problem.Make look to MDI.zip, it opens new document when menu items are selected. Each document (with its view and child frame) is created using different document template.
shall i implement in this way,or it will creat any problem in future.
following is my program:
prati at 2007-11-11 1:44:55 >

# 34 Re: How to add support for switching the view ?
I would do it this way:
JohnCz at 2007-11-11 1:45:53 >

# 35 Re: How to add support for switching the view ?
Sir,
Thanks for your every quick responses. I'm glad there are still people willing to help a rookie out.
And, also got exact point for which i was just pecking my code again and agian like a woodpecker.
Well, again thanks
prati.
prati at 2007-11-11 1:46:57 >

# 36 Re: How to add support for switching the view ?
You are very welcome. i am glad to be of help.
JohnCz at 2007-11-11 1:48:01 >

# 37 Re: How to add support for switching the view ?
Hello JohnCz sir and Pratibha (prati )
I read ur all posts on finding solution for switching between views. I downloaded those application which are there.
I am doing one project in which I have created a tab control and in which I want to fit web browser (CHtmlView). As tabs are created dynamically , I am going to create tabs and a new instance of CHtmlView. ( Jus like tabbed browsing). How can I set a single document for all those views created? I want to use that document to serilize the data.
I somewhat read about AddDocument method CDocTemplate? Can u both tell me how can I achieve this?
If u are not able to understande my problem , please let me know, I will try elaborate it.
# 38 Re: How to add support for switching the view ?
whatever i understood is that, you are creating SDI application
with so many views.And want to put tab controls, each tab contains a different view. Right ?
prati at 2007-11-11 1:49:55 >

# 39 Re: How to add support for switching the view ?
Hi
Yes , Whatever U understood is correct ! I want exactly same thing, Have u done this kind of stuff ? Or Do u know how I can do this ?
( One Private Question: Are u from India ? Ur name sounds like so)
# 40 Re: How to add support for switching the view ?
Just create tab control as a child of the main frame and each consecutive view as child of the tab, adding new item when you create view.
Give each view unique ID that you can easy decode and use the same technique as in sample to swap views.
For example: assign ID from a tab number. When selection change hide view from previous selection (or all for that nmatter); show and resize window that has selected tab ID.
Override OnSize in a tab to resize only view that view in the client area of the tab.
JohnCz at 2007-11-11 1:51:57 >

# 41 Re: How to add support for switching the view ?
first of all , Thanks for ur reply !
But let me know how can I attach a document to all those views. Later on It will need to serialize the view.Can I attach a single document or is it neede seaperate document for each view?
Waiting for ur reply.
# 42 Re: How to add support for switching the view ?
I presume that you are referring to a document instance, not class.
Once view is created, it is added to a document object.
All information needed to do that is to pass pointer to a CCreateContext class (structure) initialized with proper values.
This code will do just that in a frame window:
CRuntimeClass *pClass = RUNTIME_CLASS(CSomeClass);
CWnd *pWnd = (CWnd*)pClass->CreateObject();
CCreateContext cntxt;
cntxt.m_pCurrentDoc = GetActiveDicument(); //ot obtain pointer some other way
cntxt.m_pCurrentFrame = this;
cntxt.m_pNewViewClass = pClass;
ASSERT_KINDOF(CWnd, pWnd);
pWnd->Create(NULL, NULL, AFX_WS_DEFAULT_VIEW,
CRect(0,0,0,0), this, AFX_IDW_PANE_FIRST + 2, &cntxt);
JohnCz at 2007-11-11 1:54:04 >

# 43 Re: How to add support for switching the view ?
Thanks for ur solution, It worked fine and solved my problem,
But the next problem is that when I overirder the method of CDocument::OnFileSendMail , It opens the default mail client,
I was expecting to attach a html document ( since my view is html view ) as attachment.But it fails to attach it and shows the size of attachment is 0 bytes. I think that It couldn't serialze the document. My docuement is attached to CHtmlView.Can u please tell me that what should I do to solve this problem ?
# 44 Re: How to add support for switching the view ?
Originally posted by ajay_sonawane7
My docuement is attached to CHtmlView.Can u please tell me that what should I do to solve this problem ? It the other way around. View is attached to a document.
As for the rest you would have to give more details about what you are trying to accomplish. I would suggest creating new thread.
JohnCz at 2007-11-11 1:56:10 >

# 45 Re: How to add support for switching the view ?
Hello Sir
I want to send mail attaching the html document currently displayed in CHtmlView.
I want to use the method of CDocument::OnFileSendMail to achieve this. So I created a sample application whose view is derived from ChtmlView. After that , I overrided the method of OnFileSendMail of CHtmlView.The document serializes itself but shows the 0 bytes of file attached along with mail. ( When I click on Send Mail menu , it opens a new message using Default Mail Client ).
But when I tried the same using CEditView , it serializes content of view and attached the file with mail,
My question is why is it failing for CHtmlView ?
# 46 Re: How to add support for switching the view ?
CEdit class has already serialization build in and document created by app wizard has proper call in ID_FILE_SEND_MAIL command handler.
Just a side note: Defaulr implementation assumes (wrongly) that edit view is the only view wired to document and moreover it assumes (wrongly again) that firs view added to a document list is edit view.
ChtmlView does not have native support, therefore you have to implement it.
JohnCz at 2007-11-11 1:58:10 >

# 47 Re: How to add support for switching the view ?
Hi,
i would like to create an SDI with the ability of switching from one view to another like the application reported here (http://www.dev-archive.com/forum/showpost.php?p=958149&postcount=10):this is an MDI,but i would like my application to work exactly like this,while handling only one document.
Can you help me?
Thanks in advance!
Fraben at 2007-11-11 1:59:11 >

# 48 Re: How to add support for switching the view ?
I wrote this sample for MDI, hence switching views is handled by a parent of all views: child frame.
The same should be done in SDI in main frame window. Just port relevant code to main frame class.
JohnCz at 2007-11-11 2:00:09 >

# 49 Re: How to add support for switching the view ?
Thank you very much JohnCz!
Fraben at 2007-11-11 2:01:16 >

# 50 Re: How to add support for switching the view ?
You are very welcome.
JohnCz at 2007-11-11 2:02:14 >
