gpt4 book ai didi

c++ - windows.h 和 MFC

转载 作者:可可西里 更新时间:2023-11-01 18:21:51 27 4
gpt4 key购买 nike

为什么我不能在 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com