Use min/max instead of MIN/MAX.

diff --git a/controls/edit.c b/controls/edit.c
index c10729e..29cf1ee 100644
--- a/controls/edit.c
+++ b/controls/edit.c
@@ -977,7 +977,7 @@
 			current_def->length = current_def->net_length;
 			break;
 		}
-		es->text_width = MAX(es->text_width, current_def->width);
+		es->text_width = max(es->text_width, current_def->width);
 		start += current_def->length;
 		*previous_next = current_def;
 		previous_next = &current_def->next;
@@ -1138,8 +1138,8 @@
  */
 static void EDIT_ConfinePoint(WND *wnd, EDITSTATE *es, LPINT x, LPINT y)
 {
-	*x = MIN(MAX(*x, es->format_rect.left), es->format_rect.right - 1);
-	*y = MIN(MAX(*y, es->format_rect.top), es->format_rect.bottom - 1);
+	*x = min(max(*x, es->format_rect.left), es->format_rect.right - 1);
+	*y = min(max(*y, es->format_rect.top), es->format_rect.bottom - 1);
 }
 
 
@@ -1351,20 +1351,20 @@
 	EDIT_UnlockBuffer(wnd, es, TRUE);
 	if (es->text) {
 		if ((es->text = HeapReAlloc(es->heap, 0, es->text, size + 1)))
-			es->buffer_size = MIN(HeapSize(es->heap, 0, es->text) - 1, es->buffer_limit);
+			es->buffer_size = min(HeapSize(es->heap, 0, es->text) - 1, es->buffer_limit);
 		else
 			es->buffer_size = 0;
 	} else if (es->hloc32) {
 		if ((hNew32 = LocalReAlloc(es->hloc32, size + 1, 0))) {
 			TRACE("Old 32 bit handle %08x, new handle %08x\n", es->hloc32, hNew32);
 			es->hloc32 = hNew32;
-			es->buffer_size = MIN(LocalSize(es->hloc32) - 1, es->buffer_limit);
+			es->buffer_size = min(LocalSize(es->hloc32) - 1, es->buffer_limit);
 		}
 	} else if (es->hloc16) {
 		if ((hNew16 = LOCAL_ReAlloc(wnd->hInstance, es->hloc16, size + 1, LMEM_MOVEABLE))) {
 			TRACE("Old 16 bit handle %08x, new handle %08x\n", es->hloc16, hNew16);
 			es->hloc16 = hNew16;
-			es->buffer_size = MIN(LOCAL_Size(wnd->hInstance, es->hloc16) - 1, es->buffer_limit);
+			es->buffer_size = min(LOCAL_Size(wnd->hInstance, es->hloc16) - 1, es->buffer_limit);
 		}
 	}
 	if (es->buffer_size < size) {
@@ -1698,8 +1698,8 @@
 	s = es->selection_start;
 	e = es->selection_end;
 	ORDER_INT(s, e);
-	s = MIN(li + ll, MAX(li, s));
-	e = MIN(li + ll, MAX(li, e));
+	s = min(li + ll, max(li, s));
+	e = min(li + ll, max(li, e));
 	if (rev && (s != e) &&
 			((es->flags & EF_FOCUSED) || (es->style & ES_NOHIDESEL))) {
 		x += EDIT_PaintText(wnd, es, dc, x, y, line, 0, s - li, FALSE);
@@ -1798,10 +1798,10 @@
 	}
 	es->format_rect.left += es->left_margin;
 	es->format_rect.right -= es->right_margin;
-	es->format_rect.right = MAX(es->format_rect.right, es->format_rect.left + es->char_width);
+	es->format_rect.right = max(es->format_rect.right, es->format_rect.left + es->char_width);
 	if (es->style & ES_MULTILINE)
 		es->format_rect.bottom = es->format_rect.top +
-			MAX(1, (es->format_rect.bottom - es->format_rect.top) / es->line_height) * es->line_height;
+			max(1, (es->format_rect.bottom - es->format_rect.top) / es->line_height) * es->line_height;
 	else
 		es->format_rect.bottom = es->format_rect.top + es->line_height;
 	if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL))
@@ -1988,7 +1988,7 @@
 		ERR("could not allocate new 32 bit buffer\n");
 		return 0;
 	}
-	newSize = MIN(LocalSize(newBuf) - 1, es->buffer_limit);
+	newSize = min(LocalSize(newBuf) - 1, es->buffer_limit);
 	if (!(newText = LocalLock(newBuf))) {
 		ERR("could not lock new 32 bit buffer\n");
 		LocalFree(newBuf);
@@ -2048,7 +2048,7 @@
 		ERR("could not allocate new 16 bit buffer\n");
 		return 0;
 	}
-	newSize = MIN(LOCAL_Size(wnd->hInstance, newBuf) - 1, es->buffer_limit);
+	newSize = min(LOCAL_Size(wnd->hInstance, newBuf) - 1, es->buffer_limit);
 	if (!(newText = LOCAL_Lock(wnd->hInstance, newBuf))) {
 		ERR("could not lock new 16 bit buffer\n");
 		LOCAL_Free(wnd->hInstance, newBuf);
@@ -2091,7 +2091,7 @@
 		line = 0;
 	i = EDIT_EM_LineIndex(wnd, es, line);
 	src = es->text + i;
-	len = MIN(*(WORD *)lpch, EDIT_EM_LineLength(wnd, es, i));
+	len = min(*(WORD *)lpch, EDIT_EM_LineLength(wnd, es, i));
 	for (i = 0 ; i < len ; i++) {
 		*lpch = *src;
 		src++;
@@ -2155,7 +2155,7 @@
 	if (index > lstrlenA(es->text))
 		return es->line_count - 1;
 	if (index == -1)
-		index = MIN(es->selection_start, es->selection_end);
+		index = min(es->selection_start, es->selection_end);
 
 	line = 0;
 	line_def = es->first_line_def;
@@ -2256,7 +2256,7 @@
 		dx = -es->x_offset;
 	if (dx > es->text_width - es->x_offset)
 		dx = es->text_width - es->x_offset;
-	nyoff = MAX(0, es->y_offset + dy);
+	nyoff = max(0, es->y_offset + dy);
 	if (nyoff >= es->line_count)
 		nyoff = es->line_count - 1;
 	dy = (es->y_offset - nyoff) * es->line_height;
@@ -2294,7 +2294,7 @@
 	HFONT old_font = 0;
 	SIZE size;
 
-	index = MIN(index, len);
+	index = min(index, len);
 	dc = GetDC(wnd->hwndSelf);
 	if (es->font)
 		old_font = SelectObject(dc, es->font);
@@ -2654,12 +2654,12 @@
 {
 	if (es->style & ES_MULTILINE) {
 		if (limit)
-			es->buffer_limit = MIN(limit, BUFLIMIT_MULTI);
+			es->buffer_limit = min(limit, BUFLIMIT_MULTI);
 		else
 			es->buffer_limit = BUFLIMIT_MULTI;
 	} else {
 		if (limit)
-			es->buffer_limit = MIN(limit, BUFLIMIT_SINGLE);
+			es->buffer_limit = min(limit, BUFLIMIT_SINGLE);
 		else
 			es->buffer_limit = BUFLIMIT_SINGLE;
 	}
@@ -2739,8 +2739,8 @@
 		start = es->selection_end;
 		end = es->selection_end;
 	} else {
-		start = MIN(start, len);
-		end = MIN(end, len);
+		start = min(start, len);
+		end = min(end, len);
 	}
 	es->selection_start = start;
 	es->selection_end = end;
@@ -3724,7 +3724,7 @@
 	GetClipBox(dc, &rcRgn);
 	if (es->style & ES_MULTILINE) {
 		INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
-		for (i = es->y_offset ; i <= MIN(es->y_offset + vlc, es->y_offset + es->line_count - 1) ; i++) {
+		for (i = es->y_offset ; i <= min(es->y_offset + vlc, es->y_offset + es->line_count - 1) ; i++) {
 			EDIT_GetLineRect(wnd, es, i, 0, -1, &rcLine);
 			if (IntersectRect(&rc, &rcRgn, &rcLine))
 				EDIT_PaintLine(wnd, es, dc, i, rev);
diff --git a/controls/menu.c b/controls/menu.c
index 6eeb608..5afe241 100644
--- a/controls/menu.c
+++ b/controls/menu.c
@@ -839,9 +839,9 @@
 	
 	lpitem->rect.right  += size.cx;
 	if (TWEAK_WineLook == WIN31_LOOK)
-	    lpitem->rect.bottom += MAX( size.cy, GetSystemMetrics(SM_CYMENU) );
+	    lpitem->rect.bottom += max( size.cy, GetSystemMetrics(SM_CYMENU) );
 	else
-	    lpitem->rect.bottom += MAX (size.cy, GetSystemMetrics(SM_CYMENU)-1);
+	    lpitem->rect.bottom += max(size.cy, GetSystemMetrics(SM_CYMENU)-1);
 	lpitem->xTab = 0;
 
 	if (menuBar)
@@ -905,17 +905,17 @@
 	    MENU_CalcItemSize( hdc, lpitem, hwndOwner, orgX, orgY, FALSE );
 
 	    if (lpitem->fType & MF_MENUBARBREAK) orgX++;
-	    maxX = MAX( maxX, lpitem->rect.right );
+	    maxX = max( maxX, lpitem->rect.right );
 	    orgY = lpitem->rect.bottom;
 	    if (IS_STRING_ITEM(lpitem->fType) && lpitem->xTab)
 	    {
-		maxTab = MAX( maxTab, lpitem->xTab );
-		maxTabWidth = MAX(maxTabWidth,lpitem->rect.right-lpitem->xTab);
+		maxTab = max( maxTab, lpitem->xTab );
+		maxTabWidth = max(maxTabWidth,lpitem->rect.right-lpitem->xTab);
 	    }
 	}
 
 	  /* Finish the column (set all items to the largest width found) */
-	maxX = MAX( maxX, maxTab + maxTabWidth );
+	maxX = max( maxX, maxTab + maxTabWidth );
 	for (lpitem = &lppop->items[start]; start < i; start++, lpitem++)
 	{
 	    lpitem->rect.right = maxX;
@@ -923,7 +923,7 @@
 		lpitem->xTab = maxTab;
 	
 	}
-	lppop->Height = MAX( lppop->Height, orgY );
+	lppop->Height = max( lppop->Height, orgY );
     }
 
     lppop->Width  = maxX;
@@ -986,7 +986,7 @@
 		if (i != start) break;
 		else lpitem->rect.right = lprect->right;
 	    }
-	    maxY = MAX( maxY, lpitem->rect.bottom );
+	    maxY = max( maxY, lpitem->rect.bottom );
 	    orgX = lpitem->rect.right;
 	}
 
diff --git a/controls/scroll.c b/controls/scroll.c
index 6748222..1bd8721 100644
--- a/controls/scroll.c
+++ b/controls/scroll.c
@@ -255,7 +255,7 @@
         }
         else
         {
-            INT max = info->MaxVal - MAX( info->Page-1, 0 );
+            INT max = info->MaxVal - max( info->Page-1, 0 );
             if (info->MinVal >= max)
                 *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP;
             else
@@ -292,7 +292,7 @@
 
     if ((pixels -= thumbSize) <= 0) return infoPtr->MinVal;
 
-    pos = MAX( 0, pos - (GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP) );
+    pos = max( 0, pos - (GetSystemMetrics(SM_CXVSCROLL) - SCROLL_ARROW_THUMB_OVERLAP) );
     if (pos > pixels) pos = pixels;
 
     if (!infoPtr->Page) pos *= infoPtr->MaxVal - infoPtr->MinVal;
@@ -1350,8 +1350,8 @@
 
     if (infoPtr->CurVal < infoPtr->MinVal)
         infoPtr->CurVal = infoPtr->MinVal;
-    else if (infoPtr->CurVal > infoPtr->MaxVal - MAX( infoPtr->Page-1, 0 ))
-        infoPtr->CurVal = infoPtr->MaxVal - MAX( infoPtr->Page-1, 0 );
+    else if (infoPtr->CurVal > infoPtr->MaxVal - max( infoPtr->Page-1, 0 ))
+        infoPtr->CurVal = infoPtr->MaxVal - max( infoPtr->Page-1, 0 );
 
     TRACE("    new values: page=%d pos=%d min=%d max=%d\n",
 		 infoPtr->Page, infoPtr->CurVal,
@@ -1367,7 +1367,7 @@
     if (info->fMask & (SIF_RANGE | SIF_PAGE | SIF_DISABLENOSCROLL))
     {
         new_flags = infoPtr->flags;
-        if (infoPtr->MinVal >= infoPtr->MaxVal - MAX( infoPtr->Page-1, 0 ))
+        if (infoPtr->MinVal >= infoPtr->MaxVal - max( infoPtr->Page-1, 0 ))
         {
             /* Hide or disable scroll-bar */
             if (info->fMask & SIF_DISABLENOSCROLL)
diff --git a/dlls/comctl32/comctl32undoc.c b/dlls/comctl32/comctl32undoc.c
index 960e567..6748a00 100644
--- a/dlls/comctl32/comctl32undoc.c
+++ b/dlls/comctl32/comctl32undoc.c
@@ -852,7 +852,7 @@
         hdsa->pData = NULL;
 	hdsa->nMaxCount = 0;
 	hdsa->nItemSize = nSize;
-	hdsa->nGrow = MAX(1, nGrow);
+	hdsa->nGrow = max(1, nGrow);
     }
 
     return hdsa;
@@ -1189,7 +1189,7 @@
 
     hdpa = (HDPA)COMCTL32_Alloc (sizeof(DPA));
     if (hdpa) {
-	hdpa->nGrow = MAX(8, nGrow);
+	hdpa->nGrow = max(8, nGrow);
 	hdpa->hHeap = COMCTL32_hHeap;
 	hdpa->nMaxCount = hdpa->nGrow * 2;
 	hdpa->ptrs =
@@ -1250,7 +1250,7 @@
     if (!hdpa)
 	return FALSE;
 
-    hdpa->nGrow = MAX(8, nGrow);
+    hdpa->nGrow = max(8, nGrow);
 
     return TRUE;
 }
@@ -1553,7 +1553,7 @@
     
     /* free memory ?*/
     if ((hdpa->nMaxCount - hdpa->nItemCount) >= hdpa->nGrow) {
-	INT nNewItems = MAX(hdpa->nGrow * 2, hdpa->nItemCount);
+	INT nNewItems = max(hdpa->nGrow * 2, hdpa->nItemCount);
 	nSize = nNewItems * sizeof(LPVOID);
 	lpDest = (LPVOID)HeapReAlloc (hdpa->hHeap, HEAP_ZERO_MEMORY,
 				      hdpa->ptrs, nSize);
@@ -1790,7 +1790,7 @@
 	hdpa = (HDPA)COMCTL32_Alloc (sizeof(DPA));
 
     if (hdpa) {
-	hdpa->nGrow = MIN(8, nGrow);
+	hdpa->nGrow = min(8, nGrow);
 	hdpa->hHeap = hHeap ? hHeap : COMCTL32_hHeap;
 	hdpa->nMaxCount = hdpa->nGrow * 2;
 	hdpa->ptrs =
diff --git a/dlls/comctl32/trackbar.c b/dlls/comctl32/trackbar.c
index 7c4d8bd..77ed28a 100644
--- a/dlls/comctl32/trackbar.c
+++ b/dlls/comctl32/trackbar.c
@@ -121,7 +121,7 @@
     GetClientRect (hwnd, &lpRect);
 
     if (dwStyle & TBS_ENABLESELRANGE)
-        cyChannel = MAX(infoPtr->uThumbLen - 8, 4);
+        cyChannel = max(infoPtr->uThumbLen - 8, 4);
     else
         cyChannel = 4;
 
diff --git a/dlls/comctl32/updown.c b/dlls/comctl32/updown.c
index 066f1ed..686adad9 100644
--- a/dlls/comctl32/updown.c
+++ b/dlls/comctl32/updown.c
@@ -824,7 +824,7 @@
 	UNKNOWN_PARAM(UDM_GETACCEL, wParam, lParam);
 	return 0;
       }
-      temp = MIN(infoPtr->AccelCount, wParam);
+      temp = min(infoPtr->AccelCount, wParam);
       memcpy((void *)lParam, infoPtr->AccelVect, temp*sizeof(UDACCEL));
       return temp;
 
diff --git a/dlls/commdlg/colordlg.c b/dlls/commdlg/colordlg.c
index 3cc2c39..b6c1670 100644
--- a/dlls/commdlg/colordlg.c
+++ b/dlls/commdlg/colordlg.c
@@ -167,7 +167,7 @@
  }
 
  /* l below 120 */
- maxrgb=(256*MIN(120,lum))/120;  /* 0 .. 256 */
+ maxrgb=(256*min(120,lum))/120;  /* 0 .. 256 */
  if (hue< 80)
   res=0;
  else
@@ -193,7 +193,7 @@
  if (lum>120 && res<256)
   res+=((lum-120) * (256-res))/120;
 
- return MIN(res,255);
+ return min(res,255);
 }
 
 /***********************************************************************
@@ -204,10 +204,10 @@
  WORD maxi,mini,mmsum,mmdif,result=0;
  int iresult=0;
 
- maxi=MAX(r,b);
- maxi=MAX(maxi,g);
- mini=MIN(r,b);
- mini=MIN(mini,g);
+ maxi=max(r,b);
+ maxi=max(maxi,g);
+ mini=min(r,b);
+ mini=min(mini,g);
 
  mmsum=maxi+mini;
  mmdif=maxi-mini;
@@ -642,7 +642,7 @@
   ydif=client.bottom/YSTEPS+1;
   for(lum=0;lum<240+ldif;lum+=ldif)
   {
-   rect.top=MAX(0,rect.bottom-ydif);
+   rect.top=max(0,rect.bottom-ydif);
    r=CC_HSLtoRGB('R',hue,sat,lum);
    g=CC_HSLtoRGB('G',hue,sat,lum);
    b=CC_HSLtoRGB('B',hue,sat,lum);
diff --git a/dlls/crtdll/crtdll_main.c b/dlls/crtdll/crtdll_main.c
index 7119d50..30f0b57 100644
--- a/dlls/crtdll/crtdll_main.c
+++ b/dlls/crtdll/crtdll_main.c
@@ -1401,7 +1401,7 @@
   drivechar  = strchr(path,':');
   dirchar    = strrchr(path,'/');
   namechar   = strrchr(path,'\\');
-  dirchar = MAX(dirchar,namechar);
+  dirchar = max(dirchar,namechar);
   if (dirchar)
     namechar   = strrchr(dirchar,'.');
   else
diff --git a/dlls/ole32/hglobalstream.c b/dlls/ole32/hglobalstream.c
index 2e65c44..fc9ce4b 100644
--- a/dlls/ole32/hglobalstream.c
+++ b/dlls/ole32/hglobalstream.c
@@ -420,7 +420,7 @@
    * Using the known size of the stream, calculate the number of bytes
    * to read from the block chain
    */
-  bytesToReadFromBuffer = MIN( This->streamSize.s.LowPart - This->currentPosition.s.LowPart, cb);
+  bytesToReadFromBuffer = min( This->streamSize.s.LowPart - This->currentPosition.s.LowPart, cb);
 
   /*
    * Lock the buffer in position and copy the data.
diff --git a/dlls/ole32/memlockbytes.c b/dlls/ole32/memlockbytes.c
index 410dc2f..970c844 100644
--- a/dlls/ole32/memlockbytes.c
+++ b/dlls/ole32/memlockbytes.c
@@ -372,7 +372,7 @@
    * Using the known size of the array, calculate the number of bytes
    * to read.
    */
-  bytesToReadFromBuffer = MIN(This->byteArraySize.s.LowPart -
+  bytesToReadFromBuffer = min(This->byteArraySize.s.LowPart -
                               ulOffset.s.LowPart, cb);
 
   /*
diff --git a/dlls/ole32/stg_stream.c b/dlls/ole32/stg_stream.c
index 90e445d..44ec251 100644
--- a/dlls/ole32/stg_stream.c
+++ b/dlls/ole32/stg_stream.c
@@ -334,7 +334,7 @@
    * Using the known size of the stream, calculate the number of bytes
    * to read from the block chain
    */
-  bytesToReadFromBuffer = MIN( This->streamSize.s.LowPart - This->currentPosition.s.LowPart, cb);
+  bytesToReadFromBuffer = min( This->streamSize.s.LowPart - This->currentPosition.s.LowPart, cb);
   
   /*
    * Depending on the type of chain that was opened when the stream was constructed,
diff --git a/dlls/ole32/storage32.c b/dlls/ole32/storage32.c
index c12d1a4..5a38e71 100644
--- a/dlls/ole32/storage32.c
+++ b/dlls/ole32/storage32.c
@@ -4171,7 +4171,7 @@
      * Calculate how many bytes we can copy from this big block.
      */
     bytesToReadInBuffer = 
-      MIN(This->parentStorage->bigBlockSize - offsetInBlock, size);
+      min(This->parentStorage->bigBlockSize - offsetInBlock, size);
     
     /*
      * Copy those bytes to the buffer
@@ -4261,7 +4261,7 @@
      * Calculate how many bytes we can copy from this big block.
      */
     bytesToWrite = 
-      MIN(This->parentStorage->bigBlockSize - offsetInBlock, size);
+      min(This->parentStorage->bigBlockSize - offsetInBlock, size);
     
     /*
      * Copy those bytes to the buffer
@@ -4900,7 +4900,7 @@
      * Calculate how many bytes we can copy from this small block.
      */
     bytesToReadInBuffer = 
-      MIN(This->parentStorage->smallBlockSize - offsetInBlock, size);
+      min(This->parentStorage->smallBlockSize - offsetInBlock, size);
 
     /*
      * Calculate the offset of the small block in the small block file.
@@ -4990,7 +4990,7 @@
      * Calculate how many bytes we can copy to this small block.
      */
     bytesToWriteInBuffer = 
-      MIN(This->parentStorage->smallBlockSize - offsetInBlock, size);
+      min(This->parentStorage->smallBlockSize - offsetInBlock, size);
     
     /*
      * Calculate the offset of the small block in the small block file.
diff --git a/dlls/winmm/lolvldrv.c b/dlls/winmm/lolvldrv.c
index bf87a50..f4fa53f 100644
--- a/dlls/winmm/lolvldrv.c
+++ b/dlls/winmm/lolvldrv.c
@@ -101,7 +101,7 @@
     if (_lread(hFile, &dw, 4) != 4)			E(("Can't read nr table offset\n"));
     if (_llseek(hFile, dw, SEEK_SET) < 0) 		E(("Can't seek to nr table %lu\n", dw));
     if (_lread(hFile, buf, 1) != 1)			E(("Can't read descr length\n"));
-    buflen = MIN((BYTE)buf[0], buflen - 1);
+    buflen = min((BYTE)buf[0], buflen - 1);
     if (_lread(hFile, buf, buflen) != buflen)		E(("Can't read descr (%d)\n", buflen));
     buf[buflen] = '\0';
     ret = TRUE;
diff --git a/dlls/winmm/mciwave/mciwave.c b/dlls/winmm/mciwave/mciwave.c
index 5a57e03..c777786 100644
--- a/dlls/winmm/mciwave/mciwave.c
+++ b/dlls/winmm/mciwave/mciwave.c
@@ -629,7 +629,7 @@
     }
 
     whidx = 0;
-    left = MIN(wmw->dwLength, end - wmw->dwPosition);
+    left = min(wmw->dwLength, end - wmw->dwPosition);
     wmw->hEvent = CreateEventA(NULL, FALSE, FALSE, NULL);
     wmw->dwEventCount = 1L; /* for first buffer */
 
@@ -637,7 +637,7 @@
     
     /* FIXME: this doesn't work if wmw->dwPosition != 0 */
     while (left > 0 && wmw->dwStatus != MCI_MODE_STOP && wmw->dwStatus != MCI_MODE_NOT_READY) {
-	count = mmioRead(wmw->hFile, waveHdr[whidx].lpData, MIN(bufsize, left));
+	count = mmioRead(wmw->hFile, waveHdr[whidx].lpData, min(bufsize, left));
 	TRACE("mmioRead bufsize=%ld count=%ld\n", bufsize, count);
 	if (count < 1) 
 	    break;
diff --git a/dlls/winmm/mmio.c b/dlls/winmm/mmio.c
index fc81f94..eeb794f 100644
--- a/dlls/winmm/mmio.c
+++ b/dlls/winmm/mmio.c
@@ -532,7 +532,7 @@
 	    
 	    if (extEnd - extStart - 1 > 4)
 		WARN("Extension length > 4\n");
-	    lstrcpynA(ext,extStart + 1,MIN(extEnd-extStart,5));
+	    lstrcpynA(ext,extStart + 1,min(extEnd-extStart,5));
 	    TRACE("Got extension: %s\n", debugstr_a(ext));
 	    /* FOURCC codes identifying file-extentions must be uppercase */
 	    ret = mmioStringToFOURCCA(ext, MMIO_TOUPPER);
diff --git a/dlls/winmm/mmsystem.c b/dlls/winmm/mmsystem.c
index dc14602..705393a 100644
--- a/dlls/winmm/mmsystem.c
+++ b/dlls/winmm/mmsystem.c
@@ -410,7 +410,7 @@
 		PlaySound_Stop = PlaySound_Loop = FALSE;
 		break;
 	    }
-	    count = mmioRead(hmmio, waveHdr[index].lpData, MIN(bufsize, left));
+	    count = mmioRead(hmmio, waveHdr[index].lpData, min(bufsize, left));
 	    if (count < 1) break;
 	    left -= count;
 	    waveHdr[index].dwBufferLength = count;
@@ -992,7 +992,7 @@
     case MIXER_GETCONTROLDETAILSF_LISTTEXT:
 	{
 	    LPVOID	paDetailsW = lpmcd->paDetails;
-	    int		size = MAX(1, lpmcd->cChannels) * sizeof(MIXERCONTROLDETAILS_LISTTEXTA);
+	    int		size = max(1, lpmcd->cChannels) * sizeof(MIXERCONTROLDETAILS_LISTTEXTA);
 
 	    if (lpmcd->u.cMultipleItems != 0 && lpmcd->u.cMultipleItems != lpmcd->u.hwndOwner) {
 		size *= lpmcd->u.cMultipleItems;
@@ -3091,11 +3091,11 @@
 	    DWORD	i;
 	    BYTE	ch;
 	    
-	    for (i = 0; i < MIN(16, lpMidiHdr->dwBufferLength - dwToGo); i++)
+	    for (i = 0; i < min(16, lpMidiHdr->dwBufferLength - dwToGo); i++)
 		printf("%02x ", lpData[dwToGo + i]);
 	    for (; i < 16; i++)
 		printf("   ");
-	    for (i = 0; i < MIN(16, lpMidiHdr->dwBufferLength - dwToGo); i++) {
+	    for (i = 0; i < min(16, lpMidiHdr->dwBufferLength - dwToGo); i++) {
 		ch = lpData[dwToGo + i];
 		printf("%c", (ch >= 0x20 && ch <= 0x7F) ? ch : '.');
 	    }
diff --git a/dlls/winmm/time.c b/dlls/winmm/time.c
index c37637b..8e475c9 100644
--- a/dlls/winmm/time.c
+++ b/dlls/winmm/time.c
@@ -222,7 +222,7 @@
     EnterCriticalSection(&iData->cs);
 
     for (lpTimer = iData->lpTimerList; lpTimer != NULL; lpTimer = lpTimer->lpNext) {
-	wNewID = MAX(wNewID, lpTimer->wTimerID);
+	wNewID = max(wNewID, lpTimer->wTimerID);
     }
     
     lpNewTimer->lpNext = iData->lpTimerList;
diff --git a/dlls/winmm/wineoss/audio.c b/dlls/winmm/wineoss/audio.c
index 0e7d527..e5d9e39 100644
--- a/dlls/winmm/wineoss/audio.c
+++ b/dlls/winmm/wineoss/audio.c
@@ -389,7 +389,7 @@
 	TRACE("imhere[1]\n");
 	MsgWaitForMultipleObjects(0, NULL, FALSE, 
 				  (wwo->state == WINE_WS_PLAYING) ? 
-				     (MAX(wwo->wFragsUsedInQueue, 4) - 2) * dwSleepTime : 
+				     (max(wwo->wFragsUsedInQueue, 4) - 2) * dwSleepTime : 
 				     /*INFINITE*/100, 
 				  QS_POSTMESSAGE);
 	TRACE("imhere[2]\n");
diff --git a/files/dos_fs.c b/files/dos_fs.c
index 69e6dab..4ba1c23 100644
--- a/files/dos_fs.c
+++ b/files/dos_fs.c
@@ -524,7 +524,7 @@
 
     const char *p = strchr( name, '/' );
     int len = p ? (int)(p - name) : strlen(name);
-    if ((p = strchr( name, '\\' ))) len = MIN( (int)(p - name), len );
+    if ((p = strchr( name, '\\' ))) len = min( (int)(p - name), len );
     /* Ignore trailing dots */
     while (len > 1 && name[len-1] == '.') len--;
     if (long_len < len + 1) return FALSE;
diff --git a/files/drive.c b/files/drive.c
index 5dc15b4..24dc0b1 100644
--- a/files/drive.c
+++ b/files/drive.c
@@ -923,7 +923,7 @@
     assert(s);
     ret = strlen(s) + 3; /* length of WHOLE current directory */
     if (ret >= buflen) return ret + 1;
-    lstrcpynA( buf, "A:\\", MIN( 4, buflen ) );
+    lstrcpynA( buf, "A:\\", min( 4, buflen ) );
     if (buflen) buf[0] += DRIVE_GetCurrentDrive();
     if (buflen > 3) lstrcpynA( buf + 3, s, buflen - 3 );
     return ret;
diff --git a/files/file.c b/files/file.c
index 7369123..76c2c65 100644
--- a/files/file.c
+++ b/files/file.c
@@ -1488,7 +1488,7 @@
  */
 UINT WINAPI SetHandleCount( UINT count )
 {
-    return MIN( 256, count );
+    return min( 256, count );
 }
 
 
diff --git a/files/profile.c b/files/profile.c
index 10dfbd7..bcac788 100644
--- a/files/profile.c
+++ b/files/profile.c
@@ -149,7 +149,7 @@
             const char *env_p;
             const char *p2 = strchr( p, '}' );
             if (!p2) continue;  /* ignore it */
-            lstrcpynA(env_val, p + 2, MIN( sizeof(env_val), (int)(p2-p)-1 ));
+            lstrcpynA(env_val, p + 2, min( sizeof(env_val), (int)(p2-p)-1 ));
             if ((env_p = getenv( env_val )) != NULL)
             {
                 lstrcpynA( buffer, env_p, len );
diff --git a/graphics/enhmetafiledrv/graphics.c b/graphics/enhmetafiledrv/graphics.c
index e83c7a0..0aba29b 100644
--- a/graphics/enhmetafiledrv/graphics.c
+++ b/graphics/enhmetafiledrv/graphics.c
@@ -48,10 +48,10 @@
     if(!EMFDRV_WriteRecord( dc, &emr.emr ))
     	return FALSE;
 
-    bounds.left   = MIN(x, dc->w.CursPosX);
-    bounds.top    = MIN(y, dc->w.CursPosY);
-    bounds.right  = MAX(x, dc->w.CursPosX);
-    bounds.bottom = MAX(y, dc->w.CursPosY);
+    bounds.left   = min(x, dc->w.CursPosX);
+    bounds.top    = min(y, dc->w.CursPosY);
+    bounds.right  = max(x, dc->w.CursPosX);
+    bounds.bottom = max(y, dc->w.CursPosY);
 
     EMFDRV_UpdateBBox( dc, &bounds );
 
@@ -116,10 +116,10 @@
     if(angleEnd < 0) angleEnd += 2 * M_PI;
     if(angleEnd < angleStart) angleEnd += 2 * M_PI;
 
-    bounds.left   = MIN(xinterStart, xinterEnd);
-    bounds.top    = MIN(yinterStart, yinterEnd);
-    bounds.right  = MAX(xinterStart, xinterEnd);
-    bounds.bottom = MAX(yinterStart, yinterEnd);
+    bounds.left   = min(xinterStart, xinterEnd);
+    bounds.top    = min(yinterStart, yinterEnd);
+    bounds.right  = max(xinterStart, xinterEnd);
+    bounds.bottom = max(yinterStart, yinterEnd);
     
     for(i = 0; i <= 8; i++) {
         if(i * M_PI / 2 < angleStart) /* loop until we're past start */
diff --git a/graphics/enhmetafiledrv/init.c b/graphics/enhmetafiledrv/init.c
index 914858f..bdedaed 100644
--- a/graphics/enhmetafiledrv/init.c
+++ b/graphics/enhmetafiledrv/init.c
@@ -173,10 +173,10 @@
         *bounds = *rect;
 	return;
     }
-    bounds->left   = MIN(bounds->left,   rect->left);
-    bounds->top    = MIN(bounds->top,    rect->top);
-    bounds->right  = MAX(bounds->right,  rect->right);
-    bounds->bottom = MAX(bounds->bottom, rect->bottom);
+    bounds->left   = min(bounds->left,   rect->left);
+    bounds->top    = min(bounds->top,    rect->top);
+    bounds->right  = max(bounds->right,  rect->right);
+    bounds->bottom = max(bounds->bottom, rect->bottom);
     return;
 }
 
diff --git a/graphics/metafiledrv/init.c b/graphics/metafiledrv/init.c
index b00d8ca..f04aa5c 100644
--- a/graphics/metafiledrv/init.c
+++ b/graphics/metafiledrv/init.c
@@ -369,7 +369,7 @@
     }
 
     physDev->mh->mtSize += rlen / 2;
-    physDev->mh->mtMaxRecord = MAX(physDev->mh->mtMaxRecord, rlen / 2);
+    physDev->mh->mtMaxRecord = max(physDev->mh->mtMaxRecord, rlen / 2);
     return TRUE;
 }
 
diff --git a/graphics/x11drv/graphics.c b/graphics/x11drv/graphics.c
index ad1ef3c..46c4a2c 100644
--- a/graphics/x11drv/graphics.c
+++ b/graphics/x11drv/graphics.c
@@ -668,8 +668,8 @@
 
     /* Make sure ell_width and ell_height are >= 1 otherwise XDrawArc gets
        called with width/height < 0 */
-    ell_width  = MAX(abs( ell_width * dc->vportExtX / dc->wndExtX ), 1);
-    ell_height = MAX(abs( ell_height * dc->vportExtY / dc->wndExtY ), 1);
+    ell_width  = max(abs( ell_width * dc->vportExtX / dc->wndExtX ), 1);
+    ell_height = max(abs( ell_height * dc->vportExtY / dc->wndExtY ), 1);
 
     /* Fix the coordinates */
 
diff --git a/graphics/x11drv/xfont.c b/graphics/x11drv/xfont.c
index 04d8fc1..b98461d 100644
--- a/graphics/x11drv/xfont.c
+++ b/graphics/x11drv/xfont.c
@@ -3065,10 +3065,10 @@
 		    if (CI_NONEXISTCHAR(cs)) cs = def; 
   		} else cs = def;
 		if(pfo->lpX11Trans)
-		    *buffer++ = MAX(cs->attributes, 0) *
+		    *buffer++ = max(cs->attributes, 0) *
 		      pfo->lpX11Trans->pixelsize / 1000.0 * pfo->rescale;
 		else
-		    *buffer++ = MAX(cs->width, 0 ) * pfo->rescale;
+		    *buffer++ = max(cs->width, 0 ) * pfo->rescale;
 	    }
 	}
 
diff --git a/include/windef.h b/include/windef.h
index 79d4b80..b988580 100644
--- a/include/windef.h
+++ b/include/windef.h
@@ -421,25 +421,14 @@
                                    ((DWORD)GET_WORD((WORD *)(ptr)+1) << 16)))
 #endif  /* 1 */
 
-/* MIN and MAX macros */
-
-#ifdef MAX
-#undef MAX
-#endif
-#define MAX(a,b) (((a) > (b)) ? (a) : (b))
-
-#ifdef MIN
-#undef MIN
-#endif
-#define MIN(a,b) (((a) < (b)) ? (a) : (b))
-
-#define __max(a,b) MAX(a,b)
-#define __min(a,b) MIN(a,b)
+/* min and max macros */
+#define __max(a,b) (((a) > (b)) ? (a) : (b))
+#define __min(a,b) (((a) < (b)) ? (a) : (b))
 #ifndef max
-#define max(a,b)   MAX(a,b)
+#define max(a,b)   (((a) > (b)) ? (a) : (b))
 #endif
 #ifndef min
-#define min(a,b)   MIN(a,b)
+#define min(a,b)   (((a) < (b)) ? (a) : (b))
 #endif
 
 #define _MAX_PATH  260
diff --git a/loader/pe_image.c b/loader/pe_image.c
index 2109f74..27c5e0d 100644
--- a/loader/pe_image.c
+++ b/loader/pe_image.c
@@ -397,8 +397,8 @@
                       pe_seg->NumberOfRelocations,
                       pe_seg->NumberOfLinenumbers,
                       pe_seg->Characteristics);
-        vma_size=MAX(vma_size, pe_seg->VirtualAddress+pe_seg->SizeOfRawData);
-        vma_size=MAX(vma_size, pe_seg->VirtualAddress+pe_seg->Misc.VirtualSize);
+        vma_size=max(vma_size, pe_seg->VirtualAddress+pe_seg->SizeOfRawData);
+        vma_size=max(vma_size, pe_seg->VirtualAddress+pe_seg->Misc.VirtualSize);
         pe_seg++;
     }
     return vma_size;
diff --git a/loader/resource.c b/loader/resource.c
index bfe3ca1..1709008 100644
--- a/loader/resource.c
+++ b/loader/resource.c
@@ -839,7 +839,7 @@
     TRACE("strlen = %d\n", (int)*p );
     
     if (buffer == NULL) return *p;
-    i = MIN(buflen - 1, *p);
+    i = min(buflen - 1, *p);
     if (i > 0) {
 	memcpy(buffer, p + 1, i);
 	buffer[i] = '\0';
@@ -889,7 +889,7 @@
     TRACE("strlen = %d\n", (int)*p );
     
     if (buffer == NULL) return *p;
-    i = MIN(buflen - 1, *p);
+    i = min(buflen - 1, *p);
     if (i > 0) {
 	memcpy(buffer, p + 1, i * sizeof (WCHAR));
 	buffer[i] = (WCHAR) 0;
@@ -995,7 +995,7 @@
     }
     slen=mre->Length;
     TRACE("	- strlen=%d\n",slen);
-    i = MIN(buflen - 1, slen);
+    i = min(buflen - 1, slen);
     if (buffer == NULL)
 	return slen;
     if (i>0) {
diff --git a/memory/heap.c b/memory/heap.c
index 1792267..5ee1e2a 100644
--- a/memory/heap.c
+++ b/memory/heap.c
@@ -639,7 +639,7 @@
     }
     size += sizeof(SUBHEAP) + sizeof(ARENA_FREE);
     if (!(subheap = HEAP_CreateSubHeap( heap, heap->flags, size,
-                                        MAX( HEAP_DEF_SIZE, size ) )))
+                                        max( HEAP_DEF_SIZE, size ) )))
         return NULL;
 
     TRACE("created new sub-heap %08lx of %08lx bytes for heap %08lx\n",
diff --git a/memory/local.c b/memory/local.c
index b8d086b..2833057 100644
--- a/memory/local.c
+++ b/memory/local.c
@@ -390,7 +390,7 @@
     }
     ptr = PTR_SEG_OFF_TO_LIN( selector, 0 );
 
-    start = LALIGN( MAX( start, sizeof(INSTANCEDATA) ) );
+    start = LALIGN( max( start, sizeof(INSTANCEDATA) ) );
     heapInfoArena = LALIGN(start + sizeof(LOCALARENA) );
     freeArena = LALIGN( heapInfoArena + ARENA_HEADER_SIZE
                         + sizeof(LOCALHEAPINFO) );
@@ -857,7 +857,7 @@
     }
 
     size += ARENA_HEADER_SIZE;
-    size = LALIGN( MAX( size, sizeof(LOCALARENA) ) );
+    size = LALIGN( max( size, sizeof(LOCALARENA) ) );
 
 #if 0
 notify_done:
diff --git a/misc/version.c b/misc/version.c
index 1ebfc43..8b98d72 100644
--- a/misc/version.c
+++ b/misc/version.c
@@ -475,7 +475,7 @@
   GetSystemInfo(&si);
 
   /* There doesn't seem to be any Pentium flag.  */
-  result = cpuflags[MIN (si.wProcessorLevel, 4)] | WF_ENHANCED | WF_PMODE | WF_80x87 | WF_PAGING;
+  result = cpuflags[min(si.wProcessorLevel, 4)] | WF_ENHANCED | WF_PMODE | WF_80x87 | WF_PAGING;
   if (si.wProcessorLevel >= 4) result |= WF_HASCPUID;
   ovi.dwOSVersionInfoSize = sizeof(ovi);
   GetVersionExA(&ovi);
diff --git a/msdos/int21.c b/msdos/int21.c
index fb1b343..64cc2a7 100644
--- a/msdos/int21.c
+++ b/msdos/int21.c
@@ -820,12 +820,12 @@
         if (p && p[1] && (p != entry.cAlternateFileName))
         {
             memcpy( pResult->filename, entry.cAlternateFileName,
-                    MIN( (p - entry.cAlternateFileName), 8 ) );
-            memcpy( pResult->filename + 8, p + 1, MIN( strlen(p), 3 ) );
+                    min( (p - entry.cAlternateFileName), 8 ) );
+            memcpy( pResult->filename + 8, p + 1, min( strlen(p), 3 ) );
         }
         else
             memcpy( pResult->filename, entry.cAlternateFileName,
-                    MIN( strlen(entry.cAlternateFileName), 8 ) );
+                    min( strlen(entry.cAlternateFileName), 8 ) );
     }
     return 1;
 }
diff --git a/objects/enhmetafile.c b/objects/enhmetafile.c
index 6a4e3f8..7cca796 100644
--- a/objects/enhmetafile.c
+++ b/objects/enhmetafile.c
@@ -177,9 +177,9 @@
     if (!buf) return sizeof(ENHMETAHEADER);
     emh = EMF_GetEnhMetaHeader(hmf);
     if(!emh) return FALSE;
-    memmove(buf, emh, MIN(sizeof(ENHMETAHEADER), bufsize));
+    memmove(buf, emh, min(sizeof(ENHMETAHEADER), bufsize));
     EMF_ReleaseEnhMetaHeader(hmf);
-    return MIN(sizeof(ENHMETAHEADER), bufsize);
+    return min(sizeof(ENHMETAHEADER), bufsize);
 }
 
 
@@ -213,7 +213,7 @@
  		 size - first - 1);
  
      EMF_ReleaseEnhMetaHeader(hmf);
-     return MIN(size, emh->nDescription);
+     return min(size, emh->nDescription);
 }
 
 /*****************************************************************************
@@ -244,9 +244,9 @@
      }
  
      memmove(buf, (char *) emh + emh->offDescription, 
- 	    MIN(size,emh->nDescription));
+ 	    min(size,emh->nDescription));
      EMF_ReleaseEnhMetaHeader(hmf);
-     return MIN(size, emh->nDescription);
+     return min(size, emh->nDescription);
 }
 
 /****************************************************************************
@@ -303,7 +303,7 @@
   }
 
   /* Copy the lesser of the two byte counts */
-  uEnhMetaFileSize = MIN( uEnhMetaFileSize, bufsize );
+  uEnhMetaFileSize = min( uEnhMetaFileSize, bufsize );
 
   /* Copy everything */
   lpEnhMetaFile = EMF_GetEnhMetaHeader( hmf );
@@ -1375,7 +1375,7 @@
   {
     PEMREOF lpEof = (PEMREOF)lpEMR;
     EMF_PaletteCopy* info = (EMF_PaletteCopy*)lpData;
-    DWORD dwNumPalToCopy = MIN( lpEof->nPalEntries, info->cEntries );
+    DWORD dwNumPalToCopy = min( lpEof->nPalEntries, info->cEntries );
 
     TRACE( "copying 0x%08lx palettes\n", dwNumPalToCopy );
 
diff --git a/objects/region.c b/objects/region.c
index 7748d3d..bc1f95f 100644
--- a/objects/region.c
+++ b/objects/region.c
@@ -1543,7 +1543,7 @@
      * have to worry about using too much memory. I hope to be able to
      * nuke the Xrealloc() at the end of this function eventually.
      */
-    newReg->size = MAX(reg1->numRects,reg2->numRects) * 2;
+    newReg->size = max(reg1->numRects,reg2->numRects) * 2;
 
     if (! (newReg->rects = HeapAlloc( GetProcessHeap(), 0, 
 			          sizeof(RECT) * newReg->size )))
@@ -1614,8 +1614,8 @@
 	 */
 	if (r1->top < r2->top)
 	{
-	    top = MAX(r1->top,ybot);
-	    bot = MIN(r1->bottom,r2->top);
+	    top = max(r1->top,ybot);
+	    bot = min(r1->bottom,r2->top);
 
 	    if ((top != bot) && (nonOverlap1Func != (void (*)())NULL))
 	    {
@@ -1626,8 +1626,8 @@
 	}
 	else if (r2->top < r1->top)
 	{
-	    top = MAX(r2->top,ybot);
-	    bot = MIN(r2->bottom,r1->top);
+	    top = max(r2->top,ybot);
+	    bot = min(r2->bottom,r1->top);
 
 	    if ((top != bot) && (nonOverlap2Func != (void (*)())NULL))
 	    {
@@ -1656,7 +1656,7 @@
 	 * Now see if we've hit an intersecting band. The two bands only
 	 * intersect if ybot > ytop
 	 */
-	ybot = MIN(r1->bottom, r2->bottom);
+	ybot = min(r1->bottom, r2->bottom);
 	curBand = newReg->numRects;
 	if (ybot > ytop)
 	{
@@ -1699,7 +1699,7 @@
 		    r1BandEnd++;
 		}
 		(* nonOverlap1Func) (newReg, r1, r1BandEnd,
-				     MAX(r1->top,ybot), r1->bottom);
+				     max(r1->top,ybot), r1->bottom);
 		r1 = r1BandEnd;
 	    } while (r1 != r1End);
 	}
@@ -1714,7 +1714,7 @@
 		 r2BandEnd++;
 	    }
 	    (* nonOverlap2Func) (newReg, r2, r2BandEnd,
-				MAX(r2->top,ybot), r2->bottom);
+				max(r2->top,ybot), r2->bottom);
 	    r2 = r2BandEnd;
 	} while (r2 != r2End);
     }
@@ -1786,8 +1786,8 @@
 
     while ((r1 != r1End) && (r2 != r2End))
     {
-	left = MAX(r1->left, r2->left);
-	right =	MIN(r1->right, r2->right);
+	left = max(r1->left, r2->left);
+	right =	min(r1->right, r2->right);
 
 	/*
 	 * If there's any overlap between the two rectangles, add that
@@ -2026,10 +2026,10 @@
     REGION_RegionOp (newReg, reg1, reg2, (voidProcp) REGION_UnionO, 
 		(voidProcp) REGION_UnionNonO, (voidProcp) REGION_UnionNonO);
 
-    newReg->extents.left = MIN(reg1->extents.left, reg2->extents.left);
-    newReg->extents.top = MIN(reg1->extents.top, reg2->extents.top);
-    newReg->extents.right = MAX(reg1->extents.right, reg2->extents.right);
-    newReg->extents.bottom = MAX(reg1->extents.bottom, reg2->extents.bottom);
+    newReg->extents.left = min(reg1->extents.left, reg2->extents.left);
+    newReg->extents.top = min(reg1->extents.top, reg2->extents.top);
+    newReg->extents.right = max(reg1->extents.right, reg2->extents.right);
+    newReg->extents.bottom = max(reg1->extents.bottom, reg2->extents.bottom);
     newReg->type = (newReg->numRects) ?
                         ((newReg->numRects > 1) ? COMPLEXREGION : SIMPLEREGION)
                         : NULLREGION ;
@@ -2711,8 +2711,8 @@
 	  (Pts[2].x == Pts[3].x) &&
 	  (Pts[3].y == Pts[0].y))))
     {
-        SetRectRgn( hrgn, MIN(Pts[0].x, Pts[2].x), MIN(Pts[0].y, Pts[2].y), 
-		            MAX(Pts[0].x, Pts[2].x), MAX(Pts[0].y, Pts[2].y) );
+        SetRectRgn( hrgn, min(Pts[0].x, Pts[2].x), min(Pts[0].y, Pts[2].y), 
+		            max(Pts[0].x, Pts[2].x), max(Pts[0].y, Pts[2].y) );
 	GDI_HEAP_UNLOCK( hrgn );
 	return hrgn;
     }
diff --git a/programs/winhelp/hlpfile.c b/programs/winhelp/hlpfile.c
index 9948441..e15c0ae 100644
--- a/programs/winhelp/hlpfile.c
+++ b/programs/winhelp/hlpfile.c
@@ -229,7 +229,7 @@
   buf = topic.map[0] + 0xc;
   while(buf + 0xc < topic.end)
     {
-      BYTE *end = MIN(buf + GET_UINT(buf, 0), topic.end);
+      BYTE *end = min(buf + GET_UINT(buf, 0), topic.end);
       UINT next, index, offset;
 
       switch (buf[0x14])
@@ -772,7 +772,7 @@
       /* I don't know why, it's necessary for printman.hlp */
       if (ptr + 0x44 > end) ptr = end - 0x44;
 
-      newsize += HLPFILE_Uncompressed1_Size(ptr + 0xc, MIN(end, ptr + 0x1000));
+      newsize += HLPFILE_Uncompressed1_Size(ptr + 0xc, min(end, ptr + 0x1000));
     }
 
   topic.hMap    = GlobalAlloc(GMEM_FIXED, topic.wMapLen * sizeof(topic.map[0]));
@@ -788,7 +788,7 @@
       if (ptr + 0x44 > end) ptr = end - 0x44;
 
       topic.map[i] = newptr - 0xc;
-      newptr = HLPFILE_Uncompress1(ptr + 0xc, MIN(end, ptr + 0x1000), newptr);
+      newptr = HLPFILE_Uncompress1(ptr + 0xc, min(end, ptr + 0x1000), newptr);
     }
 
   return TRUE;
diff --git a/programs/winhelp/macro.c b/programs/winhelp/macro.c
index 82fd5a2..a7f6e26 100644
--- a/programs/winhelp/macro.c
+++ b/programs/winhelp/macro.c
@@ -161,7 +161,7 @@
 
   button->wParam = WH_FIRST_BUTTON;
   for (b = &win->first_button; *b; b = &(*b)->next)
-    button->wParam = MAX(button->wParam, (*b)->wParam + 1);
+    button->wParam = max(button->wParam, (*b)->wParam + 1);
   *b = button;
 
   SendMessage(win->hMainWnd, WM_USER, 0, 0);
diff --git a/programs/winhelp/winhelp.c b/programs/winhelp/winhelp.c
index 590deaf..d083c57 100644
--- a/programs/winhelp/winhelp.c
+++ b/programs/winhelp/winhelp.c
@@ -225,8 +225,8 @@
       origin = *mouse;
       ClientToScreen(hParentWnd, &origin);
       origin.x -= size.cx / 2;
-      origin.x  = MIN(origin.x, GetSystemMetrics(SM_CXSCREEN) - size.cx);
-      origin.x  = MAX(origin.x, 0);
+      origin.x  = min(origin.x, GetSystemMetrics(SM_CXSCREEN) - size.cx);
+      origin.x  = max(origin.x, 0);
     }
 
   /* Initialize WINHELP_WINDOW struct */
@@ -466,8 +466,8 @@
 			     lstrlen(button->lpszName), &textsize);
 	  ReleaseDC(button->hWnd, hDc);
 
-	  button_size.cx = MAX(button_size.cx, textsize.cx + BUTTON_CX);
-	  button_size.cy = MAX(button_size.cy, textsize.cy + BUTTON_CY);
+	  button_size.cx = max(button_size.cx, textsize.cx + BUTTON_CX);
+	  button_size.cy = max(button_size.cy, textsize.cy + BUTTON_CY);
 	}
 
       x = 0;
@@ -787,13 +787,13 @@
 	      textlen = low;
 	      while (textlen && text[textlen] && text[textlen] != ' ') textlen--;
 	    }
-	  if (!part && !textlen) textlen = MAX(low, 1);
+	  if (!part && !textlen) textlen = max(low, 1);
 
 	  if (free_width <= 0 || !textlen)
 	    {
 	      part = 0;
 	      space.cx = rect.left + indent;
-	      space.cx = MIN(space.cx, rect.right - rect.left - 1);
+	      space.cx = min(space.cx, rect.right - rect.left - 1);
 	      continue;
 	    }
 
@@ -807,7 +807,7 @@
 	    }
 
 	  if (newsize)
-	    newsize->cx = MAX(newsize->cx, (*line)->rect.right + INTERNAL_BORDER_WIDTH);
+	    newsize->cx = max(newsize->cx, (*line)->rect.right + INTERNAL_BORDER_WIDTH);
 
 	  len -= textlen;
 	  text += textlen;
@@ -892,7 +892,7 @@
   part->rect.top      =
     ((*partp) ? line->rect.top : line->rect.bottom) + *line_ascent - ascent;
   part->rect.bottom   = part->rect.top + textsize->cy;
-  line->rect.bottom   = MAX(line->rect.bottom, part->rect.bottom);
+  line->rect.bottom   = max(line->rect.bottom, part->rect.bottom);
   part->hSelf         = handle;
   part->lpsText       = ptr;
   part->wTextLen      = textlen;
diff --git a/server/registry.c b/server/registry.c
index 00b9ae5..5173f1c 100644
--- a/server/registry.c
+++ b/server/registry.c
@@ -350,7 +350,7 @@
 static void touch_key( struct key *key )
 {
     key->modif = time(NULL);
-    key->level = MAX( key->level, current_level );
+    key->level = max( key->level, current_level );
 }
 
 /* try to grow the array of subkeys; return 1 if OK, 0 on error */
@@ -1186,7 +1186,7 @@
     value->len  = len;
     value->type = type;
     /* update the key level but not the modification time */
-    key->level = MAX( key->level, current_level );
+    key->level = max( key->level, current_level );
     return 1;
 
  error:
diff --git a/server/trace.c b/server/trace.c
index 96145a8..0ef5f73 100644
--- a/server/trace.c
+++ b/server/trace.c
@@ -172,13 +172,13 @@
 
 static void dump_varargs_read_process_memory_reply( const struct read_process_memory_request *req )
 {
-    int count = MIN( req->len, get_req_size( req->data, sizeof(int) ) );
+    int count = min( req->len, get_req_size( req->data, sizeof(int) ) );
     dump_bytes( (unsigned char *)req->data, count * sizeof(int) );
 }
 
 static void dump_varargs_write_process_memory_request( const struct write_process_memory_request *req )
 {
-    int count = MIN( req->len, get_req_size( req->data, sizeof(int) ) );
+    int count = min( req->len, get_req_size( req->data, sizeof(int) ) );
     dump_bytes( (unsigned char *)req->data, count * sizeof(int) );
 }
 
diff --git a/tools/build.c b/tools/build.c
index 994a1cf..838a1a7 100644
--- a/tools/build.c
+++ b/tools/build.c
@@ -369,9 +369,9 @@
     {
         if (!strcmp( Names[i]->name, Names[i+1]->name ))
         {
-            Line = MAX( Names[i]->lineno, Names[i+1]->lineno );
+            Line = max( Names[i]->lineno, Names[i+1]->lineno );
             fatal_error( "'%s' redefined (previous definition at line %d)\n",
-                         Names[i]->name, MIN( Names[i]->lineno, Names[i+1]->lineno ) );
+                         Names[i]->name, min( Names[i]->lineno, Names[i+1]->lineno ) );
         }
     }
 
diff --git a/windows/cursoricon.c b/windows/cursoricon.c
index afcca46..08b3b8a 100644
--- a/windows/cursoricon.c
+++ b/windows/cursoricon.c
@@ -499,7 +499,7 @@
 	 */
 
     	if ((pInfo = (BITMAPINFO *)HeapAlloc( GetProcessHeap(), 0, 
-	  MAX(size, sizeof(BITMAPINFOHEADER) + 2*sizeof(RGBQUAD)))))
+	  max(size, sizeof(BITMAPINFOHEADER) + 2*sizeof(RGBQUAD)))))
 	{	
 	    memcpy( pInfo, bmi, size );	
 	    pInfo->bmiHeader.biHeight /= 2;
diff --git a/windows/dce.c b/windows/dce.c
index 78f1123..5b14309 100644
--- a/windows/dce.c
+++ b/windows/dce.c
@@ -411,10 +411,10 @@
 		goto fail;
             }
 
-	    lprect->left = MAX( lprect->left, wndPtr->rectClient.left );
-	    lprect->right = MIN( lprect->right, wndPtr->rectClient.right );
-	    lprect->top = MAX( lprect->top, wndPtr->rectClient.top );
-	    lprect->bottom = MIN( lprect->bottom, wndPtr->rectClient.bottom );
+	    lprect->left = max( lprect->left, wndPtr->rectClient.left );
+	    lprect->right = min( lprect->right, wndPtr->rectClient.right );
+	    lprect->top = max( lprect->top, wndPtr->rectClient.top );
+	    lprect->bottom = min( lprect->bottom, wndPtr->rectClient.bottom );
 
             WIN_ReleaseWndPtr(wndPtr);
 	}
diff --git a/windows/msgbox.c b/windows/msgbox.c
index 4d6db88..9fa8a0a 100644
--- a/windows/msgbox.c
+++ b/windows/msgbox.c
@@ -155,7 +155,7 @@
 	    }
 	}
     }
-    bw = MAX(bw, bh * 2);
+    bw = max(bw, bh * 2);
     /* Button white space */
     bh = bh * 2;
     bw = bw * 2;
@@ -168,14 +168,14 @@
 	       DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK | DT_CALCRECT);
     /* Min text width corresponds to space for the buttons */
     tleft = 2 * ileft + iwidth;
-    twidth = MAX((bw + bspace) * buttons + bspace - tleft, rect.right);
+    twidth = max((bw + bspace) * buttons + bspace - tleft, rect.right);
     theight = rect.bottom;
     
     if (hFont)
 	SelectObject(hdc, hPrevFont);
     ReleaseDC(hItem, hdc);
     
-    tiheight = 16 + MAX(iheight, theight);
+    tiheight = 16 + max(iheight, theight);
     wwidth  = tleft + twidth + ileft + borwidth;
     wheight = 8 + tiheight + bh + borheight;
     
diff --git a/windows/nonclient.c b/windows/nonclient.c
index 6394790..8b0edd8 100644
--- a/windows/nonclient.c
+++ b/windows/nonclient.c
@@ -2157,23 +2157,23 @@
         SetRect(&mouseRect, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
     if (ON_LEFT_BORDER(hittest))
     {
-	mouseRect.left  = MAX( mouseRect.left, sizingRect.right-maxTrack.x );
-	mouseRect.right = MIN( mouseRect.right, sizingRect.right-minTrack.x );
+	mouseRect.left  = max( mouseRect.left, sizingRect.right-maxTrack.x );
+	mouseRect.right = min( mouseRect.right, sizingRect.right-minTrack.x );
     }
     else if (ON_RIGHT_BORDER(hittest))
     {
-	mouseRect.left  = MAX( mouseRect.left, sizingRect.left+minTrack.x );
-	mouseRect.right = MIN( mouseRect.right, sizingRect.left+maxTrack.x );
+	mouseRect.left  = max( mouseRect.left, sizingRect.left+minTrack.x );
+	mouseRect.right = min( mouseRect.right, sizingRect.left+maxTrack.x );
     }
     if (ON_TOP_BORDER(hittest))
     {
-	mouseRect.top    = MAX( mouseRect.top, sizingRect.bottom-maxTrack.y );
-	mouseRect.bottom = MIN( mouseRect.bottom,sizingRect.bottom-minTrack.y);
+	mouseRect.top    = max( mouseRect.top, sizingRect.bottom-maxTrack.y );
+	mouseRect.bottom = min( mouseRect.bottom,sizingRect.bottom-minTrack.y);
     }
     else if (ON_BOTTOM_BORDER(hittest))
     {
-	mouseRect.top    = MAX( mouseRect.top, sizingRect.top+minTrack.y );
-	mouseRect.bottom = MIN( mouseRect.bottom, sizingRect.top+maxTrack.y );
+	mouseRect.top    = max( mouseRect.top, sizingRect.top+minTrack.y );
+	mouseRect.bottom = min( mouseRect.bottom, sizingRect.top+maxTrack.y );
     }
     if (wndPtr->dwStyle & WS_CHILD)
     {
@@ -2231,10 +2231,10 @@
 	    case VK_RIGHT: pt.x += 8; break;		
 	}
 
-	pt.x = MAX( pt.x, mouseRect.left );
-	pt.x = MIN( pt.x, mouseRect.right );
-	pt.y = MAX( pt.y, mouseRect.top );
-	pt.y = MIN( pt.y, mouseRect.bottom );
+	pt.x = max( pt.x, mouseRect.left );
+	pt.x = min( pt.x, mouseRect.right );
+	pt.y = max( pt.y, mouseRect.top );
+	pt.y = min( pt.y, mouseRect.bottom );
 
 	dx = pt.x - capturePoint.x;
 	dy = pt.y - capturePoint.y;
diff --git a/windows/rect.c b/windows/rect.c
index 1717cf8..1f48e77 100644
--- a/windows/rect.c
+++ b/windows/rect.c
@@ -183,10 +183,10 @@
 	SetRectEmpty16( dest );
 	return FALSE;
     }
-    dest->left   = MAX( src1->left, src2->left );
-    dest->right  = MIN( src1->right, src2->right );
-    dest->top    = MAX( src1->top, src2->top );
-    dest->bottom = MIN( src1->bottom, src2->bottom );
+    dest->left   = max( src1->left, src2->left );
+    dest->right  = min( src1->right, src2->right );
+    dest->top    = max( src1->top, src2->top );
+    dest->bottom = min( src1->bottom, src2->bottom );
     return TRUE;
 }
 
@@ -204,10 +204,10 @@
 	SetRectEmpty( dest );
 	return FALSE;
     }
-    dest->left   = MAX( src1->left, src2->left );
-    dest->right  = MIN( src1->right, src2->right );
-    dest->top    = MAX( src1->top, src2->top );
-    dest->bottom = MIN( src1->bottom, src2->bottom );
+    dest->left   = max( src1->left, src2->left );
+    dest->right  = min( src1->right, src2->right );
+    dest->top    = max( src1->top, src2->top );
+    dest->bottom = min( src1->bottom, src2->bottom );
     return TRUE;
 }
 
@@ -232,10 +232,10 @@
 	if (IsRectEmpty16(src2)) *dest = *src1;
 	else
 	{
-	    dest->left   = MIN( src1->left, src2->left );
-	    dest->right  = MAX( src1->right, src2->right );
-	    dest->top    = MIN( src1->top, src2->top );
-	    dest->bottom = MAX( src1->bottom, src2->bottom );	    
+	    dest->left   = min( src1->left, src2->left );
+	    dest->right  = max( src1->right, src2->right );
+	    dest->top    = min( src1->top, src2->top );
+	    dest->bottom = max( src1->bottom, src2->bottom );	    
 	}
     }
     return TRUE;
@@ -262,10 +262,10 @@
 	if (IsRectEmpty(src2)) *dest = *src1;
 	else
 	{
-	    dest->left   = MIN( src1->left, src2->left );
-	    dest->right  = MAX( src1->right, src2->right );
-	    dest->top    = MIN( src1->top, src2->top );
-	    dest->bottom = MAX( src1->bottom, src2->bottom );	    
+	    dest->left   = min( src1->left, src2->left );
+	    dest->right  = max( src1->right, src2->right );
+	    dest->top    = min( src1->top, src2->top );
+	    dest->bottom = max( src1->bottom, src2->bottom );	    
 	}
     }
     return TRUE;
diff --git a/windows/timer.c b/windows/timer.c
index b724780..8a33d4a 100644
--- a/windows/timer.c
+++ b/windows/timer.c
@@ -255,7 +255,7 @@
     if (proc) WINPROC_SetProc( &pTimer->proc, proc, type, WIN_PROC_TIMER );
 
     pTimer->expired  = FALSE;
-    pTimer->hService = SERVICE_AddTimer( MAX( timeout * 1000L, SYS_TIMER_RATE ),
+    pTimer->hService = SERVICE_AddTimer( max( timeout * 1000L, SYS_TIMER_RATE ),
                                        TIMER_CheckTimer, (ULONG_PTR)pTimer );
     
     TRACE("Timer added: %p, %04x, %04x, %04x, %08lx\n", 
diff --git a/windows/user.c b/windows/user.c
index c8b3f6b..7d4a735 100644
--- a/windows/user.c
+++ b/windows/user.c
@@ -69,7 +69,7 @@
     default:
         return 0;
     }
-    return (WORD)MIN( userPercent, gdiPercent );
+    return (WORD)min( userPercent, gdiPercent );
 }
 
 
diff --git a/windows/winpos.c b/windows/winpos.c
index ba42028..f615246 100644
--- a/windows/winpos.c
+++ b/windows/winpos.c
@@ -1142,9 +1142,9 @@
                       MinMax.ptMaxPosition.x, MinMax.ptMaxPosition.y,
                       MinMax.ptMaxTrackSize.x, MinMax.ptMaxTrackSize.y,
                       MinMax.ptMinTrackSize.x, MinMax.ptMinTrackSize.y);
-    MinMax.ptMaxTrackSize.x = MAX( MinMax.ptMaxTrackSize.x,
+    MinMax.ptMaxTrackSize.x = max( MinMax.ptMaxTrackSize.x,
                                    MinMax.ptMinTrackSize.x );
-    MinMax.ptMaxTrackSize.y = MAX( MinMax.ptMaxTrackSize.y,
+    MinMax.ptMaxTrackSize.y = max( MinMax.ptMaxTrackSize.y,
                                    MinMax.ptMinTrackSize.y );
 
     if (maxSize) *maxSize = MinMax.ptMaxSize;
@@ -2087,8 +2087,8 @@
 	((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) == 0))
     {
 	WINPOS_GetMinMaxInfo( wndPtr, &maxSize, NULL, NULL, NULL );
-	winpos->cx = MIN( winpos->cx, maxSize.x );
-	winpos->cy = MIN( winpos->cy, maxSize.y );
+	winpos->cx = min( winpos->cx, maxSize.x );
+	winpos->cy = min( winpos->cy, maxSize.y );
     }
     return 0;
 }
@@ -2239,8 +2239,8 @@
 
 	r.left = Wnd->rectClient.left - Wnd->rectWindow.left;
         r.top = Wnd->rectClient.top  - Wnd->rectWindow.top;
-	r.right = r.left + MIN( ocw, ncw );
-	r.bottom = r.top + MIN( och, nch );
+	r.right = r.left + min( ocw, ncw );
+	r.bottom = r.top + min( och, nch );
 
 	REGION_CropRgn( hrgnValid, hrgnValid, &r, 
 			(uFlags & SWP_EX_PAINTSELF) ? NULL : (POINT*)&(Wnd->rectWindow));
diff --git a/windows/winproc.c b/windows/winproc.c
index 861e8eb..7b6893e 100644
--- a/windows/winproc.c
+++ b/windows/winproc.c
@@ -1620,7 +1620,7 @@
     case LB_GETSELITEMS:
         {
             LPINT16 items;
-            *pwparam16 = (WPARAM16)MIN( wParam32, 0x7f80 ); /* Must be < 64K */
+            *pwparam16 = (WPARAM16)min( wParam32, 0x7f80 ); /* Must be < 64K */
             if (!(items = SEGPTR_ALLOC( *pwparam16 * sizeof(INT16)
                                         + sizeof(LPARAM)))) return -1;
             *((LPARAM *)items)++ = *plparam;  /* Store the previous lParam */
@@ -1633,7 +1633,7 @@
         {
             INT i;
             LPINT16 stops;
-            *pwparam16 = (WPARAM16)MIN( wParam32, 0x7f80 ); /* Must be < 64K */
+            *pwparam16 = (WPARAM16)min( wParam32, 0x7f80 ); /* Must be < 64K */
             if (!(stops = SEGPTR_ALLOC( *pwparam16 * sizeof(INT16)
                                         + sizeof(LPARAM)))) return -1;
             for (i = 0; i < *pwparam16; i++) stops[i] = *((LPINT)*plparam+i);
@@ -1765,7 +1765,7 @@
     case WM_GETTEXT:
         {
             LPSTR str;
-            *pwparam16 = (WPARAM16)MIN( wParam32, 0xff80 ); /* Must be < 64K */
+            *pwparam16 = (WPARAM16)min( wParam32, 0xff80 ); /* Must be < 64K */
             if (!(str = SEGPTR_ALLOC(*pwparam16 + sizeof(LPARAM)))) return -1;
             *((LPARAM *)str)++ = *plparam;  /* Store the previous lParam */
             *plparam = (LPARAM)SEGPTR_GET(str);