diff -Naur windows_split2/src/sound.cpp windows_split3/src/sound.cpp
--- windows_split2/src/sound.cpp	2008-04-04 21:08:43.000000000 +0200
+++ windows_split3/src/sound.cpp	2008-04-06 12:08:32.000000000 +0200
@@ -198,9 +198,7 @@
 
 void SndCopyToPool()
 {
-	uint i;
-
-	for (i = 0; i < _file_count; i++) {
+	for (uint i = 0; i < _file_count; i++) {
 		FileEntry *orig = &_files[_sound_idx[i]];
 		FileEntry *fe = AllocateFileEntry();
 
@@ -212,7 +210,7 @@
 
 static void SndPlayScreenCoordFx(SoundFx sound, int left, int right, int top, int bottom)
 {
-	Window* const *wz;
+	WindowListItem_const wz;
 
 	if (msf.effect_vol == 0) return;
 
diff -Naur windows_split2/src/station_gui.cpp windows_split3/src/station_gui.cpp
--- windows_split2/src/station_gui.cpp	2008-04-06 10:07:11.000000000 +0200
+++ windows_split3/src/station_gui.cpp	2008-04-06 12:10:05.000000000 +0200
@@ -184,36 +184,37 @@
 };
 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(plstations_d));
 
+
 /**
- * Set the 'SL_REBUILD' flag for all station lists
+ * Set the \a slf flag for all station-list windows
  */
-void RebuildStationLists()
+static void SetStationListsFlag(StationListFlags slf)
 {
-	Window* const *wz;
+	WindowListItem_const wz;
 
 	FOR_ALL_WINDOWS(wz) {
 		Window *w = *wz;
 		if (w->window_class == WC_STATION_LIST) {
-			WP(w, plstations_d).flags |= SL_REBUILD;
+			WP(w, plstations_d).flags |= slf;
 			SetWindowDirty(w);
 		}
 	}
 }
 
 /**
+ * Set the 'SL_REBUILD' flag for all station lists
+ */
+void RebuildStationLists()
+{
+	SetStationListsFlag(SL_REBUILD);
+}
+
+/**
  * Set the 'SL_RESORT' flag for all station lists
  */
 void ResortStationLists()
 {
-	Window* const *wz;
-
-	FOR_ALL_WINDOWS(wz) {
-		Window *w = *wz;
-		if (w->window_class == WC_STATION_LIST) {
-			WP(w, plstations_d).flags |= SL_RESORT;
-			SetWindowDirty(w);
-		}
-	}
+	SetStationListsFlag(SL_RESORT);
 }
 
 /**
diff -Naur windows_split2/src/vehicle_gui.cpp windows_split3/src/vehicle_gui.cpp
--- windows_split2/src/vehicle_gui.cpp	2008-04-01 22:09:14.000000000 +0200
+++ windows_split3/src/vehicle_gui.cpp	2008-04-06 12:10:20.000000000 +0200
@@ -99,9 +99,9 @@
 	INVALID_STRING_ID
 };
 
-void RebuildVehicleLists()
+static void SetVehicleListsFlag(SortListFlags slf)
 {
-	Window* const *wz;
+	WindowListItem_const wz;
 
 	FOR_ALL_WINDOWS(wz) {
 		Window *w = *wz;
@@ -111,7 +111,7 @@
 			case WC_ROADVEH_LIST:
 			case WC_SHIPS_LIST:
 			case WC_AIRCRAFT_LIST:
-				WP(w, vehiclelist_d).l.flags |= VL_REBUILD;
+				WP(w, vehiclelist_d).l.flags |= slf;
 				SetWindowDirty(w);
 				break;
 
@@ -120,25 +120,20 @@
 	}
 }
 
-void ResortVehicleLists()
+/**
+ * Rebuild all vehicle list windows
+ */
+void RebuildVehicleLists()
 {
-	Window* const *wz;
-
-	FOR_ALL_WINDOWS(wz) {
-		Window *w = *wz;
-
-		switch (w->window_class) {
-			case WC_TRAINS_LIST:
-			case WC_ROADVEH_LIST:
-			case WC_SHIPS_LIST:
-			case WC_AIRCRAFT_LIST:
-				WP(w, vehiclelist_d).l.flags |= VL_RESORT;
-				SetWindowDirty(w);
-				break;
+	SetVehicleListsFlag(VL_REBUILD);
+}
 
-			default: break;
-		}
-	}
+/**
+ * Resort all vehicle list windows
+ */
+void ResortVehicleLists()
+{
+	SetVehicleListsFlag(VL_RESORT);
 }
 
 void BuildVehicleList(vehiclelist_d *vl, PlayerID owner, uint16 index, uint16 window_type)
diff -Naur windows_split2/src/viewport.cpp windows_split3/src/viewport.cpp
--- windows_split2/src/viewport.cpp	2008-04-05 12:38:01.000000000 +0200
+++ windows_split3/src/viewport.cpp	2008-04-06 12:29:52.000000000 +0200
@@ -206,10 +206,10 @@
 
 static Point _vp_move_offs;
 
-static void DoSetViewportPosition(Window* const *wz, int left, int top, int width, int height)
+static void DoSetViewportPosition(WindowListItem_const wz, int left, int top, int width, int height)
 {
 
-	for (; wz != _last_z_window; wz++) {
+	for (; wz != WindowListItem_TOP(); wz++) {
 		const Window *w = *wz;
 
 		if (left + width > w->left &&
@@ -323,7 +323,11 @@
 		i = top + height - _screen.height;
 		if (i >= 0) height -= i;
 
-		if (height > 0) DoSetViewportPosition(FindWindowZPosition(w) + 1, left, top, width, height);
+		if (height > 0) {
+			WindowListItem_const wz = FindWindowZPosition(w);
+			wz++;
+			DoSetViewportPosition(wz, left, top, width, height);
+		}
 	}
 }
 
@@ -1724,7 +1728,7 @@
 
 void MarkAllViewportsDirty(int left, int top, int right, int bottom)
 {
-	Window* const *wz;
+	WindowListItem_const wz;
 
 	FOR_ALL_WINDOWS(wz) {
 		const ViewPort *vp = (*wz)->viewport;
diff -Naur windows_split2/src/widgets/dropdown.cpp windows_split3/src/widgets/dropdown.cpp
--- windows_split2/src/widgets/dropdown.cpp	2008-03-27 21:30:12.000000000 +0100
+++ windows_split3/src/widgets/dropdown.cpp	2008-04-06 12:47:04.000000000 +0200
@@ -313,9 +313,14 @@
 	ShowDropDownList(w, list, selected, button);
 }
 
+/**
+ * Delete the drop-down menu from window \a pw
+ * @param pw Parent window of the drop-down menu window
+ */
 void HideDropDownMenu(Window *pw)
 {
-	Window **wz;
+	WindowListItem wz;
+
 	FOR_ALL_WINDOWS(wz) {
 		if ((*wz)->window_class != WC_DROPDOWN_MENU) continue;
 
diff -Naur windows_split2/src/window_func.h windows_split3/src/window_func.h
--- windows_split2/src/window_func.h	2008-04-06 12:20:43.000000000 +0200
+++ windows_split3/src/window_func.h	2008-04-06 12:42:48.000000000 +0200
@@ -5,14 +5,19 @@
 #ifndef WINDOW_FUNC_H
 #define WINDOW_FUNC_H
 
+#include <list>
 #include "core/geometry_type.hpp"
 #include "window_type.h"
 #include "player_type.h"
 
+typedef std::list<Window*> WindowList;
+typedef WindowList::iterator WindowListItem;              ///< Iterating item in window list (from bottom to top)
+typedef WindowList::const_iterator WindowListItem_const;  ///< Constant iterating item in window list (from bottom to top)
+#define WindowListItem_BOTTOM() (_window_list.begin())
+#define WindowListItem_TOP()    (_window_list.end())
+#define FOR_ALL_WINDOWS(wz) for (wz = WindowListItem_BOTTOM(); wz != WindowListItem_TOP(); wz++)
 
-extern Window *_z_windows[]; ///< Window stack, lowest window (behind all others) is at index 0
-extern Window **_last_z_window; ///< always points to the next free space in the z-array
-#define FOR_ALL_WINDOWS(wz) for (wz = _z_windows; wz != _last_z_window; wz++)
+extern WindowList _window_list;
 
 
 extern Point _cursorpos_drag_start;
@@ -69,7 +74,7 @@
  * Special window functions for GUI users
  */
 Window *FindWindowById(WindowClass cls, WindowNumber number);
-Window **FindWindowZPosition(const Window *w);
+WindowListItem FindWindowZPosition(const Window *w);
 
 void DeleteWindowById(WindowClass cls, WindowNumber number);
 void DeleteWindowByClass(WindowClass cls);
diff -Naur windows_split2/src/window_gui.h windows_split3/src/window_gui.h
--- windows_split2/src/window_gui.h	2008-04-06 11:36:49.000000000 +0200
+++ windows_split3/src/window_gui.h	2008-04-06 11:34:38.000000000 +0200
@@ -11,11 +11,6 @@
 #include "player_type.h"
 #include "strings_type.h"
 
-/**
- * The maximum number of windows that can be opened.
- */
-static const int MAX_NUMBER_OF_WINDOWS = 25;
-
 typedef void WindowProc(Window *w, WindowEvent *e);
 
 /* How the resize system works:
diff -Naur windows_split2/src/window_list.cpp windows_split3/src/window_list.cpp
--- windows_split2/src/window_list.cpp	2008-04-06 10:44:44.000000000 +0200
+++ windows_split3/src/window_list.cpp	2008-04-06 12:06:54.000000000 +0200
@@ -27,13 +27,21 @@
 
 #include "table/sprites.h"
 
-static Point _drag_delta; //< delta between mouse cursor and upper left corner of dragged window
+/**
+ * The maximum number of windows that can be opened.
+ */
+static const unsigned int MAX_NUMBER_OF_WINDOWS = 25;
+
+/**
+ * List of windows opened at the screen.
+ * Uppermost window is at _window_list.back(), bottom window is at _window_list.front().
+ */
+WindowList _window_list;
 
-Window *_z_windows[MAX_NUMBER_OF_WINDOWS]; ///< Window stack, lowest window (behind all others) is at index 0
-Window **_last_z_window; ///< always points to the next free space in the z-array
 static Window *_mouseover_last_w = NULL; ///< Pointer to window last called with MOUSEOVER event
 
 Point _cursorpos_drag_start;
+static Point _drag_delta; //< delta between mouse cursor and upper left corner of dragged window
 
 int _scrollbar_start_pos;
 int _scrollbar_size;
@@ -62,12 +70,12 @@
  * @param right Right edge of the rectangle that should be repainted
  * @param bottom Bottom edge of the rectangle that should be repainted
  */
-static void DrawOverlappedWindow(Window* const *wz, int left, int top, int right, int bottom)
+static void DrawOverlappedWindow(WindowListItem_const wz, int left, int top, int right, int bottom)
 {
-	Window* const *vz = wz;
-	int x;
+	WindowListItem_const vz = wz;
+	vz++;
 
-	while (++vz != _last_z_window) {
+	for (; vz != WindowListItem_TOP(); vz++) {
 		const Window *v = *vz; // Window v is more to front in stack than window *wz
 
 		if (right > v->left &&
@@ -75,6 +83,7 @@
 				left < v->left + v->width &&
 				top < v->top + v->height) {
 			/* v and rectangle intersect with eeach other */
+			int x;
 
 			if (left < (x = v->left)) {
 				DrawOverlappedWindow(wz, left, top, x, bottom);
@@ -105,17 +114,15 @@
 	}
 
 	/* Setup blitter, and dispatch a repaint event to window *wz */
-	{
-		DrawPixelInfo *dp = _cur_dpi;
-		dp->width = right - left;
-		dp->height = bottom - top;
-		dp->left = left - (*wz)->left;
-		dp->top = top - (*wz)->top;
-		dp->pitch = _screen.pitch;
-		dp->dst_ptr = BlitterFactoryBase::GetCurrentBlitter()->MoveTo(_screen.dst_ptr, left, top);
-		dp->zoom = ZOOM_LVL_NORMAL;
-		CallWindowEventNP(*wz, WE_PAINT);
-	}
+	DrawPixelInfo *dp = _cur_dpi;
+	dp->width = right - left;
+	dp->height = bottom - top;
+	dp->left = left - (*wz)->left;
+	dp->top = top - (*wz)->top;
+	dp->pitch = _screen.pitch;
+	dp->dst_ptr = BlitterFactoryBase::GetCurrentBlitter()->MoveTo(_screen.dst_ptr, left, top);
+	dp->zoom = ZOOM_LVL_NORMAL;
+	CallWindowEventNP(*wz, WE_PAINT);
 }
 
 /**
@@ -128,7 +135,7 @@
  */
 void DrawOverlappedWindowForAll(int left, int top, int right, int bottom)
 {
-	Window* const *wz;
+	WindowListItem_const wz;
 	DrawPixelInfo bk;
 	_cur_dpi = &bk;
 
@@ -167,7 +174,7 @@
  * @return a Window pointer that is the child of w, or NULL otherwise */
 static Window *FindChildWindow(const Window *w)
 {
-	Window* const *wz;
+	WindowListItem_const wz;
 
 	FOR_ALL_WINDOWS(wz) {
 		Window *v = *wz;
@@ -180,18 +187,19 @@
 /** Find the z-value of a window. A window must already be open
  * or the behaviour is undefined but function should never fail
  * @param w window to query Z Position
- * @return the window that matches it */
-Window **FindWindowZPosition(const Window *w)
+ * @return Pointer into the window-list at the position of \a w
+ */
+WindowListItem FindWindowZPosition(const Window *w)
 {
-	Window **wz;
+	WindowListItem wz;
 
-	for (wz = _z_windows; wz != _last_z_window; wz++) {
+	FOR_ALL_WINDOWS(wz) {
 		if (*wz == w) return wz;
 	}
 
 	DEBUG(misc, 3, "Window (cls %d, number %d) is not open, probably removed by recursive calls",
 		w->window_class, w->window_number);
-	return NULL;
+	return WindowListItem_TOP();
 }
 
 /**
@@ -199,12 +207,10 @@
  */
 void DeleteWindow(Window *w)
 {
-	Window *v;
-	Window **wz;
 	if (w == NULL) return;
 
 	/* Delete any children a window might have in a head-recursive manner */
-	v = FindChildWindow(w);
+	Window *v = FindChildWindow(w);
 	if (v != NULL) DeleteWindow(v);
 
 	if (_thd.place_mode != VHM_NONE &&
@@ -216,12 +222,8 @@
 	CallWindowEventNP(w, WE_DESTROY);
 	SetWindowDirty(w); // Ensure that the area covered by the deleted window will be redrawn
 
-	/* Find the window in the z-array, and effectively remove it
-	 * by moving all windows after it one to the left */
-	wz = FindWindowZPosition(w);
-	if (wz == NULL) return;
-	memmove(wz, wz + 1, (byte*)_last_z_window - (byte*)wz);
-	_last_z_window--;
+	WindowListItem wz = FindWindowZPosition(w);  // Find and remove window from the window list
+	_window_list.erase(wz);
 
 	if (w == _mouseover_last_w) {
 		_mouseover_last_w = NULL; // Don't let HandleMouseOver() call this window
@@ -237,7 +239,7 @@
  */
 Window *FindWindowById(WindowClass cls, WindowNumber number)
 {
-	Window* const *wz;
+	WindowListItem_const wz;
 
 	FOR_ALL_WINDOWS(wz) {
 		Window *w = *wz;
@@ -263,7 +265,7 @@
  */
 void DeleteWindowByClass(WindowClass cls)
 {
-	Window* const *wz;
+	WindowListItem_const wz;
 
 restart_search:
 	/* When we find the window to delete, we need to restart the search
@@ -285,7 +287,7 @@
  * @param id PlayerID player identifier */
 void DeletePlayerWindows(PlayerID id)
 {
-	Window* const *wz;
+	WindowListItem_const wz;
 
 restart_search:
 	/* When we find the window to delete, we need to restart the search
@@ -311,7 +313,7 @@
  * @param new_player PlayerID of the new owner of the window */
 void ChangeWindowOwner(PlayerID old_player, PlayerID new_player)
 {
-	Window* const *wz;
+	WindowListItem_const wz;
 
 	FOR_ALL_WINDOWS(wz) {
 		Window *w = *wz;
@@ -341,21 +343,25 @@
  */
 static void BringWindowToFront(const Window *w)
 {
-	Window *tempz;
-	Window **wz = FindWindowZPosition(w);
-	Window **vz = _last_z_window;
+	WindowListItem wz = FindWindowZPosition(w);
+	WindowListItem vz = WindowListItem_TOP();
 
-	/* Bring the window just below the vital windows */
-	do {
-		if (--vz < _z_windows) return;
-	} while (IsVitalWindow(*vz));
+	assert(!_window_list.empty());  // There should be opened windows (at least \c *w )
+
+	/* Find top-most window just below vital windows */
+	vz--;
+	while (IsVitalWindow(*vz)) {
+		assert(vz != wz);   // w should not be a vital window
+		if (vz == WindowListItem_BOTTOM()) return;  // entire window-list consists of vital windows
+		vz--;
+	}
 
 	if (wz == vz) return; // window is already in the right position
-	assert(wz < vz);
 
-	tempz = *wz;
-	memmove(wz, wz + 1, (byte*)vz - (byte*)wz);
-	*vz = tempz;
+	/* Bring the window just below the vital windows */
+	vz++;
+	_window_list.insert(vz, *wz);
+	_window_list.erase(wz);
 
 	SetWindowDirty(w);
 }
@@ -393,7 +399,7 @@
  */
 static Window *FindDeletableWindow()
 {
-	Window* const *wz;
+	WindowListItem_const wz;
 
 	FOR_ALL_WINDOWS(wz) {
 		Window *w = *wz;
@@ -413,11 +419,10 @@
  */
 static Window *ForceFindDeletableWindow()
 {
-	Window* const *wz;
+	WindowListItem_const wz;
 
-	for (wz = _z_windows;; wz++) {
+	FOR_ALL_WINDOWS(wz) {
 		Window *w = *wz;
-		assert(wz < _last_z_window);
 		if (w->window_class != WC_MAIN_WINDOW && !IsVitalWindow(w)) return w;
 	}
 	NOT_REACHED();
@@ -444,10 +449,8 @@
 static Window *LocalAllocateWindow(int x, int y, int min_width, int min_height, int def_width, int def_height,
 				WindowProc *proc, WindowClass cls, const Widget *widget, int window_number, void *data)
 {
-	assert(_last_z_window >= _z_windows && _last_z_window <= endof(_z_windows)); // _last_z_window sanity check
-
 	/* We have too many open windows, close one first */
-	if (_last_z_window == endof(_z_windows)) {
+	if (_window_list.size() >= MAX_NUMBER_OF_WINDOWS) {
 		Window *w = FindDeletableWindow();
 		if (w == NULL) w = ForceFindDeletableWindow();
 		DeleteWindow(w);
@@ -457,7 +460,7 @@
 				x, y, min_width, min_height, proc, widget, window_number);
 
 	{
-		Window **wz = _last_z_window;
+		WindowListItem wz = WindowListItem_TOP();
 
 		/* Hacky way of specifying always-on-top windows. These windows are
 		 * always above other windows because they are moved below them.
@@ -467,18 +470,26 @@
 		 * XXX - Yes, ugly, probably needs something like w->always_on_top flag
 		 * to implement correctly, but even then you need some kind of distinction
 		 * between on-top of chat/news and status windows, because these conflict */
-		if (wz != _z_windows && w->window_class != WC_SEND_NETWORK_MSG && w->window_class != WC_HIGHSCORE && w->window_class != WC_ENDSCREEN) {
-			if (FindWindowById(WC_MAIN_TOOLBAR, 0)     != NULL) wz--;
-			if (FindWindowById(WC_STATUS_BAR, 0)       != NULL) wz--;
-			if (FindWindowById(WC_NEWS_WINDOW, 0)      != NULL) wz--;
-			if (FindWindowById(WC_SEND_NETWORK_MSG, 0) != NULL) wz--;
-
-			assert(wz >= _z_windows);
-			if (wz != _last_z_window) memmove(wz + 1, wz, (byte*)_last_z_window - (byte*)wz);
+		if (w->window_class != WC_SEND_NETWORK_MSG
+				&& w->window_class != WC_HIGHSCORE && w->window_class != WC_ENDSCREEN) {
+			if (FindWindowById(WC_MAIN_TOOLBAR, 0) != NULL) {
+				assert(wz != WindowListItem_BOTTOM());
+				wz--;
+			}
+			if (FindWindowById(WC_STATUS_BAR, 0) != NULL) {
+				assert(wz != WindowListItem_BOTTOM());
+				wz--;
+			}
+			if (FindWindowById(WC_NEWS_WINDOW, 0) != NULL) {
+				assert(wz != WindowListItem_BOTTOM());
+				wz--;
+			}
+			if (FindWindowById(WC_SEND_NETWORK_MSG, 0) != NULL) {
+				assert(wz != WindowListItem_BOTTOM());
+				wz--;
+			}
 		}
-
-		*wz = w;
-		_last_z_window++;
+		_window_list.insert(wz, w);
 	}
 
 	WindowEvent e;
@@ -562,7 +573,7 @@
 
 static bool IsGoodAutoPlace1(int left, int top, int width, int height, Point &pos)
 {
-	Window* const *wz;
+	WindowListItem_const wz;
 
 	int right  = width + left;
 	int bottom = height + top;
@@ -590,7 +601,7 @@
 
 static bool IsGoodAutoPlace2(int left, int top, int width, int height, Point &pos)
 {
-	Window* const *wz;
+	WindowListItem_const wz;
 
 	if (left < -(width>>2) || left > _screen.width - (width>>1)) return false;
 	if (top < 22 || top > _screen.height - (height>>2)) return false;
@@ -615,7 +626,7 @@
 
 static Point GetAutoPlacePosition(int width, int height)
 {
-	Window* const *wz;
+	WindowListItem_const wz;
 	Point pt;
 
 	if (IsGoodAutoPlace1(0, 24, width, height, pt)) return pt;
@@ -768,12 +779,11 @@
  * For this we start at the topmost window, obviously and work our way down to the bottom
  * @param x position x to query
  * @param y position y to query
- * @return a pointer to the found window if any, NULL otherwise */
+ * @return a pointer to the found window if any, NULL otherwise
+ */
 Window *FindWindowFromPt(int x, int y)
 {
-	Window* const *wz;
-
-	for (wz = _last_z_window; wz != _z_windows;) {
+	for (WindowListItem_const wz = WindowListItem_TOP(); wz != WindowListItem_BOTTOM();) {
 		Window *w = *--wz;
 		if (IsInsideBS(x, w->left, w->width) && IsInsideBS(y, w->top, w->height)) {
 			return w;
@@ -792,14 +802,14 @@
 {
 	IConsoleClose();
 
-	_last_z_window = _z_windows;
+	_window_list.clear();
 	_mouseover_last_w = NULL;
 	_no_scroll = 0;
 }
 
 void UnInitWindowSystem()
 {
-	Window **wz;
+	WindowListItem wz;
 
 restart_search:
 	/* Delete all windows, reset z-array.
@@ -812,7 +822,7 @@
 		goto restart_search;
 	}
 
-	assert(_last_z_window == _z_windows);
+	assert(_window_list.empty());
 }
 
 void ResetWindowSystem()
@@ -832,9 +842,9 @@
 static void DecreaseWindowCounters()
 {
 	Window *w;
-	Window* const *wz;
+	WindowListItem_const wz;
 
-	for (wz = _last_z_window; wz != _z_windows;) {
+	for (wz = WindowListItem_TOP(); wz != WindowListItem_BOTTOM();) {
 		w = *--wz;
 		/* Unclick scrollbar buttons if they are pressed. */
 		if (w->flags4 & (WF_SCROLL_DOWN | WF_SCROLL_UP)) {
@@ -844,7 +854,7 @@
 		CallWindowEventNP(w, WE_MOUSELOOP);
 	}
 
-	for (wz = _last_z_window; wz != _z_windows;) {
+	for (wz = WindowListItem_TOP(); wz != WindowListItem_BOTTOM();) {
 		w = *--wz;
 
 		if (w->flags4&WF_TIMEOUT_MASK && !(--w->flags4&WF_TIMEOUT_MASK)) {
@@ -970,7 +980,8 @@
 
 static bool HandleWindowDragging()
 {
-	Window* const *wz;
+	WindowListItem_const wz;
+
 	/* Get out immediately if no window is being dragged at all. */
 	if (!_dragging_window) return true;
 
@@ -1000,7 +1011,7 @@
 			ny = y;
 
 			if (_patches.window_snap_radius != 0) {
-				Window* const *vz;
+				WindowListItem_const vz;
 
 				int hsnap = _patches.window_snap_radius;
 				int vsnap = _patches.window_snap_radius;
@@ -1202,7 +1213,7 @@
 
 static bool HandleScrollbarScrolling()
 {
-	Window* const *wz;
+	WindowListItem_const wz;
 	int i;
 	int pos;
 	Scrollbar *sb;
@@ -1311,8 +1322,7 @@
 static bool MaybeBringWindowToFront(const Window *w)
 {
 	bool bring_to_front = false;
-	Window* const *wz;
-	Window* const *uz;
+	WindowListItem_const wz;
 
 	if (w->window_class == WC_MAIN_WINDOW ||
 			IsVitalWindow(w) ||
@@ -1322,7 +1332,7 @@
 	}
 
 	wz = FindWindowZPosition(w);
-	for (uz = wz; ++uz != _last_z_window;) {
+	for (WindowListItem_const uz = wz; ++uz != WindowListItem_TOP();) {
 		Window *u = *uz;
 
 		/* A modal child will prevent the activation of the parent window */
@@ -1398,7 +1408,7 @@
  */
 void SendWindowMessageClass(WindowClass wnd_class, int msg, int wparam, int lparam)
 {
-	Window* const *wz;
+	WindowListItem_const wz;
 
 	FOR_ALL_WINDOWS(wz) {
 		if ((*wz)->window_class == wnd_class) SendWindowMessageW(*wz, msg, wparam, lparam);
@@ -1415,7 +1425,6 @@
  */
 void HandleKeypress(uint32 key)
 {
-	Window* const *wz;
 	WindowEvent e;
 	/* Stores if a window with a textfield for typing is open
 	 * If this is the case, keypress events are only passed to windows with text fields and
@@ -1464,7 +1473,7 @@
 	}
 
 	/* Call the event, start with the uppermost window. */
-	for (wz = _last_z_window; wz != _z_windows;) {
+	for (WindowListItem_const wz = WindowListItem_TOP(); wz != WindowListItem_BOTTOM();) {
 		Window *w = *--wz;
 
 		/* if a query window is open, only call the event for certain window types */
@@ -1499,7 +1508,7 @@
 	e.we.ctrl.cont = true;
 
 	/* Call the event, start with the uppermost window. */
-	for (Window* const *wz = _last_z_window; wz != _z_windows;) {
+	for (WindowListItem_const wz = WindowListItem_TOP(); wz != WindowListItem_BOTTOM();) {
 		Window *w = *--wz;
 		w->wndproc(w, &e);
 		if (!e.we.ctrl.cont) break;
@@ -1736,19 +1745,19 @@
  */
 void UpdateWindows()
 {
-	Window* const *wz;
+	WindowListItem_const wz;
 	static int we4_timer = 0;
 	int t = we4_timer + 1;
 
 	if (t >= 100) {
-		for (wz = _last_z_window; wz != _z_windows;) {
+		for (wz = WindowListItem_TOP(); wz != WindowListItem_BOTTOM();) {
 			CallWindowEventNP(*--wz, WE_4);
 		}
 		t = 0;
 	}
 	we4_timer = t;
 
-	for (wz = _last_z_window; wz != _z_windows;) {
+	for (wz = WindowListItem_TOP(); wz != WindowListItem_BOTTOM();) {
 		Window *w = *--wz;
 		if (w->flags4 & WF_WHITE_BORDER_MASK) {
 			w->flags4 -= WF_WHITE_BORDER_ONE;
@@ -1781,7 +1790,7 @@
  */
 void InvalidateWindow(WindowClass cls, WindowNumber number)
 {
-	Window* const *wz;
+	WindowListItem_const wz;
 
 	FOR_ALL_WINDOWS(wz) {
 		const Window *w = *wz;
@@ -1797,7 +1806,7 @@
  */
 void InvalidateWindowWidget(WindowClass cls, WindowNumber number, byte widget_index)
 {
-	Window* const *wz;
+	WindowListItem_const wz;
 
 	FOR_ALL_WINDOWS(wz) {
 		const Window *w = *wz;
@@ -1813,7 +1822,7 @@
  */
 void InvalidateWindowClasses(WindowClass cls)
 {
-	Window* const *wz;
+	WindowListItem_const wz;
 
 	FOR_ALL_WINDOWS(wz) {
 		if ((*wz)->window_class == cls) SetWindowDirty(*wz);
@@ -1826,7 +1835,7 @@
  */
 void InvalidateWindowData(WindowClass cls, WindowNumber number)
 {
-	Window* const *wz;
+	WindowListItem_const wz;
 
 	FOR_ALL_WINDOWS(wz) {
 		Window *w = *wz;
@@ -1840,7 +1849,7 @@
  */
 void InvalidateWindowClassesData(WindowClass cls)
 {
-	Window* const *wz;
+	WindowListItem_const wz;
 
 	FOR_ALL_WINDOWS(wz) {
 		if ((*wz)->window_class == cls) InvalidateThisWindowData(*wz);
@@ -1856,9 +1865,7 @@
  */
 void CallWindowTickEvent()
 {
-	Window* const *wz;
-
-	for (wz = _last_z_window; wz != _z_windows;) {
+	for (WindowListItem_const wz = WindowListItem_TOP(); wz != WindowListItem_BOTTOM();) {
 		CallWindowEventNP(*--wz, WE_TICK);
 	}
 }
@@ -1869,7 +1876,7 @@
 
 void DeleteNonVitalWindows()
 {
-	Window* const *wz;
+	WindowListItem_const wz;
 
 restart_search:
 	/* When we find the window to delete, we need to restart the search
@@ -1898,7 +1905,7 @@
  * that standard windows (status bar, etc.) are not stickied, so these aren't affected */
 void DeleteAllNonVitalWindows()
 {
-	Window* const *wz;
+	WindowListItem_const wz;
 
 	/* Delete every window except for stickied ones, then sticky ones as well */
 	DeleteNonVitalWindows();
@@ -1956,7 +1963,7 @@
  */
 void RelocateAllWindows(int neww, int newh)
 {
-	Window* const *wz;
+	WindowListItem_const wz;
 
 	FOR_ALL_WINDOWS(wz) {
 		Window *w = *wz;
