如何从 MFC 中的对话框头文件访问静态变量

How to access static variable from Dialog header file in MFC

本文关键字:文件 访问 静态 变量 对话框 MFC      更新时间:2023-10-16

CDialog我在CDialogDlg.h中有static int mStatus;。我喜欢从另一个cpp file访问该静态变量,例如 test.cpp 。通常我们访问静态变量CDialogDlg::mStatus = 1.但是当我CDialogDlg.h包含在test.h中时,我得到了两个编译错误

 Error 1: error C2504: 'CDialogEx' : base class undefined
 Error 2: error C2065: 'IDD_CDialog_DIALOG' : undeclared identifier

为什么我不能将CDialogDlg.h包含在test.h中.我对MFC不是很熟悉。谢谢。

由于默认情况下#include "resource.h"通常包含在头文件中,因此CMyNameApp.h它应该已#include <afxdialogex.h>。即使您可以从标头中删除#include "resource.h",也必须再次包含它。

#include "resource.h"
#include <afxdialogex.h>

应该解决你的整个问题。