为什么我不能在 afx(MFC) 项目中包含 windows.h?
最佳答案
通常,MFC 应用程序代码包括afx.h
或afxwin.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/