diff --git a/runtime/doc/gui_w32.txt b/runtime/doc/gui_w32.txt
index b92a69321537d52efb6bc00ff47e821e230ddf41..17ed69a60c7470e65bf393d485a35412972ea851 100644
--- a/runtime/doc/gui_w32.txt
+++ b/runtime/doc/gui_w32.txt
@@ -1,4 +1,4 @@
-*gui_w32.txt*   For Vim version 7.1.  Last change: 2007 May 03
+*gui_w32.txt*   For Vim version 7.1.  Last change: 2007 Aug 14
 
 
 		  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -53,6 +53,16 @@ vimrc or gvimrc file: >
 There is a specific version of gvim.exe that runs under the Win32s subsystem
 of Windows 3.1 or 3.11.  See |win32s|.
 
+
+Using Vim as a plugin					*gui-w32-windowid*
+
+When gvim starts up normally, it creates its own top level window.  If you
+pass Vim the command-line option |--windowid| with a decimal or hexadecimal
+value, Vim will create a window that is a child of the window with the given
+ID.  This enables Vim to act as a plugin in another application.  This really
+is a programmer's interface, and is of no use without a supporting application
+to spawn Vim correctly.
+
 ==============================================================================
 2. Vim as default editor				*vim-default-editor*
 
diff --git a/runtime/doc/starting.txt b/runtime/doc/starting.txt
index 7de79ce41dfda4ce03d21b62307ce5aeda2d3a0b..b58dade4aeec70182b269bfaee5d1d31705e9f34 100644
--- a/runtime/doc/starting.txt
+++ b/runtime/doc/starting.txt
@@ -1,4 +1,4 @@
-*starting.txt*  For Vim version 7.1.  Last change: 2007 May 12
+*starting.txt*  For Vim version 7.1.  Last change: 2007 Aug 14
 
 
 		  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -548,6 +548,11 @@ a slash.  Thus "-R" means recovery and "-/R" readonly.
 		that it runs inside another window.  See |gui-gtk-socketid|
 		for details. {not in Vi}
 
+--windowid {id}						*--windowid*
+		Win32 GUI Vim only.  Make gvim try to use the window {id} as a
+		parent, so that it runs inside that window.  See
+		|gui-w32-windowid| for details. {not in Vi}
+
 --echo-wid						*--echo-wid*
 		GTK+ GUI Vim only.  Make gvim echo the Window ID on stdout,
 		which can be used to run gvim in a kpart widget.  The format
diff --git a/runtime/doc/vi_diff.txt b/runtime/doc/vi_diff.txt
index 854c8baf5eaed5bf703030f2a50ec13453ca26f0..93ba2f5288792af6caf3ea0a0ab0d7a49785d309 100644
--- a/runtime/doc/vi_diff.txt
+++ b/runtime/doc/vi_diff.txt
@@ -1,4 +1,4 @@
-*vi_diff.txt*   For Vim version 7.1.  Last change: 2007 May 07
+*vi_diff.txt*   For Vim version 7.1.  Last change: 2007 Aug 14
 
 
 		  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -827,6 +827,8 @@ Only Vim is able to accept options in between and after the file names.
 
 --socketid {id}		Vim: GTK window socket to run Vim in
 
+--windowid {id}		Vim: Win32 window ID to run Vim in
+
 --version	Vim: show version message and exit.
 
 -?		Vile: print usage summary and exit.
diff --git a/src/globals.h b/src/globals.h
index edd4c79bdf4f441006df25ca7993600972c954ba..d6e879a01753b033d28aa0850646f4e369fb156e 100644
--- a/src/globals.h
+++ b/src/globals.h
@@ -876,7 +876,7 @@ EXTERN int Exec_reg INIT(= FALSE);	/* TRUE when executing a register */
 EXTERN int no_mapping INIT(= FALSE);	/* currently no mapping allowed */
 EXTERN int no_zero_mapping INIT(= 0);	/* mapping zero not allowed */
 EXTERN int allow_keys INIT(= FALSE);	/* allow key codes when no_mapping
-					     * is set */
+					 * is set */
 EXTERN int no_u_sync INIT(= 0);		/* Don't call u_sync() */
 
 EXTERN int restart_edit INIT(= 0);	/* call edit when next cmd finished */
@@ -1252,6 +1252,14 @@ EXTERN guint32	gtk_socket_id INIT(= 0);
 EXTERN int	echo_wid_arg INIT(= FALSE);	/* --echo-wid argument */
 #endif
 
+#ifdef FEAT_GUI_W32
+/*
+ * The value of the --windowid argument.
+ * For embedding gvim inside another application.
+ */
+EXTERN int	win_socket_id INIT(= 0);
+#endif
+
 #if defined(FEAT_CLIENTSERVER) || defined(FEAT_EVAL)
 EXTERN int	typebuf_was_filled INIT(= FALSE); /* received text from client
 						     or from feedkeys() */
diff --git a/src/gui_w32.c b/src/gui_w32.c
index 092d8d516ed1dee5782190e86ba695d1a3a83816..bcc1524a95637fdd155a29cfce3549e653ab2b52 100644
--- a/src/gui_w32.c
+++ b/src/gui_w32.c
@@ -23,6 +23,8 @@
  * e.g., replace LONG with LONG_PTR, etc.
  */
 
+#include "vim.h"
+
 /*
  * These are new in Windows ME/XP, only defined in recent compilers.
  */
@@ -1432,16 +1434,29 @@ gui_mch_init(void)
 	}
     }
     else
-	/* Open toplevel window. */
+    {
+	/* If the provided windowid is not valid reset it to zero, so that it
+	 * is ignored and we open our own window. */
+	if (IsWindow((HWND)win_socket_id) <= 0)
+	    win_socket_id = 0;
+
+	/* Create a window.  If win_socket_id is not zero without border and
+	 * titlebar, it will be reparented below. */
 	s_hwnd = CreateWindow(
-	    szVimWndClass, "Vim MSWindows GUI",
-	    WS_OVERLAPPEDWINDOW,
-	    gui_win_x == -1 ? CW_USEDEFAULT : gui_win_x,
-	    gui_win_y == -1 ? CW_USEDEFAULT : gui_win_y,
-	    100,				/* Any value will do */
-	    100,				/* Any value will do */
-	    NULL, NULL,
-	    s_hinst, NULL);
+		szVimWndClass, "Vim MSWindows GUI",
+		win_socket_id == 0 ? WS_OVERLAPPEDWINDOW : WS_POPUP,
+		gui_win_x == -1 ? CW_USEDEFAULT : gui_win_x,
+		gui_win_y == -1 ? CW_USEDEFAULT : gui_win_y,
+		100,				/* Any value will do */
+		100,				/* Any value will do */
+		NULL, NULL,
+		s_hinst, NULL);
+	if (s_hwnd != NULL && win_socket_id != 0)
+	{
+	    SetParent(s_hwnd, (HWND)win_socket_id);
+	    ShowWindow(s_hwnd, SW_SHOWMAXIMIZED);
+	}
+    }
 
     if (s_hwnd == NULL)
 	return FAIL;
diff --git a/src/main.c b/src/main.c
index 7d553f15587219024032f67cec5a79b235b155c9..ab5d31bf2491275a155e9c7f2fcb60b01449f218 100644
--- a/src/main.c
+++ b/src/main.c
@@ -275,6 +275,7 @@ main
      *   -display or --display
      *   --server...
      *   --socketid
+     *   --windowid
      */
     early_arg_scan(&params);
 
@@ -1489,7 +1490,7 @@ parse_command_name(parmp)
  * Get the name of the display, before gui_prepare() removes it from
  * argv[].  Used for the xterm-clipboard display.
  *
- * Also find the --server... arguments and --socketid
+ * Also find the --server... arguments and --socketid and --windowid
  */
 /*ARGSUSED*/
     static void
@@ -1536,24 +1537,35 @@ early_arg_scan(parmp)
 #  endif
 	}
 # endif
-# ifdef FEAT_GUI_GTK
+
+# if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_W32)
+#  ifdef FEAT_GUI_W32
+	else if (STRICMP(argv[i], "--windowid") == 0)
+#  else
 	else if (STRICMP(argv[i], "--socketid") == 0)
+#  endif
 	{
-	    unsigned int    socket_id;
+	    unsigned int    id;
 	    int		    count;
 
 	    if (i == argc - 1)
 		mainerr_arg_missing((char_u *)argv[i]);
 	    if (STRNICMP(argv[i+1], "0x", 2) == 0)
-		count = sscanf(&(argv[i + 1][2]), "%x", &socket_id);
+		count = sscanf(&(argv[i + 1][2]), "%x", &id);
 	    else
-		count = sscanf(argv[i+1], "%u", &socket_id);
+		count = sscanf(argv[i+1], "%u", &id);
 	    if (count != 1)
 		mainerr(ME_INVALID_ARG, (char_u *)argv[i]);
 	    else
-		gtk_socket_id = socket_id;
+#  ifdef FEAT_GUI_W32
+		win_socket_id = id;
+#  else
+		gtk_socket_id = id;
+#  endif
 	    i++;
 	}
+# endif
+# ifdef FEAT_GUI_GTK
 	else if (STRICMP(argv[i], "--echo-wid") == 0)
 	    echo_wid_arg = TRUE;
 # endif
@@ -1683,8 +1695,12 @@ command_line_scan(parmp)
 		    }
 		}
 #endif
-#ifdef FEAT_GUI_GTK
+#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_W32)
+# ifdef FEAT_GUI_GTK
 		else if (STRNICMP(argv[0] + argv_idx, "socketid", 8) == 0)
+# else
+		else if (STRNICMP(argv[0] + argv_idx, "windowid", 8) == 0)
+# endif
 		{
 		    /* already processed -- snatch the following arg */
 		    if (argc > 1)
@@ -1693,6 +1709,8 @@ command_line_scan(parmp)
 			++argv;
 		    }
 		}
+#endif
+#ifdef FEAT_GUI_GTK
 		else if (STRNICMP(argv[0] + argv_idx, "echo-wid", 8) == 0)
 		{
 		    /* already processed, skip */
@@ -3120,6 +3138,7 @@ usage()
 #endif
 #ifdef FEAT_GUI_W32
     main_msg(_("-P <parent title>\tOpen Vim inside parent application"));
+    main_msg(_("--windowid <HWND>\tOpen Vim inside another win32 widget"));
 #endif
 
 #ifdef FEAT_GUI_GNOME
diff --git a/src/version.c b/src/version.c
index cae6b52d7b2a74f0cd4085b219443e2cc1cb8679..c04c5e8e32c9cb30c92c553f43666c564e02a209 100644
--- a/src/version.c
+++ b/src/version.c
@@ -666,6 +666,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    91,
 /**/
     90,
 /**/