CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2009
    Location
    Aarhus, Denmark
    Posts
    7

    [MFC Newbie] workflow for calling function from InitInstance

    Hi everybody.

    As some of you might have read in my previous thread (http://www.codeguru.com/forum/showthread.php?t=476458) I'm trying to add a commandline interface to an existing MFC application.

    I'm new to MFC, but do have some C++ experience.

    Even though I'm new to MFC, I've found out that it's a SDI app, and I've read about the relationship between the CMainFram, CView and CDocument classes.

    Here is what I want to do: Once I locate a switch (or option) in my commandline, I want to execute a function from my InitInstance() - code exampel below:

    Code:
    BOOL CMyMlvApp::InitInstance()
    {
    	....
    
    	CommandLineParser cmdInfo;
    	ParseCommandLine(cmdInfo);
    
    	if(cmdInfo.IsLoad())
    	{
                    //Here I want to call the load-function
    		AfxMessageBox("Hello World from Load");
    	}
    	if(cmdInfo.IsVerify())
    	{
                    //Here I want to call the verify-function
    		AfxMessageBox("Hello World from Verify");
    	}
    	if(cmdInfo.IsReset())
    	{
                    //Here I want to call the reset-function
    		AfxMessageBox("Hello World from Reset");
    	}
    
    	// Dispatch commands specified on the command line
    	if (!ProcessShellCommand(cmdInfo))
    		return FALSE;
    
            ....
    }
    I've located the functions I want to call in the CDocument class
    Code:
    void CMyMlvDoc::OnFunctionVerify() 
    {
    	CRtMem RtMem(&m_MlvConfig,m_ProcessorId);
    	
    	if (RtMem.m_Status==RT_OK)
    	{
    		CVerifyDlg dlg(&RtMem,&m_hexlineList);
    		
    		dlg.m_VerifyDescription=GetTitle();
    		
    		dlg.DoModal();
    	}
    	else
    		AfxMessageBox("Verify failed");
    }
    I have tried creating an object of CMyMlvDoc, and calling the "OnFunctionVerify()", but it's protected. And I've tried copying the content of the function directly into the InitInstance - no succes.

    So what I want to know is: how is the workflow for calling this function in my InitInstance-function?

    If you need any more information, let me know

    //Kasper D.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: [MFC Newbie] workflow for calling function from InitInstance

    The "workflow" is:
    ProcessShellCommand calls CWinApp::OnFileNew to start the application with an empty document if no file name was entered on the command line, or CWinApp::OpenDocumentFile to start the application and load a document if a document name was specified. It is during this phase of the program's execution that the framework creates the frame window, document, and view objects using run-time class information contained in the document template. ProcessShellCommand returns TRUE if the initialization succeeded and FALSE if it did not. A FALSE return causes InitInstance to return FALSE also, which shuts down the application.
    Victor Nijegorodov

  3. #3
    Join Date
    May 2009
    Location
    Aarhus, Denmark
    Posts
    7

    Re: [MFC Newbie] workflow for calling function from InitInstance

    In my InitInstance-function, I've located the following block:

    Code:
    	CMySingleDocTemplate* pDocTemplate;
    	pDocTemplate = new CMySingleDocTemplate(
    		IDR_MAINFRAME,
    		RUNTIME_CLASS(CMyMlvDoc),
    		RUNTIME_CLASS(CMainFrame),       // main SDI frame window
    		RUNTIME_CLASS(CMyMlvView));
    	AddDocTemplate(pDocTemplate);
    Could this pDocTemplate be used to acces the function? And how?

    //Kasper D.

  4. #4
    Join Date
    May 2009
    Location
    Aarhus, Denmark
    Posts
    7

    Re: [MFC Newbie] workflow for calling function from InitInstance

    Hi Victor.

    From where are you quoting this? I would like to read the full text

    And as you can see in the post I made simultaniously with yours, I'm pretty sure the InitInstance opens a Document for me - right?

    //Kasper D.

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: [MFC Newbie] workflow for calling function from InitInstance

    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured