?
Solved

Deriving a class from CFileDialog & displaying Open/Save dialog

Posted on 1998-10-19
2
Medium Priority
?
827 Views
Last Modified: 2013-11-20
When creating a dialog based app, I create a new class &
derive it from CFileDialog. I am trying to display the Open & Save dialog, but it doesen't work.  I've asked this question before and followed instructions from Answer2000.
Now I am getting a "unresolved external" error after I build the application. Here is a snippet of my code.
The class declaration is here:


#if !defined(AFX_FILEOPENSAVE_H__76822602_5EB8_11D2_AC74_444553540000__INCLUDED_)
#define AFX_FILEOPENSAVE_H__76822602_5EB8_11D2_AC74_444553540000__INCLUDED_

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
// FileOpenSave.h : header file
/////////////////////////////////////////////////////////////////////////////
// CFileOpenSave dialog

class CFileOpenSave : public CFileDialog
{
      DECLARE_DYNAMIC(CFileOpenSave)

            
public:
      CFileOpenSave(BOOL bOpenFileDialog, // TRUE for FileOpen, FALSE for FileSaveAs
            LPCTSTR lpszDefExt = NULL,
            LPCTSTR lpszFileName = NULL,
            DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
            LPCTSTR lpszFilter = NULL,
            CWnd* pParentWnd = NULL);
      

     
      CFileOpenSave(); //constructor function declared here

protected:
      //{{AFX_MSG(CFileOpenSave)
      afx_msg void OnFileOpen();
      //}}AFX_MSG
      DECLARE_MESSAGE_MAP()
};
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////

The .cpp file is here:

// FileOpenSave.cpp : implementation file
//

#include "stdafx.h"
#include "Table2.h"
#include "FileOpenSave.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CFileOpenSave

IMPLEMENT_DYNAMIC(CFileOpenSave, CFileDialog)

CFileOpenSave::CFileOpenSave(BOOL bOpenFileDialog, LPCTSTR lpszDefExt, LPCTSTR lpszFileName,
            DWORD dwFlags, LPCTSTR lpszFilter, CWnd* pParentWnd) :
            CFileDialog(bOpenFileDialog, lpszDefExt, lpszFileName, dwFlags, lpszFilter, pParentWnd)
{
}

      

BEGIN_MESSAGE_MAP(CFileOpenSave, CFileDialog)
      //{{AFX_MSG_MAP(CFileOpenSave)
      ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
      //}}AFX_MSG_MAP
END_MESSAGE_MAP()


void CFileOpenSave::OnFileOpen()
{
      
    CFileOpenSave dlgOpSv;
    dlgOpSv.DoModal();

    // TODO: Add your command handler code here
    //This is my problem.  I don't know why it's not     //working!
}


My dialog box has a menu with File|Open, but doesn't create the dialog.  I've included the <afxdlgs.h> file in the stdfx.h f header & still nothing.  The only time
it works is if I create an SDI or MDI app.
If you are out there, please Help, Answers2000.
I've looked in my books to trubleshoot this problem &
in the MFC help.  Still having problems. (Remember,
I'm a beginner...)

0
Comment
Question by:pagz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 7

Expert Comment

by:psdavis
ID: 1323522
Give us the unresolved error so we can see it!
0
 
LVL 7

Accepted Solution

by:
psdavis earned 100 total points
ID: 1323523
Ahhh... I see it now...

void CFileOpenSave::OnFileOpen()
{
    CFileOpenSave dlgOpSv;
    dlgOpSv.DoModal();
}

You are trying to create the dialog by a function inside of the dialog.  The CFileOpenSave::OnFileOpen doesn't exist yet until the DoModal is run, but the DoModal is inside itself.

You're going to want to run it from a different class...

void CYourDialogBox::OnFileOpen()
{
    CFileOpenSave dlgOpSv;
    dlgOpSv.DoModal();
}

Phillip
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

801 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