Thread: MFC Inclusion of Derived CEdit class

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

    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'

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    All your .cpp and .h files should be included in your 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...

    #ifndef CMYDIALOG_H
    #define CMYDIALOG_H
    #include <afxwin.h>
    #include "resource.h"
    class CMyDialog : public CDialog  
    	CMyDialog(CWnd* ParentWnd = NULL)
    	virtual BOOL OnInitDialog();
    	void OnListen();
    	int nPortGiven;
    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
    Hmm, the file already has somewhat of the structure you suggested...

    #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
    	CFileEdit(LPCSTR szFileExt, LPCSTR szFileFilter);
    // Attributes
    // Operations
    // Overrides
    	// ClassWizard generated virtual function overrides
    // Implementation
    	LPCSTR GetFileExtension();
    	void SetFileExtension(LPCSTR szExt);
    	LPCSTR GetFileFilter();
    	void AddFileFilter(LPCSTR szFileFilter);
    	void SetFileFilter(LPCSTR szFirstArg, ...);
    	virtual ~CFileEdit();
    	// Generated message map functions
    	CString m_szFileExt;
    	CString m_szFileFilter;
    	afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
    // 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 08:46 AM.

  4. #4
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    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:

    void CFileEdit::OnLButtonDblClk(UINT nFlags, CPoint point) 
    	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::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, 07:11 PM