diff --git a/Common/CreateFile.cpp b/Common/CreateFile.cpp
index 5731e1490ecb47e0eb8510d20b283ebb05f1a643..55bca74e0258e41a4ce32627a2f9e5d25960e978 100644
--- a/Common/CreateFile.cpp
+++ b/Common/CreateFile.cpp
@@ -23,11 +23,6 @@
 #include "gl2yuv.h"
 #endif
 
-#if defined(WIN32)
-#undef min
-#undef max
-#endif
-
 int GuessFileFormatFromFileName(std::string fileName)
 {
   std::string ext = SplitFileName(fileName)[2];
diff --git a/Common/Options.cpp b/Common/Options.cpp
index 893e5902f89386c8ec0644013f2f58334f3ce6ec..d4d17aec8e66dec820d4e851282549efc98bfd51 100644
--- a/Common/Options.cpp
+++ b/Common/Options.cpp
@@ -40,11 +40,6 @@
 #include "clippingWindow.h"
 #endif
 
-#if defined(WIN32)
-#undef min
-#undef max
-#endif
-
 // General routines for string options
 
 bool StringOption(int action, const char *category, int num, 
diff --git a/Graphics/PixelBuffer.h b/Graphics/PixelBuffer.h
index 4669b11afea4edff9144238b079fea8963a466f5..2c3216da745dec59568897afff797ef67c6a2241 100644
--- a/Graphics/PixelBuffer.h
+++ b/Graphics/PixelBuffer.h
@@ -11,6 +11,12 @@
 #include "GmshMessage.h"
 #include "Draw.h"
 
+#if defined(WIN32)
+#include <windows.h>
+#undef min
+#undef max
+#endif
+
 #if defined(__APPLE__)
 #include <OpenGL/gl.h>
 #include <OpenGL/glu.h>
diff --git a/Graphics/drawContext.h b/Graphics/drawContext.h
index 42da54c3a6af9fdb51874721c3a791cfb9e87947..50a7d6a1d1916a64511a23d865aa180fa1001998 100644
--- a/Graphics/drawContext.h
+++ b/Graphics/drawContext.h
@@ -11,6 +11,12 @@
 #include <set>
 #include "SBoundingBox3d.h"
 
+#if defined(WIN32)
+#include <windows.h>
+#undef min
+#undef max
+#endif
+
 #if defined(__APPLE__)
 #include <OpenGL/gl.h>
 #include <OpenGL/glu.h>
diff --git a/Plugin/CutPlane.cpp b/Plugin/CutPlane.cpp
index b1cca992e1ca8198ac7cd66ae536941709d6fb94..4fb9bfe9e942b68b04894e19d4a6736e03fe6d70 100644
--- a/Plugin/CutPlane.cpp
+++ b/Plugin/CutPlane.cpp
@@ -12,11 +12,6 @@
 #include "Draw.h"
 #endif
 
-#if defined(WIN32)
-#undef min
-#undef max
-#endif
-
 int GMSH_CutPlanePlugin::iview = 0;
 
 StringXNumber CutPlaneOptions_Number[] = {
diff --git a/Plugin/Probe.cpp b/Plugin/Probe.cpp
index a6d617f5d855dbffeff7bdab37b5a4c80dc89a9c..3f821e686aaf1554a814930e1b3f3c2cf9972740 100644
--- a/Plugin/Probe.cpp
+++ b/Plugin/Probe.cpp
@@ -14,11 +14,6 @@
 #include "Draw.h"
 #endif
 
-#if defined(WIN32)
-#undef min
-#undef max
-#endif
-
 int GMSH_ProbePlugin::iview = 0;
 
 StringXNumber ProbeOptions_Number[] = {