CoderSource.net
Search
Different form
Started by agenore at 03-26-2006 10:34 PM. Topic has 20 replies.

Print Search « Previous Thread Next Thread »
   03-26-2006, 10:34 PM
agenore is not online. Last active: 7/24/2006 9:38:58 AM agenore



Top 10 Posts
Joined on 03-21-2006
Parma
Posts 26
Sad [:(] Different form
Hi,
I'm a new user of MFC Application. Until now I worked with C++ for console application (like parsing text and so on), with Visual Basic. Now, in VB I can create several form (modal or modeless) but in VC I don't understand how create form like.
Who Can help me?

   Report 
   03-27-2006, 1:31 AM
Yasir is not online. Last active: 11/16/2006 10:02:40 AM Yasir

Top 10 Posts
Joined on 03-15-2006
Posts 44
Re: Different form
Actually the form you used in VB to create the application are called dialogs in visual c++ application. If you create an application using MFC application wizard it will ask to select from 3 types of applications of MFC.
1)- Dialog based application (most likely form based application in VB)
2)- single document application
3)-Multidocument application
The later two have different archtecture than dialog based.
Just follow the step in the MFC application wizard and select the Dialog based application when it asks for mfc application type.
It will create a main dailog or form of the application. you can create any number of dialogs or forms by going into resource view and then right click the dialogs and then click insert. and select a dialog type. It will insert a new dialog in your application. you can associate some class with this dialog to handle different type of events. you can do this association by using the form wizard.
Just dobule click the dialog on some empty area it will open the class wizard and ask you to associate some class with this dialog. Seclect a class or new class name. and then it will associate this class with you dailoag. now come to the point from where you want to call or display that dialog.
Create and object of the class that is associated with that dialog. Then call the DoModel function of that object it will display your dialog.
Any events on this dialog will be handeled by the class that you just created.
If you have any other concerns plz feel free to ask but if you provide the refferences what you did and like that it will be great.

Best Regards
-Yasir
   Report 
   03-27-2006, 1:35 AM
Yasir is not online. Last active: 11/16/2006 10:02:40 AM Yasir

Top 10 Posts
Joined on 03-15-2006
Posts 44
Re: Different form
Hey

you can start learning mfc based applications with this serious of tutorials.

http://www.codersource.net/mfc_tutorial_Part1.html

Best Regards
-Yasir
   Report 
   03-27-2006, 2:34 AM
agenore is not online. Last active: 7/24/2006 9:38:58 AM agenore



Top 10 Posts
Joined on 03-21-2006
Parma
Posts 26
Re: Different form
Thanks, but I just bought a book 'How learn VC++ in 24 hours' (in italian) and it explain how make a dialog but that i need is:
Main MDI window, empty with only menu;
When I press a menu item start a custom form, if I repeat the same operation another form (like the first) will be open.
When I press a different menu item a different custom form will start.
Now I don't get this, I don't know to do different modeless form to reaction a different menu input.

   Report 
   03-27-2006, 6:14 AM
Yasir is not online. Last active: 11/16/2006 10:02:40 AM Yasir

Top 10 Posts
Joined on 03-15-2006
Posts 44
Re: Different form
Hi
Yes you cand do this all. First of all you need the study the MDI file architecture.
we can create different type of documets by creating differetn type of Dcoment, view and child window objects like this. As MDI architecture uses the CDocManager which has ability to handle multiple documents of multiple types. you can use
AddDocTemplate function to add different documents.
CMultiDocTemplate* pDocTemplate;
pDocTemplate = new CMultiDocTemplate(
IDR_MFCMDITYPE,
RUNTIME_CLASS(CMFCMDIDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CMFCMDIView));
AddDocTemplate(pDocTemplate);

Then you can trick on each different event create the object of different document type and view in the differnt child winodow.

Best Regards
-Yasir

   Report 
   03-28-2006, 4:09 AM
agenore is not online. Last active: 7/24/2006 9:38:58 AM agenore



Top 10 Posts
Joined on 03-21-2006
Parma
Posts 26
Re: Different form
Thanks!
I just read about MDI Architectures but when I tried to applie the concept it doesn't work. I don't found the mistake. Now I looking for an example on the web to understand the point.

   Report 
   03-28-2006, 10:50 AM
Yasir is not online. Last active: 11/16/2006 10:02:40 AM Yasir

Top 10 Posts
Joined on 03-15-2006
Posts 44
Re: Different form
Okie

Give it a try if does not work plz post with exact situation and your code. and what error it says. May be i will be able to help out.
   Report 
   04-02-2006, 11:24 PM
agenore is not online. Last active: 7/24/2006 9:38:58 AM agenore



Top 10 Posts
Joined on 03-21-2006
Parma
Posts 26
Re: Different form
Well, I found the method to realize multiple form but now I have another problem.
When I click on 'new file' a little form with all type of the documents appeare. How I Can to by pass this?
Thanks.

   Report 
   04-03-2006, 11:58 AM
Yasir is not online. Last active: 11/16/2006 10:02:40 AM Yasir

Top 10 Posts
Joined on 03-15-2006
Posts 44
Re: Different form
you have to create your own class inherited from CDocManager. Acctully when you click on the File New. onFileNew() function is called of CDocManager. you can override that function. and then onFilenew() function calls createNewdocument function. which actually creates new document.


Create your own cdocmanageryour class. inherit from CDocManager. override onFilenew and createnewdocument.
And in the initinstance function of CwinApp you need to replace the default document manager by yours created one.

m_pDocManager = new CDocManagerYours;

if you feel any difficulty feel free to contact me.

   Report 
   04-04-2006, 2:24 AM
agenore is not online. Last active: 7/24/2006 9:38:58 AM agenore



Top 10 Posts
Joined on 03-21-2006
Parma
Posts 26
Re: Different form
Uh.... I looking for the class CDocManager but I haven't found on MSDN Library. Same thing for the createNewdocument method. I have just found the method onFileNew().
Can I send to you the code of my example?

   Report 
   04-04-2006, 6:07 AM
Yasir is not online. Last active: 11/16/2006 10:02:40 AM Yasir

Top 10 Posts
Joined on 03-15-2006
Posts 44
Re: Different form
some classes of MFC are documented by msdn and provide the complete technical details about how they work. But some are completely missing CDocManager class is not listed int the MSDN. but that is class which handles your new file event.
you need to override the onNewFile() function.

yes you can put the code for your example.


   Report 
   04-06-2006, 1:58 AM
agenore is not online. Last active: 7/24/2006 9:38:58 AM agenore



Top 10 Posts
Joined on 03-21-2006
Parma
Posts 26
Sad [:(] Re: Different form
Well, I created a my docmanager, I replaced the method onNewFile() but now I have 2 another problems:
1) I put a message on the method onFileNew(), and when I start the application the message appear. How I can resolv it?
2) .... For create several document How can I do?
sorry for all question ... but I don't find a good documentation.

   Report 
   04-06-2006, 9:45 PM
Yasir is not online. Last active: 11/16/2006 10:02:40 AM Yasir

Top 10 Posts
Joined on 03-15-2006
Posts 44
Re: Different form
First of all no sorry because if we cant help some one then what is benifit of knowlege. any how you are most welcome.

1)--- In the class that is derived from WinApp in function on initinstance there is a call to processshellcommand like that.

if (!ProcessShellCommand(cmdInfo))
return FALSE;
Actually this call generates a ID_FILE_NEW event to create a new document at the start of application you can comment these two lines and at startup there will be no application.

2)----And for second question how to create multiple documents for different events. Below is the code for onFileNew() i got from the MFC source. See what it does.

void CDocManager::OnFileNew()
{
if (m_templateList.IsEmpty())
{
TRACE0("Error: no document templates registered with CWinApp.\n");
AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC);
return;
}

CDocTemplate* pTemplate = (CDocTemplate*)m_templateList.GetHead();
if (m_templateList.GetCount() > 1)
{
// more than one document template to choose from
// bring up dialog prompting user
CNewTypeDlg dlg(&m_templateList);
int nID = dlg.DoModal();
if (nID == IDOK)
pTemplate = dlg.m_pSelectedTemplate;
else
return; // none - cancel operation
}

ASSERT(pTemplate != NULL);
ASSERT_KINDOF(CDocTemplate, pTemplate);

pTemplate->OpenDocumentFile(NULL);
// if returns NULL, the user has already been alerted
}

Gets the head document template from template list. and then call openDocumentFile for that template.
What you can trick is just keep empty the OnFileNew() function but create another function of ur docmanager class say CreateDiffDocs and do some code like this. pass the index of the document in the list to which you want to create the document.

CreateDiffDocs(int index)
{
POSITION p;
CDocTemplate *temp;
p=m_templatelist.Getheadpostion();
for(int i=0;i<=index;i++)
{
temp=m_templatelist.getNext(p);

}

//then call the opendocumentfile as in the onNewFile function.
}

I think that is enough to help you. if still had problems dont feel shy to message.

Best Regards
-Yasir
   Report 
   04-07-2006, 5:08 AM
agenore is not online. Last active: 7/24/2006 9:38:58 AM agenore



Top 10 Posts
Joined on 03-21-2006
Parma
Posts 26
Re: Different form
MFC Source? Where is It?

   Report 
   04-07-2006, 6:54 AM
Yasir is not online. Last active: 11/16/2006 10:02:40 AM Yasir

Top 10 Posts
Joined on 03-15-2006
Posts 44
Re: Different form

this is included with you visual studio installation. The exact path is.
..\Program Files\Microsoft Visual Studio\VC98\MFC

Best Regards
-Yasir
   Report 
  Page 1 of 2 (21 items) 1 2 »
Codersource.Net » Programming » MFC Programming » Different form

MENU
Home
MFC 
C++
.Net
WIN32
Programming
Forum
My Articles
Welcome to Codersource.Net Login | Register | Faq  

Google
 

NOTES:


Thanks for visiting our CoderSource.net. This site will be improved with more articles. Interested visitors can also submit their articles through the Submit Article link.Your article will also be published after due consideration by the editor. 

© Copyright 2003. All rights on content reserved by CoderSource.net. Contact    About Us