|
-
April 10th, 2008, 07:40 AM
#1
[SOLVED] Calling cdialog function from a subclassed control
I am not very pratical with classes interaction and I would like to know why if I declare a CDialog member variable into my subclassed control's class, visual studio gives weird errors like error C2065: 'IDD_MY_DIALOG' : undeclared identifier
Better explanation:
I have a mfc dialog with its nice class CMyDialog and all handlers.. OnInitDialog.. OnCancel... etc...
I have a control subclassed to something.. CStatic for example, so I have a class for this control derived from CStatic, and I'll call CMyCustomLabel
Why if I try to
#include "MyDialog.h"
into MyCustomLabel.h, visual studio starts to give me a lot of strange errors?
How do I call a function inside CMyDialog from a function inside CMyCustomLabel ??
Can't understand this problem..
Last edited by NasterMain; April 10th, 2008 at 02:47 PM.
Reason: Problem Solved Brilliantly
-
April 10th, 2008, 07:51 AM
#2
Re: Calling cdialog function from a subclassed control
First, dialog IDs (ie. 'IDD_MY_DIALOG') are typically stored in "resource.h". Make sure you include resource.h. Second, from your problem description, it would appear that you are trying to display a dialog/call a dialog function from within a static control. Is this correct? How are you planning to accomplish this? You may want to post some code that shows what you are trying to accomplish.
Gort...Klaatu, Barada Nikto!
-
April 10th, 2008, 08:08 AM
#3
Re: Calling cdialog function from a subclassed control
Here's an example of what I am trying to do:
#include "MyDialog.h" <- only including this causes me to have a LOT of weird errors
#pragma once
// CTabClass
class CTabClass : public CTabCtrl
{
DECLARE_DYNAMIC(CTabClass)
public:
CTabClass();
virtual ~CTabClass();
protected:
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnTcnSelchange(NMHDR *pNMHDR, LRESULT *pResult);
CMyDialog dlg;
};
Simple including a .h file of a mfc dialog class causes a lot of errors, here's some:
1> c:\blabla..\tabclass.h(6) : see declaration of 'CTabClass'
1>c:\blabla..\tabclass.cpp(10) : error C2027: use of undefined type 'CTabClass'
1> c:\blabla..\tabclass.h(6) : see declaration of 'CTabClass'
1>c:\blabla..\tabclass.cpp(10) : error C2496: 'classCTabClass' : 'selectany' can only be applied to data items with external linkage
1>c:\blabla..\tabclass.cpp(10) : error C2027: use of undefined type 'CTabClass'
1> c:\blabla..\tabclass.h(6) : see declaration of 'CTabClass'
1>c:\blabla..\tabclass.cpp(10) : error C2027: use of undefined type 'CTabClass'
1> c:\blabla..\tabclass.h(6) : see declaration of 'CTabClass'
1>c:\blabla..\tabclass.cpp(10) : error C2027: use of undefined type 'CTabClass'
1> c:\blabla..\tabclass.h(6) : see declaration of 'CTabClass'
1>c:\blabla..\tabclass.cpp(10) : error C2027: use of undefined type 'CTabClass'
1> c:\blabla..\tabclass.h(6) : see declaration of 'CTabClass'
1>c:\blabla..\tabclass.cpp(10) : error C2270: 'GetRuntimeClass' : modifiers not allowed on nonmember functions
1>c:\blabla..\tabclass.cpp(10) : error C2027: use of undefined type 'CTabClass'
1> c:\blabla..\tabclass.h(6) : see declaration of 'CTabClass'
1>c:\blabla..\tabclass.cpp(12) : error C2027: use of undefined type 'CTabClass'
1> c:\blabla..\tabclass.h(6) : see declaration of 'CTabClass'
1>c:\blabla..\tabclass.cpp(12) : error C2059: syntax error : ')'
1>c:\blabla..\tabclass.cpp(13) : error C2143: syntax error : missing ';' before '{'
1>c:\blabla..\tabclass.cpp(13) : error C2447: '{' : missing function header (old-style formal list?)
and so on..
What's wrong?? ._.
-
April 10th, 2008, 08:16 AM
#4
Re: Calling cdialog function from a subclassed control
What source file is generating the errors?
Gort...Klaatu, Barada Nikto!
-
April 10th, 2008, 09:24 AM
#5
Re: Calling cdialog function from a subclassed control
the .h file of the control subclassed from CTabCtrl
And the error of IDD_MY_DIALOG undefined (that is NOT true, if i remove that include the compiling process goes okay) from the .h file of CMyDialog
Dunno what's wrong (
-
April 10th, 2008, 09:54 AM
#6
Re: Calling cdialog function from a subclassed control
Try moving the include file inside the pragma.
Gort...Klaatu, Barada Nikto!
-
April 10th, 2008, 11:11 AM
#7
Re: Calling cdialog function from a subclassed control
No success, same errors
-
April 10th, 2008, 11:32 AM
#8
Re: Calling cdialog function from a subclassed control
If the code is not too large, I would suggest you post the cpp and header file(s) using Code tags. More than likely, the order of includes is at fault here.
Gort...Klaatu, Barada Nikto!
-
April 10th, 2008, 11:41 AM
#9
Re: Calling cdialog function from a subclassed control
I searched a little and I found I am trying to include B.h into A.h and A.h into B.h and this is not possible, this mechanism seems to be called "Header Guard"
Using the #define symbols should solve the problem, but still can't get it working!
Someone knows more please?
-
April 10th, 2008, 11:48 AM
#10
Re: Calling cdialog function from a subclassed control
Here are the two include files:
-------------------------------- TabClass.h-------------------------
#pragma once
// CTabClass
class CPropListBoxDlg; <- THIS SHOULD TELL THE COMPILER A CPROPLISTBOXDLG IS ALREADY DEFINED
class CTabClass : public CTabCtrl
{
DECLARE_DYNAMIC(CTabClass)
public:
CTabClass();
virtual ~CTabClass();
protected:
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnTcnSelchange(NMHDR *pNMHDR, LRESULT *pResult);
CPropListBoxDlg m_dlg;
};
----------------------------------------------------------------------
---------------PropListBoxDlg.h ----------------------------------
#if !defined(AFX_PROPLISTBOXDLG_H__B8AE534A_3892_11D4_BC48_00105AA2186F__INCLUDED_)
#define AFX_PROPLISTBOXDLG_H__B8AE534A_3892_11D4_BC48_00105AA2186F__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "afxcmn.h"
#include "tabclass.h" <- INCLUDED
/////////////////////////////////////////////////////////////////////////////
// CPropListBoxDlg dialog
class CPropListBoxDlg : public CDialog
{
// Construction
public:
CPropListBoxDlg(CWnd* pParent = NULL); // standard constructor
~CPropListBoxDlg();
// Dialog Data
//{{AFX_DATA(CPropListBoxDlg)
enum { IDD = IDD_PROPLISTBOX_DIALOG };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CPropListBoxDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
public:
CTabClass m_tabctrl; <- MEMBER
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_PROPLISTBOXDLG_H__B8AE534A_3892_11D4_BC48_00105AA2186F__INCLUDED_)
---------------------------------------------------------------
It is surely an header inclusion error
Additionally I neither can't find a good link to read about this "headerguard" system.. ._.
-
April 10th, 2008, 12:04 PM
#11
Re: Calling cdialog function from a subclassed control
Earlier, I asked what your intentions were with this design. Now that you've posted code, I'm beginning to think your program design may be at fault. Assuming I am wrong, you will need to define 'm_dlg' (in TabClass.h) as a CDialog object pointer and cast it to 'CPropListBoxDlg' when you use it.
I still think you need to reconsider your program design and interaction first.
Gort...Klaatu, Barada Nikto!
-
April 10th, 2008, 01:52 PM
#12
Re: Calling cdialog function from a subclassed control
Definitely you are right, Mike, the design smells not good. Define in class a member that has inside the member of the class currently being defined... Disaster. Nevertheless,..
Code:
// CTabClass
class CPropListBoxDlg; <- THIS SHOULD TELL THE COMPILER A CPROPLISTBOXDLG IS ALREADY DEFINED
// :D Never it should! This just hints the compiler that the symbolic
// name is a name of class defined somewhere to let the
// compiler be aware of variable pointer size if any would have been met
// prior that class full declaration
class CTabClass : public CTabCtrl
{
DECLARE_DYNAMIC(CTabClass)
public:
CTabClass();
virtual ~CTabClass();
protected:
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnTcnSelchange(NMHDR *pNMHDR, LRESULT *pResult);
CPropListBoxDlg* m_pDlg; // that would be enough to calm your compiler down
};
Last edited by Igor Vartanov; April 10th, 2008 at 02:00 PM.
Best regards,
Igor
-
April 10th, 2008, 02:46 PM
#13
Re: Calling cdialog function from a subclassed control
Thanks so much to everyone, problem solved.
This inclusion system is called: "Forward Declarations" and lets two classes perform a "reciprocal inclusion"
Notice that the pointer to CPropListBoxDlg class has to be initialized into the constructor of the CTabClass class:
CTabClass::CTabClass(CPropListBoxDlg *pointer)
{
m_pDlg = pointer;
}
I'll write an article soon or later about this mechanism I just learned, because excepted for this great forums, web lacks of papers at this purpose.
Thanks again to everyone!
-
April 10th, 2008, 03:08 PM
#14
Re: Calling cdialog function from a subclassed control
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|