c++ - windows.h 和 MFC

标签 c++ mfc afx

为什么我不能在 afx(MFC) 项目中包含 windows.h?

最佳答案

通常,MFC 应用程序代码包括afx.hafxwin.h(后者包含前者)。 windows.h 的前两行是

#ifndef _WINDOWS_
#define _WINDOWS_

这意味着如果包含此 header ,则 _WINDOWS_ 已定义。 Afx.h 包括 afxver_.h 并且此 header 包括 afxv_w32.h 其中包含以下代码:

#ifdef _WINDOWS_
    #error WINDOWS.H already included. MFC apps must not #include <windows.h>
#endif
...
#include <windows.h>

因此,如果您在 MFC header 之前包含 windows.h,您将在编译时遇到此错误,并且如您所见,如果您包含 afxwin.h 您不需要自己包含 windows.h - 它已经包含在 afxv_w32.h 中。

关于c++ - windows.h 和 MFC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5026799/

相关文章:

c++ - 类内定义的友元函数属于哪个作用域?

c++ - 使用具有多个顶层窗口的 MFC MDI

visual-studio-2008 - Visual C++ 2008,#include "afxdb.h"时出错

c++ - 调用父类中的方法

c++ - 如何访问 QNetworkReply->readAll()?

python - 如何使用 <numpy/arrayobject.h> 在 C++ 中从 np.array 获取数据到 std::vector?

c++ - 使用 GDAL 库加载图像 (VC++)

winapi - 模式对话框的消息泵如何与主应用程序消息泵交互?

c++ - 为特定的 mfc dll 调用 AfxEnableMemoryLeakDump

c++ - 在 AFX 中使用什么函数对这些密码进行编码?