F
F
Fat Lorrie2013-12-26 16:21:49
C++ / C#
Fat Lorrie, 2013-12-26 16:21:49

How to solve the problem of working with a dialog class in an MFC project?

MSVS 2010. There is a dialog application based on MFC. There is some controller class in which I want to store a pointer to the dialog object for subsequent interaction. But when you try to attach the dialog header file ( Project_nameDlg.h ) to the controller, the compiler starts swearing at all sorts of nonsense (that the define-constant IDD_PROJECT_NAME_DIALOG is not defined - the identifier of the dialog in resource.h, and there it swears that ";" is expected before the constants ).
Clearly: let there be a dialog class CProject_nameDlg and another class Test, with a pointer to the first one.

/* Project_nameDlg.h */
#pragma once
#include "afxwin.h"

class CProject_nameDlg : public CDialog {
public:
  CProject_nameDlg(CWnd* pParent = NULL);	// standard constructor
  enum { IDD = IDD_PROJECT_NAME_DIALOG };
.......
};

/* Test.h */
#include "Project_nameDlg.h"

stuct Test {
  CProject_nameDlg* ptr_;

  Test(CProject_nameDlg* ptr)  :  ptr_( ptr ) { }
 };

I suspect that this is somehow related to resources and some kind of internal code generation, which gets lost at the second inclusion of the ill-fated dialog class. Forces to do "intelligent interface" instead of MVC. But everything should not be so clumsy, maybe there is some kind of workaround?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
Fat Lorrie, 2013-12-27
@Free_ze

The problem was solved by a hard forced inclusion resource.hin the dialog header file ( Project_nameDlg.h). Because there are define constants, then there will be no collision (overridden), but I will be sure that I will not catch

undeclared identifier IDD_PROJECT_NAME_DIALOG

Also found:
stackoverflow.com/questions/20651931/how-to-access...

G
Gadya Petrovich, 2013-12-26
@digitallez

There is probably something wrong with the order of the includes (maybe even in the place where it says #include "Test.h").
Try adding at the beginning of Test.h :
#pragma once
#include "afxwin.h"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question