1:為什么要 #define WIN32_LEAN_AND_MEAN 。答案很簡單,因為要包含盡量精簡的內容,包含了這一句編譯的時候明顯快多了。
2:不加載MFC所需的模塊。如果你的工程不使用MFC,就加上這句,這樣一來在編譯鏈接時,包括最后生成的一些供調試用的模塊時,速度更快,容量更小。
3:我想這個不是 MFC 特有的, WIN32_LEAN_AND_MEAN 是針對 Win32 相關的頭文件的, 比如在包含 WIN32/MFC SDK 頭文件之前定義些宏, 可以通過預處理來關閉掉一些不太常用的系統接口或參數, 這樣可以加快編譯的速度!你可以看看 Windows.h 文件里和 WIN32_LEAN_AND_MEAN 相關的部分就明白了, 另外在這個文件開始部分一個注釋, 這里有很多更詳細的控制開關(宏)
In the Windows.h header, if WIN32_LEAN_AND_MEAN is not defined, the preprocessor will includes other headers. So if you want to not include theses headers, you must define WIN32_LEAN_AND_MEAN before #include , else it won't have any effects
#ifndef WIN32_LEAN_AND_MEAN #include <cderr.h> #include <dde.h> #include <ddeml.h> #include <dlgs.h> #ifndef _MAC #include <lzexpand.h> #include <mmsystem.h> #include <nb30.h> #include <rpc.h> #endif #include <shellapi.h> #ifndef _MAC #include <winperf.h> #include <winsock.h> #endif #ifndef NOCRYPT #include <wincrypt.h> #include <winefs.h> #include <winscard.h> #endif #ifndef NOGDI #ifndef _MAC #include <winspool.h> #ifdef INC_OLE1 #include <ole.h> #else #include <ole2.h> #endif /* !INC_OLE1 */ #endif /* !MAC */ #include <commdlg.h> #endif /* !NOGDI */ #endif /* WIN32_LEAN_AND_MEAN */
Directly from Windows.h