MFC Inclusion of Derived CEdit class

This is a discussion on MFC Inclusion of Derived CEdit class within the Windows Programming forums, part of the Platform Specific Boards category; Okay, I derived a class from CEdit, named CFileEdit. Where do I include the file/files at? I have about 20 ...

  1. #1
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802

    MFC Inclusion of Derived CEdit class

    Okay, I derived a class from CEdit, named CFileEdit. Where do I include the file/files at? I have about 20 differents source files, and I have no idea where to #include either FileEdit.h or FileEdit.cpp

    Whenever I create a variable of type CFileEdit I get 4 errors relating to undeclared identifier. If I put the include at the top of the same file I get the error in, I get the errors:

    C:\DOCUMENTS AND SETTINGS\ADMINISTRATOR\MY DOCUMENTS\MY PROJECTS\ColorCoder\ColorCoder.cpp(12) : error C2370: 'THIS_FILE' : redefinition; different storage class
    c:\documents and settings\administrator\my documents\my projects\colorcoder\fileedit.cpp(11) : see declaration of 'THIS_FILE'
    PageKeywords.cpp

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    All your .cpp and .h files should be included in your project....how this is done will differ by compiler....but its usualy pretty straightforward

    Basically, use an "#include CFileEdit.h" directive whenever you have source that makes an instance or makes reference to the object you have derived......also in the cpp file that you use to declare the member functions and statics of your derived class.......

    In your header, structure it like so...

    Code:
    #ifndef CMYDIALOG_H
    #define CMYDIALOG_H
    #include <afxwin.h>
    #include "resource.h"
    class CMyDialog : public CDialog  
    {
    public:
    	CMyDialog(CWnd* ParentWnd = NULL)
    		:CDialog(IDD_DIALOG1,ParentWnd){}
    protected:
    	virtual BOOL OnInitDialog();
    	void OnListen();
    	DECLARE_MESSAGE_MAP()
    	int nPortGiven;
    };
    #endif
    That should allow you to build the project without multiple declaration and also compile single modules..........

    This is all fairly basic stuff and I doubt if it's helping you........if you have any more indications at what the problem could be, please post them

  3. #3
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    Hmm, the file already has somewhat of the structure you suggested...

    Code:
    #if !defined(AFX_FILEEDIT_H__3D9FCD0F_B0F8_41A2_9ECB_09E1FA253CFA__INCLUDED_)
    #define AFX_FILEEDIT_H__3D9FCD0F_B0F8_41A2_9ECB_09E1FA253CFA__INCLUDED_
    
    #if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000
    // FileEdit.h : header file
    //
    
    /////////////////////////////////////////////////////////////////////////////
    // CFileEdit window
    
    class CFileEdit : public CEdit
    {
    // Construction
    public:
    	CFileEdit(LPCSTR szFileExt, LPCSTR szFileFilter);
    	CFileEdit();
    
    // Attributes
    public:
    
    // Operations
    public:
    
    // Overrides
    	// ClassWizard generated virtual function overrides
    	//{{AFX_VIRTUAL(CFileEdit)
    	//}}AFX_VIRTUAL
    
    // Implementation
    public:
    	LPCSTR GetFileExtension();
    	void SetFileExtension(LPCSTR szExt);
    	LPCSTR GetFileFilter();
    	void AddFileFilter(LPCSTR szFileFilter);
    	void SetFileFilter(LPCSTR szFirstArg, ...);
    	virtual ~CFileEdit();
    
    	// Generated message map functions
    protected:
    	CString m_szFileExt;
    	CString m_szFileFilter;
    	//{{AFX_MSG(CFileEdit)
    	afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
    	//}}AFX_MSG
    
    	DECLARE_MESSAGE_MAP()
    };
    
    /////////////////////////////////////////////////////////////////////////////
    
    //{{AFX_INSERT_LOCATION}}
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
    
    #endif // !defined(AFX_FILEEDIT_H__3D9FCD0F_B0F8_41A2_9ECB_09E1FA253CFA__INCLUDED_)
    I've always had this problem... I've never been able to use Derived classes for anything, I worked my way around it before but enough is enough...

    I think my book has an example of using derived classes in MFC, maybe that'll help, I'll check it and get back to ya.

    Edit:: I got it Thanks for the help
    Last edited by Dual-Catfish; 05-19-2002 at 09:46 AM.

  4. #4
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    I have another question...
    In the class CFileEdit, I have a Message handler for WM_LBUTTONDBLCLK(), but whenever I double click the control, nothing is happening...

    This is what the function looks like:

    Code:
    void CFileEdit::OnLButtonDblClk(UINT nFlags, CPoint point) 
    {
    	//AfxMessageBox("Hi!");
    	CFileDialog g_cfBrowseForFile(TRUE, m_szFileExt, NULL, OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST, m_szFileFilter);
    	if (g_cfBrowseForFile.DoModal() == IDOK)
    	{
    		CString szFileName;
    		szFileName = g_cfBrowseForFile.GetFolderPath();
    		CEdit::SetWindowText(szFileName);
    	}
    	CEdit::OnLButtonDblClk(nFlags, point);
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 10-31-2005, 12:05 PM
  2. Replies: 4
    Last Post: 12-29-2002, 12:29 AM
  3. Document Class and Dialog Windows :: MFC
    By kuphryn in forum Windows Programming
    Replies: 3
    Last Post: 12-01-2002, 12:27 AM
  4. Constructors + Derived class
    By MethodMan in forum C++ Programming
    Replies: 6
    Last Post: 11-10-2002, 05:05 PM
  5. Troubles overriding a const in a derived class
    By sh0x in forum C++ Programming
    Replies: 5
    Last Post: 10-05-2001, 08:11 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21