--- ./tkWin32Dll.c	Sat Dec  7 16:46:51 2002
+++ ../wince/tkWin32Dll.c	Wed Apr  2 18:06:16 2003
@@ -17,7 +17,7 @@
  * The following declaration is for the VC++ DLL entry point.
  */
 
-BOOL APIENTRY		DllMain _ANSI_ARGS_((HINSTANCE hInst,
+BOOL APIENTRY		DllMain _ANSI_ARGS_((HANDLE hInst,
 			    DWORD reason, LPVOID reserved));
 
 /*
--- ./tkWinClipboard.c	Wed Apr 12 11:51:11 2000
+++ ../wince/tkWinClipboard.c	Tue Mar 11 15:36:55 2003
@@ -54,8 +54,7 @@
     char *data, *destPtr;
     Tcl_DString ds;
     HGLOBAL handle;
-    Tcl_Encoding encoding;
-    int result, locale;
+    int result;
 
     if ((selection != Tk_InternAtom(tkwin, "CLIPBOARD"))
 	    || (target != XA_STRING)
@@ -81,11 +80,15 @@
 		Tcl_UniCharLen((Tcl_UniChar *)data), &ds);
 	GlobalUnlock(handle);
     } else if (IsClipboardFormatAvailable(CF_TEXT)) {
+	Tcl_Encoding encoding = NULL;
 	/*
 	 * Determine the encoding to use to convert this text.
 	 */
 
+#ifdef CF_LOCALE // not defined for Windows CE as of v3.0
 	if (IsClipboardFormatAvailable(CF_LOCALE)) {
+	    int locale;
+
 	    handle = GetClipboardData(CF_LOCALE);
 	    if (!handle) {
 		CloseClipboard();
@@ -115,9 +118,8 @@
 
 	    encoding = Tcl_GetEncoding(NULL, Tcl_DStringValue(&ds));
 	    Tcl_DStringFree(&ds);
-	} else {
-	    encoding = NULL;
 	}
+#endif
 
 	/*
 	 * Fetch the text and convert it to UTF.
--- ./tkWinColor.c	Wed Jul  5 20:17:44 2000
+++ ../wince/tkWinColor.c	Tue Mar 11 15:36:08 2003
@@ -384,8 +384,12 @@
 		}
 	    } else {
 		cmap->size++;
+#ifdef UNDER_CE
+		panic("ResizePalette not implemented");
+#else
 		ResizePalette(cmap->palette, cmap->size);
 		SetPaletteEntries(cmap->palette, cmap->size - 1, 1, &entry);
+#endif
 	    }
 	}
 
--- ./tkWinCursor.c	Wed Aug  7 10:45:58 2002
+++ ../wince/tkWinCursor.c	Tue Mar 11 15:35:06 2003
@@ -125,7 +125,15 @@
 	    ckfree((char *) cursorPtr);
 	    return NULL;
 	}
+#ifdef UNDER_CE
+	Tcl_AppendResult(interp, "can't get cursor from a file on Windows CE",
+		(char *) NULL);
+	ckfree((char *) argv);
+	ckfree((char *) cursorPtr);
+	return NULL;
+#else
 	cursorPtr->winCursor = LoadCursorFromFile(&(argv[0][1]));
+#endif
     } else {
 	/*
 	 * Check for the cursor in the system cursor set.
--- ./tkWinButton.c	Mon Sep  2 18:05:11 2002
+++ ../wince/tkWinButton.c	Tue Mar 11 15:05:48 2003
@@ -261,7 +261,11 @@
     parent = Tk_GetHWND(parentWin);
     if (butPtr->info.type == TYPE_LABEL) {
 	class = "STATIC";
+#ifdef UNDER_CE
+	butPtr->style = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS;
+#else
 	butPtr->style = SS_OWNERDRAW | WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS;
+#endif
     } else {
 	class = "BUTTON";
 	butPtr->style = BS_OWNERDRAW | WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS;
--- ./tkWinDraw.c	Tue Feb 25 18:47:04 2003
+++ ../wince/tkWinDraw.c	Wed Apr  9 18:10:04 2003
@@ -324,7 +324,9 @@
 
     if (clipPtr && clipPtr->type == TKP_CLIP_REGION) {
 	SelectClipRgn(destDC, (HRGN) clipPtr->value.region);
+#ifdef OffsetClipRgn // not defined for Windows CE v3.0
 	OffsetClipRgn(destDC, gc->clip_x_origin, gc->clip_y_origin);
+#endif
     }
 
     BitBlt(destDC, dest_x, dest_y, width, height, srcDC, src_x, src_y,
@@ -399,7 +401,9 @@
 
 	if (clipPtr && clipPtr->type == TKP_CLIP_REGION) {
 	    SelectClipRgn(destDC, (HRGN) clipPtr->value.region);
+#ifdef OffsetClipRgn // not defined for Windows CE v3.0
 	    OffsetClipRgn(destDC, gc->clip_x_origin, gc->clip_y_origin);
+#endif
 	}
 
 	SetBkMode(destDC, OPAQUE);
@@ -585,8 +589,14 @@
 	} else {
 	    infoPtr->bmiHeader.biClrUsed = 0;
 	}
+#ifdef UNDER_CE
+	// emulated function
+	bitmap = CreateDIBitmap(dc, &infoPtr->bmiHeader, 0x04L,
+		image->data, infoPtr, DIB_RGB_COLORS);
+#else
 	bitmap = CreateDIBitmap(dc, &infoPtr->bmiHeader, CBM_INIT,
 		image->data, infoPtr, DIB_RGB_COLORS);
+#endif
 	ckfree((char *) infoPtr);
     }
     if(!bitmap) {
@@ -795,8 +805,10 @@
 	 * destination wherever the pattern is set.
 	 */
 
+#if defined(ALTERNATE) && defined(WINDING) // not on Windows CE as of v3.0
 	SetPolyFillMode(dcMem, (gc->fill_rule == EvenOddRule) ? ALTERNATE
 		: WINDING);
+#endif
 	oldMemBrush = SelectObject(dcMem, CreateSolidBrush(gc->foreground));
 	(*func)(dcMem, winPoints, npoints);
 	BitBlt(dc, rect.left, rect.top, width, height, dcMem, 0, 0, COPYFG);
@@ -824,8 +836,10 @@
 	oldBrush = SelectObject(dc, CreateSolidBrush(gc->foreground));
 	SetROP2(dc, tkpWinRopModes[gc->function]);
 
+#if defined(ALTERNATE) && defined(WINDING) // not on Windows CE as of v3.0
 	SetPolyFillMode(dc, (gc->fill_rule == EvenOddRule) ? ALTERNATE
 		: WINDING);
+#endif
 
 	(*func)(dc, winPoints, npoints);
 
@@ -1129,14 +1143,20 @@
 	 */
 
 	SetBkMode(dc, TRANSPARENT);
+//#ifdef Arc // not defined on Windows CE as of v3.0
 	Arc(dc, x, y, x+width+1, y+height+1, xstart, ystart, xend, yend);
+//#endif
     } else {
 	brush = CreateSolidBrush(gc->foreground);
 	oldBrush = SelectObject(dc, brush);
 	if (gc->arc_mode == ArcChord) {
+//#ifdef Chord // not defined on Windows CE as of v3.0
 	    Chord(dc, x, y, x+width+1, y+height+1, xstart, ystart, xend, yend);
-	} else if ( gc->arc_mode == ArcPieSlice ) {
+//#endif
+	} else if (gc->arc_mode == ArcPieSlice) {
+//#ifdef Pie // not defined on Windows CE as of v3.0
 	    Pie(dc, x, y, x+width+1, y+height+1, xstart, ystart, xend, yend);
+//#endif
 	}
 	DeleteObject(SelectObject(dc, oldBrush));
     }
@@ -1176,7 +1196,7 @@
 	 * but I don't know how to do it better.
 	 * Any ideas: <mailto:j.nijtmans@chello.nl>
 	 */
-
+#ifdef PS_DOT // not defined on Windows CE as of v3.0
 	if (p[1] && p[2]) {
 	    if (!p[3] || p[4]) {
 		style = PS_DASHDOTDOT;		/*	-..	*/
@@ -1190,6 +1210,9 @@
 		style = PS_DOT;			/*	.	*/
 	    }
 	}
+#else
+	style = PS_SOLID;
+#endif
     } else {
 	style = PS_SOLID;
     }
@@ -1202,6 +1225,7 @@
 	lb.lbColor = gc->foreground;
 	lb.lbHatch = 0;
 
+#ifdef PS_GEOMETRIC // not defined on Windows CE as of v3.0
 	style |= PS_GEOMETRIC;
 	switch (gc->cap_style) {
 	    case CapNotLast:
@@ -1226,6 +1250,7 @@
 		style |= PS_JOIN_BEVEL; 
 		break;
 	}
+#endif
 	return ExtCreatePen(style, gc->line_width, &lb, 0, NULL);
     }
 }
--- ./tkWinFont.c	Tue Feb 25 18:47:05 2003
+++ ../wince/tkWinFont.c	Mon Apr  7 18:06:14 2003
@@ -32,7 +32,7 @@
 
 #define FONTMAP_PAGES	    	(1 << (sizeof(Tcl_UniChar)*8 - FONTMAP_SHIFT))
 #define FONTMAP_BITSPERPAGE	(1 << FONTMAP_SHIFT)
-
+#define USE_OLD_TEXTOUT 0
 typedef struct FontFamily {
     struct FontFamily *nextPtr;	/* Next in list of all known font families. */
     int refCount;		/* How many SubFonts are referring to this
@@ -52,6 +52,7 @@
     int isSymbolFont;		/* Non-zero if this is a symbol font. */
     int isWideFont;		/* 1 if this is a double-byte font, 0 
 				 * otherwise. */
+#if USE_OLD_TEXTOUT
     BOOL (WINAPI *textOutProc)(HDC, int, int, TCHAR *, int);
 				/* The procedure to use to draw text after
 				 * it has been converted from UTF-8 to the 
@@ -60,7 +61,7 @@
 				/* The procedure to use to measure text after
 				 * it has been converted from UTF-8 to the 
 				 * encoding of this font. */
-
+#endif
     char *fontMap[FONTMAP_PAGES];
 				/* Two-level sparse table used to determine
 				 * quickly if the specified character exists.
@@ -157,11 +158,13 @@
  */
 
 static TkStateMap systemMap[] = {
+#ifdef ANSI_FIXED_FONT // not defined on Windows CE as of v3.0
     {ANSI_FIXED_FONT,	    "ansifixed"},
     {ANSI_VAR_FONT,	    "ansi"},
     {DEVICE_DEFAULT_FONT,   "device"},
     {OEM_FIXED_FONT,	    "oemfixed"},
     {SYSTEM_FIXED_FONT,	    "systemfixed"},
+#endif
     {SYSTEM_FONT,	    "system"},
     {-1,		    NULL}
 };
@@ -247,7 +250,8 @@
 TkpFontPkgInit(
     TkMainInfo *mainPtr)	/* The application being created. */
 {
-    if (TkWinGetPlatformId() == VER_PLATFORM_WIN32_NT) {
+    if ((TkWinGetPlatformId() == VER_PLATFORM_WIN32_NT)
+	    || (TkWinGetPlatformId() == VER_PLATFORM_WIN32_CE)) {
 	/*
 	 * If running NT, then we will be calling some Unicode functions 
 	 * explictly.  So, even if the Tcl system encoding isn't Unicode, 
@@ -485,12 +489,15 @@
      * EnumFontFamilies because it only exists under NT.
      */
 
-    if (TkWinGetPlatformId() == VER_PLATFORM_WIN32_NT) {
+    if ((TkWinGetPlatformId() == VER_PLATFORM_WIN32_NT)
+	    || (TkWinGetPlatformId() == VER_PLATFORM_WIN32_CE)) {
 	EnumFontFamiliesW(hdc, NULL, (FONTENUMPROCW) WinFontFamilyEnumProc,
 		(LPARAM) interp);
+#ifndef UNDER_CE
     } else {
 	EnumFontFamiliesA(hdc, NULL, (FONTENUMPROCA) WinFontFamilyEnumProc,
 		(LPARAM) interp);
+#endif
     }	    
     ReleaseDC(hwnd, hdc);
 }
@@ -647,10 +654,17 @@
 		familyPtr = lastSubFontPtr->familyPtr;
 		Tcl_UtfToExternalDString(familyPtr->encoding, source, 
 			(int) (p - source), &runString);
+#if USE_OLD_TEXTOUT
 		(*familyPtr->getTextExtentPoint32Proc)(hdc, 
 			Tcl_DStringValue(&runString),
 			Tcl_DStringLength(&runString) >> familyPtr->isWideFont,
 			&size);
+#else
+		GetTextExtentPoint32W(hdc, 
+			(WCHAR *) Tcl_DStringValue(&runString),
+			Tcl_DStringLength(&runString) >> familyPtr->isWideFont,
+			&size);
+#endif
 		curX += size.cx;
 		Tcl_DStringFree(&runString);
                 lastSubFontPtr = thisSubFontPtr;
@@ -663,10 +677,17 @@
 	familyPtr = lastSubFontPtr->familyPtr;
 	Tcl_UtfToExternalDString(familyPtr->encoding, source,
 		(int) (p - source), &runString);
+#if USE_OLD_TEXTOUT
 	(*familyPtr->getTextExtentPoint32Proc)(hdc,
 		Tcl_DStringValue(&runString),
 		Tcl_DStringLength(&runString) >> familyPtr->isWideFont, 
 		&size);
+#else
+	GetTextExtentPoint32W(hdc,
+		(WCHAR *) Tcl_DStringValue(&runString),
+		Tcl_DStringLength(&runString) >> familyPtr->isWideFont,
+		&size);
+#endif
 	curX += size.cx;
 	Tcl_DStringFree(&runString);
 	curByte = numBytes;
@@ -711,8 +732,13 @@
 		Tcl_UtfToExternal(NULL, familyPtr->encoding, p,
 			(int) (next - p), 0, NULL, buf, sizeof(buf), NULL,
 			&dstWrote, NULL);
+#if USE_OLD_TEXTOUT
 		(*familyPtr->getTextExtentPoint32Proc)(hdc, buf, 
 			dstWrote >> familyPtr->isWideFont, &size);
+#else
+		GetTextExtentPoint32W(hdc, (WCHAR *) buf, 
+			dstWrote >> familyPtr->isWideFont, &size);
+#endif
 		newX += size.cx;
 	    }
 	    if (newX > maxLength) {
@@ -854,7 +880,9 @@
 	SetBrushOrgEx(dc, gc->ts_x_origin, gc->ts_y_origin, NULL);
 	oldBrush = SelectObject(dc, stipple);
 
+#ifdef SetTextAlign // not defined for Windows CE as of v3.0
 	SetTextAlign(dcMem, TA_LEFT | TA_BASELINE);
+#endif
 	SetTextColor(dcMem, gc->foreground);
 	SetBkMode(dcMem, TRANSPARENT);
 	SetBkColor(dcMem, RGB(0, 0, 0));
@@ -896,7 +924,9 @@
 	SelectObject(dc, oldBrush);
 	DeleteObject(stipple);
     } else if (gc->function == GXcopy) {
+#ifdef SetTextAlign // not defined for Windows CE as of v3.0
 	SetTextAlign(dc, TA_LEFT | TA_BASELINE);
+#endif
 	SetTextColor(dc, gc->foreground);
 	SetBkMode(dc, TRANSPARENT);
 	MultiFontTextOut(dc, fontPtr, source, numBytes, x, y);
@@ -908,7 +938,9 @@
 
 	dcMem = CreateCompatibleDC(dc);
 
+#ifdef SetTextAlign // not defined for Windows CE as of v3.0
 	SetTextAlign(dcMem, TA_LEFT | TA_BASELINE);
+#endif
 	SetTextColor(dcMem, gc->foreground);
 	SetBkMode(dcMem, TRANSPARENT);
 	SetBkColor(dcMem, RGB(0, 0, 0));
@@ -976,10 +1008,17 @@
     Tcl_DString runString;
     CONST char *p, *end, *next;
     SubFont *lastSubFontPtr, *thisSubFontPtr;
+#ifndef SetTextAlign // not on Windows CE as of 3.0
+    TEXTMETRIC tm;
+#endif
 
     lastSubFontPtr = &fontPtr->subFontArray[0];
     oldFont = SelectObject(hdc, lastSubFontPtr->hFont);
 
+#ifndef SetTextAlign
+    GetTextMetrics(hdc, &tm);
+#endif
+
     end = source + numBytes;
     for (p = source; p < end; ) {
         next = p + Tcl_UtfToUniChar(p, &ch);
@@ -989,19 +1028,43 @@
 		familyPtr = lastSubFontPtr->familyPtr;
  		Tcl_UtfToExternalDString(familyPtr->encoding, source,
 			(int) (p - source), &runString);
-		(*familyPtr->textOutProc)(hdc, x, y, 
+#if USE_OLD_TEXTOUT
+		(*familyPtr->textOutProc)(hdc, x,
+#ifdef SetTextAlign
+			y, 
+#else
+			y - tm.tmAscent,
+#endif
 			Tcl_DStringValue(&runString),
 			Tcl_DStringLength(&runString) >> familyPtr->isWideFont);
 		(*familyPtr->getTextExtentPoint32Proc)(hdc, 
 			Tcl_DStringValue(&runString),
 			Tcl_DStringLength(&runString) >> familyPtr->isWideFont, 
 			&size);
+#else
+		ExtTextOutW(hdc, x,
+#ifdef SetTextAlign
+			y, 
+#else
+			y - tm.tmAscent,
+#endif
+			0, NULL, (WCHAR *) Tcl_DStringValue(&runString),
+			Tcl_DStringLength(&runString) >> familyPtr->isWideFont,
+			NULL);
+		GetTextExtentPoint32W(hdc, 
+			(WCHAR *) Tcl_DStringValue(&runString),
+			Tcl_DStringLength(&runString) >> familyPtr->isWideFont,
+			&size);
+#endif
 		x += size.cx;
 		Tcl_DStringFree(&runString);
 	    }
             lastSubFontPtr = thisSubFontPtr;
             source = p;
 	    SelectObject(hdc, lastSubFontPtr->hFont);
+#ifndef SetTextAlign
+	    GetTextMetrics(hdc, &tm);
+#endif
 	}
 	p = next;
     }
@@ -1009,8 +1072,25 @@
 	familyPtr = lastSubFontPtr->familyPtr;
  	Tcl_UtfToExternalDString(familyPtr->encoding, source,
 		(int) (p - source), &runString);
-	(*familyPtr->textOutProc)(hdc, x, y, Tcl_DStringValue(&runString),
+#if USE_OLD_TEXTOUT
+	(*familyPtr->textOutProc)(hdc, x,
+#ifdef SetTextAlign
+		y, 
+#else
+		y - tm.tmAscent,
+#endif
+		Tcl_DStringValue(&runString),
 		Tcl_DStringLength(&runString) >> familyPtr->isWideFont);
+#else
+	ExtTextOutW(hdc, x,
+#ifdef SetTextAlign
+		y, 
+#else
+		y - tm.tmAscent,
+#endif
+		0, NULL, (WCHAR *) Tcl_DStringValue(&runString),
+		Tcl_DStringLength(&runString) >> familyPtr->isWideFont, NULL);
+#endif
 	Tcl_DStringFree(&runString);
     }
     SelectObject(hdc, oldFont);
@@ -1083,10 +1163,13 @@
      * version of GetTextFace because it only exists under NT.
      */
 
-    if (TkWinGetPlatformId() == VER_PLATFORM_WIN32_NT) {
+    if ((TkWinGetPlatformId() == VER_PLATFORM_WIN32_NT)
+	    || (TkWinGetPlatformId() == VER_PLATFORM_WIN32_CE)) {
 	GetTextFaceW(hdc, LF_FACESIZE, (WCHAR *) buf);
+#ifndef UNDER_CE
     } else {
 	GetTextFaceA(hdc, LF_FACESIZE, (char *) buf);
+#endif
     }
     Tcl_ExternalToUtfDString(systemEncoding, buf, -1, &faceString);
 
@@ -1260,10 +1343,13 @@
             Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
 
     hFont = SelectObject(hdc, hFont);
-    if (TkWinGetPlatformId() == VER_PLATFORM_WIN32_NT) {
+    if ((TkWinGetPlatformId() == VER_PLATFORM_WIN32_NT)
+	    || (TkWinGetPlatformId() == VER_PLATFORM_WIN32_CE)) {
 	GetTextFaceW(hdc, LF_FACESIZE, (WCHAR *) buf);
+#ifndef UNDER_CE
     } else {
 	GetTextFaceA(hdc, LF_FACESIZE, (char *) buf);
+#endif
     }
     Tcl_ExternalToUtfDString(systemEncoding, buf, -1, &faceString);
     faceName = Tk_GetUid(Tcl_DStringValue(&faceString));
@@ -1320,6 +1406,23 @@
 	encoding = Tcl_GetEncoding(NULL, faceName);
     }
 
+#if USE_OLD_TEXTOUT
+#ifdef UNDER_CE
+    if (encoding == NULL) {
+	encoding = Tcl_GetEncoding(NULL, "unicode");
+	familyPtr->textOutProc =
+	    (BOOL (WINAPI *)(HDC, int, int, TCHAR *, int)) XCETextOutW;
+	familyPtr->getTextExtentPoint32Proc = 
+	    (BOOL (WINAPI *)(HDC, TCHAR *, int, LPSIZE)) XCEGetTextExtentPoint32W;
+	familyPtr->isWideFont = 1;
+    } else {
+	familyPtr->textOutProc = 
+	    (BOOL (WINAPI *)(HDC, int, int, TCHAR *, int)) XCETextOutA;
+	familyPtr->getTextExtentPoint32Proc = 
+	    (BOOL (WINAPI *)(HDC, TCHAR *, int, LPSIZE)) XCEGetTextExtentPoint32A;
+	familyPtr->isWideFont = 0;
+    } 
+#else
     if (encoding == NULL) {
 	encoding = Tcl_GetEncoding(NULL, "unicode");
 	familyPtr->textOutProc =
@@ -1334,6 +1437,13 @@
 	    (BOOL (WINAPI *)(HDC, TCHAR *, int, LPSIZE)) GetTextExtentPoint32A;
 	familyPtr->isWideFont = 0;
     } 
+#endif
+#else
+    if (encoding == NULL) {
+	encoding = Tcl_GetEncoding(NULL, "unicode");
+	familyPtr->isWideFont = 1;
+    }
+#endif
 
     familyPtr->encoding = encoding;
 
@@ -1525,12 +1635,15 @@
     canUse.nameTriedPtr = &ds;
     canUse.ch = ch;
     canUse.subFontPtr = NULL;
-    if (TkWinGetPlatformId() == VER_PLATFORM_WIN32_NT) {
+    if ((TkWinGetPlatformId() == VER_PLATFORM_WIN32_NT)
+	    || (TkWinGetPlatformId() == VER_PLATFORM_WIN32_CE)) {
 	EnumFontFamiliesW(hdc, NULL, (FONTENUMPROCW) WinFontCanUseProc,
 		(LPARAM) &canUse);
+#ifndef UNDER_CE
     } else {
 	EnumFontFamiliesA(hdc, NULL, (FONTENUMPROCA) WinFontCanUseProc,
 		(LPARAM) &canUse);
+#endif
     }
     subFontPtr = canUse.subFontPtr;
 
@@ -1979,14 +2092,19 @@
     lf.lfUnderline	= faPtr->underline;
     lf.lfStrikeOut	= faPtr->overstrike;
     lf.lfCharSet	= DEFAULT_CHARSET;
+#ifdef OUT_TT_PRECIS
     lf.lfOutPrecision	= OUT_TT_PRECIS;
+#else // not defined for Windows CE as of v3.0
+    lf.lfOutPrecision	= OUT_DEFAULT_PRECIS;
+#endif
     lf.lfClipPrecision	= CLIP_DEFAULT_PRECIS;
     lf.lfQuality	= DEFAULT_QUALITY;
     lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
 
     Tcl_UtfToExternalDString(systemEncoding, faceName, -1, &ds);
 
-    if (TkWinGetPlatformId() == VER_PLATFORM_WIN32_NT) {
+    if ((TkWinGetPlatformId() == VER_PLATFORM_WIN32_NT)
+	    || (TkWinGetPlatformId() == VER_PLATFORM_WIN32_CE)) {
 	Tcl_UniChar *src, *dst;
 
 	/*
@@ -2002,6 +2120,7 @@
 	}
 	*dst = '\0';
 	hFont = CreateFontIndirectW(&lf);
+#ifndef UNDER_CE
     } else {
 	/*
 	 * We can only store up to LF_FACESIZE characters
@@ -2011,6 +2130,7 @@
 	}
 	strcpy((char *) lf.lfFaceName, Tcl_DStringValue(&ds));
 	hFont = CreateFontIndirectA((LOGFONTA *) &lf);
+#endif
     }
     Tcl_DStringFree(&ds);
     return hFont;
@@ -2069,12 +2189,15 @@
      * non-zero value.
      */
 
-    if (TkWinGetPlatformId() == VER_PLATFORM_WIN32_NT) {
+    if ((TkWinGetPlatformId() == VER_PLATFORM_WIN32_NT)
+	    || (TkWinGetPlatformId() == VER_PLATFORM_WIN32_CE)) {
 	result = EnumFontFamiliesW(hdc, (WCHAR *) Tcl_DStringValue(&faceString),
 		(FONTENUMPROCW) WinFontExistProc, 0);
+#ifndef UNDER_CE
     } else {
 	result = EnumFontFamiliesA(hdc, (char *) Tcl_DStringValue(&faceString),
 		(FONTENUMPROCA) WinFontExistProc, 0);
+#endif
     }
     Tcl_DStringFree(&faceString);
     return (result == 0);
--- ./tkWinImage.c	Thu Oct 10 14:01:18 2002
+++ ../wince/tkWinImage.c	Tue Mar 11 17:39:54 2003
@@ -278,7 +278,7 @@
  *
  *----------------------------------------------------------------------
  */
-
+#ifndef UNDER_CE
 static XImage *
 XGetImageZPixmap(display, d, x, y, width, height, plane_mask, format)
     Display* display;
@@ -502,6 +502,7 @@
 
     return ret_image;
 }
+#endif // UNDER_CE
 
 /*
  *----------------------------------------------------------------------
@@ -577,6 +578,7 @@
 	}
 
 	TkWinReleaseDrawableDC(d, dc, &state);
+#ifndef UNDER_CE
     } else if (format == ZPixmap) {
 	/*
 	 * This actually handles most TWD_WINDOW requests, but it varies
@@ -586,6 +588,7 @@
 	 */
 	imagePtr = XGetImageZPixmap(display, d, x, y,
 		width, height, plane_mask, format);
+#endif
     } else {
 	char *errMsg = NULL;
 	char infoBuf[sizeof(BITMAPINFO) + sizeof(RGBQUAD)];
@@ -598,6 +601,11 @@
 	} else if (plane_mask != 1) {
 	    errMsg = "XGetImage: not implemented for plane_mask != 1";
 	}
+#ifdef UNDER_CE
+	if (errMsg != NULL) {
+	    errMsg = "XGetImage: not implemented on Windows CE";
+	}
+#endif
 	if (errMsg != NULL) {
 	    /*
 	     * Do a soft warning for the unsupported XGetImage types.
@@ -605,7 +613,7 @@
 	    TkpDisplayWarning(errMsg, "XGetImage Failure");
 	    return NULL;
 	}
-
+#ifndef UNDER_CE
 	imagePtr = XCreateImage(display, NULL, 1, XYBitmap, 0, NULL,
 		width, height, 32, 0);
 	imagePtr->data = ckalloc(imagePtr->bytes_per_line * imagePtr->height);
@@ -630,6 +638,7 @@
 	GetDIBits(dc, twdPtr->bitmap.handle, 0, height, imagePtr->data,
 		infoPtr, DIB_RGB_COLORS);
 	ReleaseDC(NULL, dc);
+#endif
     }
 
     return imagePtr;
--- ./tkWinInit.c	Tue Feb 18 11:18:33 2003
+++ ../wince/tkWinInit.c	Tue Mar 11 17:42:24 2003
@@ -13,6 +13,9 @@
  */
 
 #include "tkWinInt.h"
+#ifdef UNDER_CE
+#include "wcemenu.h"
+#endif
 
 /*
  * The Init script (common to Windows and Unix platforms) is
@@ -48,6 +51,9 @@
      * because TkWinXInit flips a static bit to do its work just once.
      */
     TkWinXInit(Tk_GetHINSTANCE());
+#ifdef UNDER_CE
+    WCEInitMenu();
+#endif
     return Tcl_Eval(interp, initScript);
 }
 
--- ./tkWinInt.h	Tue Feb 25 18:47:05 2003
+++ ../wince/tkWinInt.h	Fri Apr  4 13:24:24 2003
@@ -33,6 +33,22 @@
 #include "tkPort.h"
 #endif
 
+#ifdef UNDER_CE
+HBITMAP CreateDIBitmap (HDC  hdc, BITMAPINFOHEADER *lpbmih, DWORD  fdwInit,
+	VOID *lpBits, BITMAPINFO *lpBitsInfo, UINT iUsage);
+BOOL CeArc(HDC hdc,
+	int nLeftRect, int nTopRect, int nRightRect, int nBottomRect,
+	int nXStartArc, int nYStartArc, int nXEndArc, int nYEndArc);
+BOOL CeChord(HDC hdc,
+	int nLeftRect, int nTopRect, int nRightRect, int nBottomRect,
+	int nXRadial1, int nYRadial1, int nXRadial2, int nYRadial2);
+BOOL CePie(HDC hdc,
+	int nLeftRect, int nTopRect, int nRightRect, int nBottomRect,
+	int nXRadial1, int nYRadial1, int nXRadial2, int nYRadial2);
+#define Arc	CeArc
+#define Chord	CeChord
+#define Pie	CePie
+#endif
 
 /*
  * Define constants missing from older Win32 SDK header files.
--- ./tkWinMenu.c	Wed Aug  7 18:42:57 2002
+++ ../wince/tkWinMenu.c	Thu Apr  3 18:22:50 2003
@@ -18,6 +18,10 @@
 
 #include <string.h>
 
+#ifdef UNDER_CE
+#include "wcemenu.h"
+#endif
+
 /*
  * The class of the window for popup menus.
  */
@@ -532,6 +536,9 @@
     int i, count, systemMenu = 0, base;
     int width, height;
     Tcl_DString translatedText;
+#ifdef UNDER_CE
+    WCHAR wbuf[256];
+#endif
   
     if (NULL == winMenuHdl) {
     	return;
@@ -550,7 +557,11 @@
     }
 
     base = (menuPtr->menuFlags & MENU_SYSTEM_MENU) ? 7 : 0;
+#ifdef UNDER_CE
+    count = WCEGetMenuItemCount(winMenuHdl);
+#else
     count = GetMenuItemCount(winMenuHdl);
+#endif
     for (i = base; i < count; i++) {
 	RemoveMenu(winMenuHdl, base, MF_BYPOSITION);
     }
@@ -572,6 +583,10 @@
 		|| (menuPtr->menuFlags & MENU_SYSTEM_MENU)) {
 	    Tcl_UtfToExternalDString(NULL, itemText, -1, &translatedText);
 	    lpNewItem = Tcl_DStringValue(&translatedText);
+#ifdef UNDER_CE
+	    MultiByteToWideChar(CP_ACP, 0, lpNewItem, -1, wbuf, 126);
+	    lpNewItem = (const TCHAR *) wbuf;
+#endif
 	} else {
 	    lpNewItem = (LPCTSTR) mePtr;
 	    flags |= MF_OWNERDRAW;
@@ -681,7 +696,11 @@
 
     if ((menuPtr->menuType == MENUBAR) 
 	    && (menuPtr->parentTopLevelPtr != NULL)) {
+#ifdef UNDER_CE
+	WCEDrawMenuBar(TkWinGetWrapperWindow(menuPtr->parentTopLevelPtr));
+#else
 	DrawMenuBar(TkWinGetWrapperWindow(menuPtr->parentTopLevelPtr));
+#endif
 	Tk_GeometryRequest(menuPtr->parentTopLevelPtr, width, height);
     }
     
@@ -765,6 +784,7 @@
      */
 
     flags = TPM_LEFTALIGN;
+#ifdef SM_SWAPBUTTON // not defined for Windows CE as of v3.0
     if (GetSystemMetrics(SM_SWAPBUTTON)) {
 	if (GetAsyncKeyState(VK_LBUTTON) < 0) {
 	    flags |= TPM_RIGHTBUTTON;
@@ -778,6 +798,7 @@
 	    flags |= TPM_LEFTBUTTON;
 	}
     }
+#endif
 
     TrackPopupMenu(winMenuHdl, flags, x, y, 0, 
 	    tsdPtr->menuHWND, &noGoawayRect);
@@ -900,6 +921,7 @@
             Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
 
     switch (*pMessage) {
+#ifdef WM_INITMENU // not defined for Windows CE as of v3.0
 	case WM_INITMENU:
 	    TkMenuInit();
 	    hashEntryPtr = Tcl_FindHashEntry(&tsdPtr->winMenuTable, 
@@ -935,6 +957,7 @@
 		tsdPtr->modalMenuPtr = NULL;
 	    }
 	    break;
+#endif
 
 	case WM_SYSCOMMAND:
 	case WM_COMMAND: {
@@ -1108,6 +1131,7 @@
 	    break;
 	}
 
+#ifdef WM_MENUSELECT // not defined for Windows CE as of v3.0
 	case WM_MENUSELECT: {
 	    UINT flags = HIWORD(*pwParam);
 
@@ -1155,6 +1179,7 @@
 	    }
 	    break;
 	}
+#endif
     }
     return returnResult;
 }
@@ -1233,7 +1258,11 @@
 	hashEntryPtr = Tcl_FindHashEntry(&tsdPtr->winMenuTable, 
                 (char *) winMenuHdl);
 	Tcl_DeleteHashEntry(hashEntryPtr);
+#ifndef UNDER_CE
+	// The main window handle must not be destroyed (wince)!
+	XCETrace("DestroyMenu(%x)", winMenuHdl);
 	DestroyMenu(winMenuHdl);
+#endif
 	winMenuHdl = CreateMenu();
 	hashEntryPtr = Tcl_CreateHashEntry(&tsdPtr->winMenuTable, 
                 (char *) winMenuHdl, &newEntry);
@@ -1443,6 +1472,9 @@
     int alignFlags;			/* How to align the bitmap inside the
 					 * rectangle. */
 {
+#ifdef UNDER_CE
+    return;
+#else
     TkWinDCState state;
     HDC hdc = TkWinGetDrawableDC(display, drawable, &state);
     HDC scratchDC;
@@ -1490,6 +1522,7 @@
     DeleteObject(bitmap);
 
     TkWinReleaseDrawableDC(drawable, hdc, &state);
+#endif // UNDER_CE
 }
 
 /*
@@ -1523,6 +1556,9 @@
     int width;
     int height;
 {
+#ifdef UNDER_CE
+    return;
+#else
     if ((mePtr->type == CHECK_BUTTON_ENTRY) 
 	    || (mePtr->type == RADIO_BUTTON_ENTRY)) {
     	if (mePtr->indicatorOn && (mePtr->entryFlags & ENTRY_SELECTED)) {
@@ -1563,6 +1599,7 @@
 		    OBM_CHECK, 0);
 	}
     }    
+#endif // UNDER_CE
 }
 
 /*
@@ -1603,6 +1640,9 @@
 					 * out Windows' algorithm for where
 					 * to draw this. */
 {
+#ifdef UNDER_CE
+    return;
+#else
     int baseline;
     int leftEdge = x + mePtr->indicatorSpace + mePtr->labelWidth;
     char *accel;
@@ -1652,6 +1692,7 @@
 	DrawWindowsSystemBitmap(menuPtr->display, d, gc, &rect, OBM_MNARROW, 
 		ALIGN_BITMAP_RIGHT);
     }
+#endif // UNDER_CE
 }
 
 /*
@@ -2790,7 +2831,9 @@
     TEXTMETRIC tm;
     int pointSize;
     HFONT menuFont;
+#ifndef UNDER_CE
     NONCLIENTMETRICS ncMetrics;
+#endif
 
     /*
      * Set all of the default options. The loop will terminate when we run 
@@ -2808,10 +2851,14 @@
     }
     Tcl_DStringInit(&menuFontDString);
 
+#ifdef UNDER_CE
+    menuFont = GetStockObject(SYSTEM_FONT);
+#else
     ncMetrics.cbSize = sizeof(ncMetrics);
     SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(ncMetrics),
 	    &ncMetrics, 0);
     menuFont = CreateFontIndirect(&ncMetrics.lfMenuFont);
+#endif
     SelectObject(scratchDC, menuFont);
     GetTextMetrics(scratchDC, &tm);
     GetTextFace(scratchDC, LF_FACESIZE, faceName);
@@ -2855,6 +2902,10 @@
      * documented.
      */
 
+#ifdef UNDER_CE
+    indicatorDimensions[0] = 10;
+    indicatorDimensions[1] = 10;
+#else
     if (TkWinGetPlatformId() >= VER_PLATFORM_WIN32_WINDOWS) {
 	indicatorDimensions[0] = GetSystemMetrics(SM_CYMENUCHECK);
 	indicatorDimensions[1] = ((GetSystemMetrics(SM_CXFIXEDFRAME) +
@@ -2866,6 +2917,7 @@
 	indicatorDimensions[0] = HIWORD(dimensions);
 	indicatorDimensions[1] = LOWORD(dimensions);
    }
+#endif // UNDER_CE
 }
 
 /*
@@ -2891,7 +2943,11 @@
     ThreadSpecificData *tsdPtr = (ThreadSpecificData *) 
             Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
 
+#ifdef UNDER_CE
+    wndClass.style = CS_HREDRAW | CS_VREDRAW;
+#else
     wndClass.style = CS_OWNDC;
+#endif
     wndClass.lpfnWndProc = TkWinMenuProc;
     wndClass.cbClsExtra = 0;
     wndClass.cbWndExtra = 0;
@@ -2935,3 +2991,341 @@
     Tcl_InitHashTable(&tsdPtr->winMenuTable, TCL_ONE_WORD_KEYS);
     Tcl_InitHashTable(&tsdPtr->commandTable, TCL_ONE_WORD_KEYS);
 }
+
+#ifdef UNDER_CE
+// Dynamic menues in WinCE are a pain!
+//
+// Seems that toplevel SHMenu-Texts cannot be dynamically changed...
+// And the menu cannot be dynamically expanded. And there were other
+// problems...
+//
+// We work-around by using only one top-level popup, which is returned
+// as the menu handle. It's not very nice, but makes life easier.
+//
+// How to use:
+// Call CreateMenu() to create a menu
+// Call WCECreateMenu() to create the menubar.
+// Call WCESetMenu to copy items from the first menu to the menubar
+// Call WCEDrawMenuBar to copy items from the first menu to the menubar
+// after changes.
+//
+// Be careful when calling DestroyMenu().
+
+#if 0
+#include <windows.h>
+#include "celib.h"
+#include "wcemenu.h"
+#endif
+#include <commctrl.h>
+
+#define WCE_MAXMENUES 10
+
+WCE_MENU_INFO *menu_tab[WCE_MAXMENUES];
+
+static BOOL has_ayg;
+static FARPROC pfn_SHCreateMenuBar;
+
+BOOL 
+WCEInitMenu()
+{
+    HMODULE hMod;
+
+    if ((hMod = LoadLibraryW(L"aygshell.dll"))) {
+	if ((pfn_SHCreateMenuBar = GetProcAddressW(hMod, L"SHCreateMenuBar")))
+	    has_ayg = TRUE;
+    }
+
+    return TRUE;
+}
+
+BOOL 
+WCEIsMenuAYG()
+{
+    return has_ayg;
+}
+
+BOOL
+WCEAddMenuInfo(WCE_MENU_INFO *p)
+{
+    int i;
+
+    for(i = 0; i < WCE_MAXMENUES; i++) {
+	if(menu_tab[i] == NULL) {
+	    menu_tab[i] = p;
+	    return TRUE;
+	}
+    }
+    return FALSE;
+}
+
+WCE_MENU_INFO *
+WCEFindMenuInfoByHwnd(HWND hwnd)
+{
+    int i;
+
+    for(i = 0; i < WCE_MAXMENUES; i++) {
+	if(menu_tab[i] == NULL)
+	    break;
+	if(menu_tab[i]->hwndParent == hwnd)
+	    return menu_tab[i];
+    }
+    return NULL;
+}
+
+WCE_MENU_INFO *
+WCEFindMenuInfoByHmenu(HMENU hMenu)
+{
+    int i;
+
+    for(i = 0; i < WCE_MAXMENUES; i++) {
+	if(menu_tab[i] == NULL)
+	    break;
+	if(menu_tab[i]->hMenu == hMenu)
+	    return menu_tab[i];
+    }
+    return NULL;
+}
+
+HMENU
+WCECreateMenu(WCE_MENU_INFO *pInfo)
+{
+    HMENU hMenu;
+
+    XCETrace("MENU: WCECreateMenu");
+
+    if(has_ayg) {
+	SHMENUBARINFO mbi;
+
+	memset(&mbi, 0, sizeof(SHMENUBARINFO));
+	mbi.cbSize     = sizeof(SHMENUBARINFO);
+	mbi.dwFlags    = 0;
+	mbi.hwndParent = pInfo->hwndParent;
+	mbi.nToolBarId = pInfo->resid;
+	mbi.hInstRes   = pInfo->hInst;
+	mbi.nBmpId     = 0;
+	mbi.cBmpImages = 0;	
+
+	if((*pfn_SHCreateMenuBar)(&mbi) == FALSE)
+	    return NULL;
+
+	if(mbi.hwndMB == NULL)
+	    return NULL;
+
+	pInfo->hwndBar = mbi.hwndMB;
+
+	hMenu = SH_GetMenu(pInfo->hwndBar);
+	hMenu = CreatePopupMenu();
+	SH_SetSubMenu(pInfo->hwndBar, 0, hMenu);
+	pInfo->hMenu = SH_GetSubMenu(pInfo->hwndBar, 0);
+    } else {
+	pInfo->hwndBar = CommandBar_Create(pInfo->hInst, pInfo->hwndParent, 1); 
+	CommandBar_InsertMenubar(pInfo->hwndBar, pInfo->hInst, pInfo->resid, 0);
+	// Button does not resize!
+	//CommandBar_AddAdornments(pInfo->hwndBar, 0, 0);
+
+	pInfo->hMenu = Menu_GetMenu(pInfo->hwndBar);
+    }
+
+    // remove dummy entry
+    DeleteMenu(pInfo->hMenu, 0, MF_BYPOSITION);
+
+    WCEAddMenuInfo(pInfo);
+
+    return pInfo->hMenu;
+}
+
+// Emulates SetMenu
+
+BOOL
+WCESetMenu(HWND hwnd, HMENU hMenu)
+{
+    WCE_MENU_INFO *pInfo;
+
+    XCETrace("MENU: WCESetMenu");
+
+    if((pInfo = WCEFindMenuInfoByHwnd(hwnd)) == NULL) {
+	return FALSE;
+    }
+
+    pInfo->hMenuOrig = hMenu;
+
+    WCECopyMenu(pInfo->hMenuOrig, pInfo->hMenu);
+
+    return TRUE;
+}
+
+// Emulate GetMenu()
+
+HMENU
+WCEGetMenu(HWND hwnd)
+{
+    WCE_MENU_INFO *pInfo;
+
+    XCETrace("MENU: WCEGetMenu");
+
+    if((pInfo = WCEFindMenuInfoByHwnd(hwnd)) == NULL)
+	return NULL;
+
+    return pInfo->hMenuOrig;
+}
+
+HMENU
+WCEGetRealMenu(HWND hwnd)
+{
+    WCE_MENU_INFO *pInfo;
+
+    XCETrace("MENU: WCEGetMenu");
+
+    if((pInfo = WCEFindMenuInfoByHwnd(hwnd)) == NULL)
+	return NULL;
+
+    return pInfo->hMenu;
+}
+
+int
+WCEGetMenuHeight(HWND hwnd)
+{
+    WCE_MENU_INFO *pInfo;
+    RECT r;
+
+    if((pInfo = WCEFindMenuInfoByHwnd(hwnd)) == NULL)
+	return -1;
+
+    GetClientRect(pInfo->hwndBar, &r);
+
+    return r.bottom;
+}
+
+HWND
+WCEGetMenuWindow(HWND hwnd)
+{
+    WCE_MENU_INFO *pInfo;
+
+    if((pInfo = WCEFindMenuInfoByHwnd(hwnd)) == NULL)
+	return NULL;
+
+    return pInfo->hwndBar;
+}
+
+int
+WCEGetMenuItemCount(HMENU hMenu)
+{
+    int i;
+    MENUITEMINFOW mi;
+    WCHAR text[126];
+
+    XCETrace("MENU: GetMenuItemCount(%x)", hMenu);
+
+    for(i = 0;; i++) {
+	memset(&mi, 0, sizeof(mi));
+	mi.cbSize = sizeof(mi);
+	mi.fMask = MIIM_DATA|MIIM_TYPE;
+	mi.dwTypeData = (WCHAR*) text;
+	mi.cch = sizeof(text)/2;
+
+	text[0] = 0;
+
+	SetLastError(0);
+
+	if(!GetMenuItemInfoW(hMenu, i, TRUE, &mi)) {
+	    XCETrace("MENU: GetMenuItemInfo(%d): %d", i, GetLastError());
+	    break;
+	} else {
+	    XCETrace("MENU: Menu %x, item %d: Data %ls Type %x", 
+		    hMenu, i, text, mi.fType);
+	}
+    }
+
+    return i;
+}
+
+BOOL
+WCEDrawMenuBar(HWND hwnd)
+{
+    WCE_MENU_INFO *pInfo;
+    RECT r;
+
+    XCETrace("MENU: WCEDrawMenuBar");
+
+    if((pInfo = WCEFindMenuInfoByHwnd(hwnd)) == NULL) {
+	return FALSE;
+    }
+
+    if (pInfo->hMenuOrig == NULL) {
+	XCETrace("MENU: No original menu");
+	return TRUE;
+    }
+
+    WCECopyMenu(pInfo->hMenuOrig, pInfo->hMenu);
+
+    // Force an update. Else the menu might not popup...
+    // How can this be done better?
+    GetWindowRect(pInfo->hwndBar, &r);
+
+    // This generates a WM_NOTIFY with NM_CUSTOMDRAW (-12)
+    // Seems this is needed to update the menubar...
+    MoveWindow(pInfo->hwndBar, r.left+1, r.top+1, r.right - r.left, 
+	    r.bottom - r.top, TRUE);
+    MoveWindow(pInfo->hwndBar, r.left, r.top, r.right - r.left, 
+	    r.bottom - r.top, TRUE);
+
+    return TRUE;
+}
+
+BOOL
+WCECopyMenu(HMENU hsrc, HMENU hdest)
+{
+    int i = 0;
+    int n;
+    HMENU hMenuTmp;
+
+    n = WCEGetMenuItemCount(hdest);
+
+    XCETrace("MENU: Removing %d items in dest menu %x", n, hdest);
+
+    for (i = 0; i < n; i++) {
+	// delete destroys the menu, but we need it...
+	//DeleteMenu(hdest, 0, MF_BYPOSITION);
+	RemoveMenu(hdest, 0, MF_BYPOSITION);
+    }
+
+    n = WCEGetMenuItemCount(hsrc);
+
+    XCETrace("MENU: Copying %d items from menu %x to menu %x", n, hsrc, hdest);
+
+    for(i = 0; i < n; i++) {
+	SetLastError(0);
+
+	if((hMenuTmp = GetSubMenu(hsrc, i)) != NULL) {
+	    MENUITEMINFOW mi;
+	    WCHAR text[126];
+
+	    memset(&mi, 0, sizeof(mi));
+	    mi.cbSize = sizeof(mi);
+	    mi.fMask = MIIM_DATA|MIIM_TYPE;
+	    mi.dwTypeData = (WCHAR*) text;
+	    mi.cch = sizeof(text)/2;
+
+	    SetLastError(0);
+
+	    if(!GetMenuItemInfoW(hsrc, i, TRUE, &mi)) {
+		XCETrace("MENU: GetMenuItemInfo(%x, %d): Error %d", 
+			hsrc, i, GetLastError());
+	    } else {
+		int nsub = WCEGetMenuItemCount(hMenuTmp);
+
+		XCETrace("MENU: Appending popup %x (%ls) with %d entries to %x", 
+			hMenuTmp, text, nsub, hdest);
+	      
+		AppendMenuW(hdest, MF_POPUP, (UINT) hMenuTmp, text);
+	    }
+	} else {
+	    XCETrace("MENU: GetSubMenu(%x, %d): Error %d", 
+		    hsrc, i, GetLastError());
+	    return FALSE;
+	}
+    }
+
+    return TRUE;
+}
+#endif // UNDER_CE
--- ./tkWinPixmap.c	Tue Feb  1 03:41:44 2000
+++ ../wince/tkWinPixmap.c	Thu Apr  3 11:17:42 2003
@@ -165,6 +165,9 @@
     TkWinDrawable *twdPtr = (TkWinDrawable *)d;
 
     if (twdPtr->type == TWD_BITMAP) {
+#ifdef UNDER_CE
+        panic("XGetGeometry: cannot handle pixmap");
+#else
 	HDC dc;
 	BITMAPINFO info;
 
@@ -182,6 +185,7 @@
 
         *width_return = info.bmiHeader.biWidth;
         *height_return = info.bmiHeader.biHeight;
+#endif
     } else if (twdPtr->type == TWD_WINDOW) {
 	RECT rect;
 
--- ./tkWinPort.h	Fri Oct 18 19:10:20 2002
+++ ../wince/tkWinPort.h	Tue Mar 11 22:07:09 2003
@@ -53,8 +53,16 @@
 #endif /* _MSC_VER */
 
 #ifndef __GNUC__
+#  ifndef strncasecmp
 #    define strncasecmp strnicmp
+#  endif
+#  ifndef strcasecmp
 #    define strcasecmp stricmp
+#  endif
+#endif
+
+#ifdef UNDER_CE
+#undef time
 #endif
 
 #define NBBY 8
--- ./tkWinWm.c	Sat Dec  7 16:32:20 2002
+++ ../wince/tkWinWm.c	Thu Apr  3 18:25:46 2003
@@ -18,6 +18,14 @@
 #include "tkWinInt.h"
 #include <shellapi.h>
 
+#ifdef UNDER_CE
+#include "wcemenu.h"
+void wince_putwinhandles(HWND hWndOld, HWND hWndNew);
+HWND wince_getwinhandle(HWND hWndOld);
+#define ID_MAINMENU   100
+TkWindow *WinCERecreateChild(TkWindow *winPtr, HWND hWrapper, DWORD dwStyle);
+#endif
+
 /*
  * Event structure for synthetic activation events.  These events are
  * placed on the event queue whenever a toplevel gets a WM_MOUSEACTIVATE
@@ -426,8 +434,6 @@
 						       Pixmap pixmap));
 static int     		ReadICOHeader _ANSI_ARGS_((Tcl_Channel channel));
 static BOOL 		AdjustIconImagePointers _ANSI_ARGS_((LPICONIMAGE lpImage));
-static HICON 		MakeIconOrCursorFromResource 
-                            _ANSI_ARGS_((LPICONIMAGE lpIcon, BOOL isIcon));
 static HICON 		GetIcon _ANSI_ARGS_((WinIconPtr titlebaricon, 
 			    int icon_size));
 static int 		WinSetIcon _ANSI_ARGS_((Tcl_Interp *interp,
@@ -559,8 +565,7 @@
 
     wBitCount = ((LPBITMAPINFOHEADER) lpbi)->biBitCount;
 
-    switch (wBitCount)
-    {
+    switch (wBitCount) {
 	case 1: return 2;
 	case 4: return 16;
 	case 8:	return 256;
@@ -655,7 +660,7 @@
  *----------------------------------------------------------------------
  */
 static BOOL 
-AdjustIconImagePointers( LPICONIMAGE lpImage )
+AdjustIconImagePointers(LPICONIMAGE lpImage)
 {
     /*  Sanity check */
     if (lpImage==NULL)
@@ -683,60 +688,6 @@
 /*
  *----------------------------------------------------------------------
  *
- * MakeIconOrCursorFromResource --
- *
- *	Construct an actual HICON structure from the information
- *	in a resource.
- *
- * Results:
- *
- *
- * Side effects:
- *
- *
- *----------------------------------------------------------------------
- */
-static HICON 
-MakeIconOrCursorFromResource(LPICONIMAGE lpIcon, BOOL isIcon) {
-    HICON hIcon ;
-    static FARPROC pfnCreateIconFromResourceEx=NULL;
-    static int initinfo=0;
-    /*  Sanity Check */
-    if (lpIcon == NULL)
-	return NULL;
-    if (lpIcon->lpBits == NULL)
-	return NULL;
-    if (!initinfo) {
-	HMODULE hMod = GetModuleHandleA("USER32.DLL");
-	initinfo=1;
-	if (hMod){
-	    pfnCreateIconFromResourceEx = 
-	      GetProcAddress(hMod, "CreateIconFromResourceEx");
-	}
-    }
-    /*  Let the OS do the real work :) */
-    if (pfnCreateIconFromResourceEx!=NULL) {
-	hIcon = (HICON) (pfnCreateIconFromResourceEx)
-	(lpIcon->lpBits, lpIcon->dwNumBytes, isIcon, 0x00030000,
-	 (*(LPBITMAPINFOHEADER)(lpIcon->lpBits)).biWidth,
-	 (*(LPBITMAPINFOHEADER)(lpIcon->lpBits)).biHeight/2, 0);
-    } else {
-	 hIcon = NULL;
-    }
-    /*  It failed, odds are good we're on NT so try the non-Ex way */
-    if (hIcon == NULL)    {
-	/*  We would break on NT if we try with a 16bpp image */
-	if (lpIcon->lpbi->bmiHeader.biBitCount != 16) {
-	    hIcon = CreateIconFromResource(lpIcon->lpBits, lpIcon->dwNumBytes, 
-					   isIcon, 0x00030000);
-	}
-    }
-    return hIcon;
-}
-
-/*
- *----------------------------------------------------------------------
- *
  * ReadICOHeader --
  *
  *	Reads the header from an ICO file, as specfied by channel.
@@ -845,6 +796,9 @@
 	    class.style = CS_HREDRAW | CS_VREDRAW | CS_CLASSDC;
 #endif
 	    class.hInstance = Tk_GetHINSTANCE();
+#ifdef UNDER_CE
+	    class.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
+#endif
 	    Tcl_WinUtfToTChar(TK_WIN_TOPLEVEL_CLASS_NAME, -1, &classString);
 	    class.lpszClassName = (LPCTSTR) Tcl_DStringValue(&classString);
 	    class.lpfnWndProc = WmProc;
@@ -970,6 +924,7 @@
 	    }
 	} else {
 	    ThreadSpecificData *tsdPtr;
+#ifndef UNDER_CE
 	    if (
 #ifdef _WIN64
 		!SetClassLongPtr(hwnd, GCLP_HICONSM,
@@ -991,6 +946,7 @@
 		 * return TCL_ERROR;
 		 */
 	    }
+#endif
 	    if (
 #ifdef _WIN64
 		!SetClassLongPtr(hwnd, GCLP_HICON,
@@ -1367,7 +1323,11 @@
 }
 
 static HCURSOR 
-TclWinReadCursorFromFile(Tcl_Interp* interp, Tcl_Obj* fileName) {
+TclWinReadCursorFromFile(Tcl_Interp* interp, Tcl_Obj* fileName)
+{
+#ifdef UNDER_CE
+    return NULL;
+#else
     BlockOfIconImagesPtr lpIR;
     HICON res = NULL;
     
@@ -1380,6 +1340,7 @@
     }
     FreeIconBlock(lpIR);
     return res;
+#endif
 }
 
 /*
@@ -1400,123 +1361,123 @@
  *----------------------------------------------------------------------
  */
 static BlockOfIconImagesPtr 
-ReadIconOrCursorFromFile(Tcl_Interp* interp, Tcl_Obj* fileName, BOOL isIcon) {
-    BlockOfIconImagesPtr lpIR, lpNew;
+ReadIconOrCursorFromFile(Tcl_Interp* interp, Tcl_Obj* fileName, BOOL isIcon)
+{
+#ifdef UNDER_CE
+    Tcl_AppendResult(interp, "Error opening file \"", 
+	    Tcl_GetString(fileName), "\" for reading", (char*) NULL);
+    return NULL;
+#else
+    BlockOfIconImagesPtr lpNew, lpIR = NULL;
     Tcl_Channel          channel;
     int                  i;
     DWORD            	 dwBytesRead;
     LPICONDIRENTRY    	 lpIDE;
+    LPICONIMAGE	         lpIcon;
+    char *errMsg = NULL;
 
     /*  Open the file */
     channel = Tcl_FSOpenFileChannel(interp, fileName, "r", 0);
     if (channel == NULL) {
-	Tcl_AppendResult(interp,"Error opening file \"", 
-			 Tcl_GetString(fileName), 
-	                 "\" for reading",(char*)NULL);
+	Tcl_AppendResult(interp, "Error opening file \"", 
+		Tcl_GetString(fileName), "\" for reading", (char*) NULL);
 	return NULL;
     }
-    if (Tcl_SetChannelOption(interp, channel, "-translation", "binary")
-	    != TCL_OK) {
-	Tcl_Close(NULL, channel);
-	return NULL;
-    }
-    if (Tcl_SetChannelOption(interp, channel, "-encoding", "binary")
-	    != TCL_OK) {
+    if ((Tcl_SetChannelOption(interp, channel, "-translation", "binary")
+	    != TCL_OK) || (Tcl_SetChannelOption(interp, channel,
+		    "-encoding", "binary") != TCL_OK)) {
 	Tcl_Close(NULL, channel);
 	return NULL;
     }
     /*  Allocate memory for the resource structure */
     lpIR = (BlockOfIconImagesPtr) ckalloc(sizeof(BlockOfIconImages));
     if (lpIR == NULL)    {
-	Tcl_AppendResult(interp,"Error allocating memory",(char*)NULL);
-	Tcl_Close(NULL, channel);
-	return NULL;
+	errMsg = "Error allocating memory";
+	goto error;
     }
     /*  Read in the header */
-    if ((lpIR->nNumImages = ReadICOHeader( channel )) == -1)    {
-	Tcl_AppendResult(interp,"Invalid file header",(char*)NULL);
-	Tcl_Close(NULL, channel);
-	ckfree((char*) lpIR );
-	return NULL;
+    if ((lpIR->nNumImages = ReadICOHeader(channel)) == -1) {
+	errMsg = "Invalid file header";
+	goto error;
     }
     /*  Adjust the size of the struct to account for the images */
     lpNew = (BlockOfIconImagesPtr) ckrealloc((char*)lpIR, 
-	sizeof(BlockOfIconImages) + ((lpIR->nNumImages-1) * sizeof(ICONIMAGE)));
+	    sizeof(BlockOfIconImages)
+	    + ((lpIR->nNumImages-1) * sizeof(ICONIMAGE)));
     if (lpNew == NULL) {
-	Tcl_AppendResult(interp,"Error allocating memory",(char*)NULL);
-	Tcl_Close(NULL, channel);
-	ckfree( (char*)lpIR );
-	return NULL;
+	errMsg = "Error allocating memory";
+	goto error;
     }
     lpIR = lpNew;
     /*  Allocate enough memory for the icon directory entries */
     lpIDE = (LPICONDIRENTRY) ckalloc(lpIR->nNumImages * sizeof(ICONDIRENTRY));
     if (lpIDE == NULL) {
-	Tcl_AppendResult(interp,"Error allocating memory",(char*)NULL);
-	Tcl_Close(NULL, channel);
-	ckfree( (char*)lpIR );
-	return NULL;
+	errMsg = "Error allocating memory";
+	goto error;
     }
     /*  Read in the icon directory entries */
-    dwBytesRead = Tcl_Read(channel, (char*)lpIDE, 
-			   lpIR->nNumImages * sizeof( ICONDIRENTRY ));
-    if (dwBytesRead != lpIR->nNumImages * sizeof( ICONDIRENTRY ))    {
-	Tcl_AppendResult(interp,"Error reading file",(char*)NULL);
-	Tcl_Close(NULL, channel);
-	ckfree( (char*)lpIR );
-	return NULL;
+    dwBytesRead = Tcl_Read(channel, (char*) lpIDE, 
+	    lpIR->nNumImages * sizeof(ICONDIRENTRY));
+    if (dwBytesRead != (lpIR->nNumImages * sizeof(ICONDIRENTRY))) {
+	errMsg = "Error reading file";
+	goto error;
     }
     /*  Loop through and read in each image */
-    for( i = 0; i < lpIR->nNumImages; i++ )    {
+    for (i = 0; i < lpIR->nNumImages; i++) {
 	/*  Allocate memory for the resource */
 	lpIR->IconImages[i].lpBits = (LPBYTE) ckalloc(lpIDE[i].dwBytesInRes);
 	if (lpIR->IconImages[i].lpBits == NULL) {
-	    Tcl_AppendResult(interp,"Error allocating memory",(char*)NULL);
-	    Tcl_Close(NULL, channel);
-	    ckfree( (char*)lpIR );
-	    ckfree( (char*)lpIDE );
-	    return NULL;
+	    ckfree((char*) lpIDE);
+	    errMsg = "Error allocating memory";
+	    goto error;
 	}
 	lpIR->IconImages[i].dwNumBytes = lpIDE[i].dwBytesInRes;
 	/*  Seek to beginning of this image */
 	if (Tcl_Seek(channel, lpIDE[i].dwImageOffset, FILE_BEGIN) == -1) {
-	    Tcl_AppendResult(interp,"Error seeking in file",(char*)NULL);
-	    Tcl_Close(NULL, channel);
-	    ckfree( (char*)lpIR );
-	    ckfree( (char*)lpIDE );
-	    return NULL;
+	    ckfree((char*) lpIDE);
+	    errMsg = "Error seeking in file";
+	    goto error;
 	}
 	/*  Read it in */
-	dwBytesRead = Tcl_Read( channel, lpIR->IconImages[i].lpBits, 
+	dwBytesRead = Tcl_Read(channel, lpIR->IconImages[i].lpBits, 
 			       lpIDE[i].dwBytesInRes);
 	if (dwBytesRead != lpIDE[i].dwBytesInRes) {
-	    Tcl_AppendResult(interp,"Error reading file",(char*)NULL);
-	    Tcl_Close(NULL, channel);
-	    ckfree( (char*)lpIDE );
-	    ckfree( (char*)lpIR );
-	    return NULL;
+	    ckfree((char*) lpIDE);
+	    errMsg = "Error reading file";
+	    goto error;
 	}
+	lpIcon = &(lpIR->IconImages[i]);
 	/*  Set the internal pointers appropriately */
-	if (!AdjustIconImagePointers( &(lpIR->IconImages[i]))) {
-	    Tcl_AppendResult(interp,"Error converting to internal format",
-			     (char*)NULL);
-	    Tcl_Close(NULL, channel);
-	    ckfree( (char*)lpIDE );
-	    ckfree( (char*)lpIR );
-	    return NULL;
+	if (!AdjustIconImagePointers(lpIcon)) {
+	    ckfree((char*) lpIDE);
+	    errMsg = "Error converting to internal format";
+	    goto error;
 	}
 	lpIR->IconImages[i].hIcon =
-	    MakeIconOrCursorFromResource(&(lpIR->IconImages[i]), isIcon);
+	    CreateIconFromResourceEx(lpIcon->lpBits,
+		    lpIcon->dwNumBytes, isIcon, 0x00030000,
+		    (*(LPBITMAPINFOHEADER)(lpIcon->lpBits)).biWidth,
+		    (*(LPBITMAPINFOHEADER)(lpIcon->lpBits)).biHeight/2, 0);
     }
     /*  Clean up */
-    ckfree((char*)lpIDE);
+    ckfree((char*) lpIDE);
     Tcl_Close(NULL, channel);
-    if (lpIR == NULL){
-	Tcl_AppendResult(interp,"Reading of ", Tcl_GetString(fileName),
-	" failed!",(char*)NULL);
-	return NULL;
+    if (lpIR == NULL) {
+	Tcl_AppendResult(interp, "Reading of ", Tcl_GetString(fileName),
+		" failed!", (char*) NULL);
     }
     return lpIR;
+
+    error:
+    if (errMsg) {
+	Tcl_AppendResult(interp, errMsg, (char*) NULL);
+    }
+    Tcl_Close(NULL, channel);
+    if (lpIR) {
+	ckfree((char*) lpIR);
+    }
+    return NULL;
+#endif // UNDER_CE
 }
 
 /*
@@ -1985,7 +1946,11 @@
 	 * isn't destroyed.
 	 */
 
+#ifdef UNDER_CE
+	XCETrace("WM: WARN: Should save old menu");
+#else
 	SetMenu(oldWrapper, NULL);
+#endif
 	DestroyWindow(oldWrapper);
     }
 
@@ -2026,8 +1991,28 @@
      */
 
     if (wmPtr->hMenu != NULL) {
+#ifdef UNDER_CE
+      WCE_MENU_INFO *pminfo;
+      HMENU hMainMenu;
+#endif
 	wmPtr->flags = WM_SYNC_PENDING;
+#ifdef UNDER_CE
+	XCETrace("WM: SetMenu in UpdateWrapper()");
+
+	pminfo = (WCE_MENU_INFO *) ckalloc(sizeof(*pminfo));
+	memset(pminfo, 0, sizeof(*pminfo));
+	pminfo->type       = 0;
+	pminfo->resid      = ID_MAINMENU;
+	pminfo->hwndParent = wmPtr->wrapper;
+	pminfo->hInst      = Tk_GetHINSTANCE();
+	XCETrace("WM: Creating new menu for hwnd 0x%x", wmPtr->wrapper);
+	// WmProc: msg = 55 = WM_NOTIFYFORMAT?!
+	hMainMenu = WCECreateMenu(pminfo);
+	XCETrace("WM: New Menu is 0x%x", hMainMenu);
+	WCESetMenu(wmPtr->wrapper, wmPtr->hMenu);
+#else
 	SetMenu(wmPtr->wrapper, wmPtr->hMenu);
+#endif
 	wmPtr->flags &= ~WM_SYNC_PENDING;
     }
 
@@ -2060,7 +2045,15 @@
 
     if (tsdPtr->firstWindow) {
 	tsdPtr->firstWindow = 0;
+#ifdef UNDER_CE
+	// We have problems to actually show a completely
+	// painted window here...
+	SetForegroundWindow(wmPtr->wrapper);
+	SetActiveWindow(wmPtr->wrapper);
+	XCEShowNormalCursor();
+#else
 	SetActiveWindow(wmPtr->wrapper);
+#endif
     }
 }
 
@@ -2193,7 +2186,11 @@
     if (state == WithdrawnState) {
 	cmd = SW_HIDE;
     } else if (state == IconicState) {
+#ifdef UNDER_CE
+	cmd = SW_SHOWNORMAL;
+#else
 	cmd = SW_SHOWMINNOACTIVE;
+#endif
     } else if (state == NormalState) {
 	cmd = SW_SHOWNOACTIVATE;
     } else if (state == ZoomState) {
@@ -5047,6 +5044,15 @@
     rect.left = rect.right = rect.top = rect.bottom = 0;
     AdjustWindowRectEx(&rect, wmPtr->style, wmPtr->hMenu != NULL,
 	    wmPtr->exStyle);
+
+#ifdef UNDER_CE
+    if (wmPtr->hMenu && !WCEIsMenuAYG()) {
+	int h = WCEGetMenuHeight(wmPtr->wrapper);
+	XCETrace("WM: Adding menu height %d", h);
+	rect.bottom += h;
+    }
+#endif
+
     wmPtr->borderWidth = rect.right - rect.left;
     wmPtr->borderHeight = rect.bottom - rect.top;
 
@@ -5238,6 +5244,7 @@
 	    }
 	}
 	if (!(wmPtr->flags & WM_NEVER_MAPPED)) {
+	    // FIX: Use WCEDrawMenuBar for CE?
 	    DrawMenuBar(wmPtr->wrapper);
 	}
     }
@@ -6067,9 +6074,27 @@
     if (!(wmPtr->flags & TK_EMBEDDED)) {
 	if (!(wmPtr->flags & WM_NEVER_MAPPED)) {
 	    int syncPending = wmPtr->flags & WM_SYNC_PENDING;
+#ifdef UNDER_CE
+	    WCE_MENU_INFO *pminfo;
+	    HMENU hMainMenu;
+#endif
 
 	    wmPtr->flags |= WM_SYNC_PENDING;
+#ifdef UNDER_CE
+	    XCETrace("WM: SetMenu in TkWinSetMenu()");
+	    pminfo = (WCE_MENU_INFO *) ckalloc(sizeof(*pminfo));
+	    memset(pminfo, 0, sizeof(*pminfo));
+	    pminfo->type       = 0;
+	    pminfo->resid      = ID_MAINMENU;
+	    pminfo->hwndParent = wmPtr->wrapper;
+	    pminfo->hInst      = Tk_GetHINSTANCE();
+	    XCETrace("WM: Creating menu for hwnd 0x%x", wmPtr->wrapper);
+	    hMainMenu = WCECreateMenu(pminfo);
+	    XCETrace("WM: Menu is 0x%x", hMainMenu);
+	    WCESetMenu(wmPtr->wrapper, hMenu);
+#else
 	    SetMenu(wmPtr->wrapper, hMenu);
+#endif
 	    if (!syncPending) {
 		wmPtr->flags &= ~WM_SYNC_PENDING;
 	    }
@@ -6127,13 +6152,27 @@
 	    case SW_SHOWMAXIMIZED:
 		state = ZoomState;
 		break;
+#ifdef SW_SHOWMINIMIZED // not defined for Window CE as of v3.0
 	    case SW_SHOWMINIMIZED:
 		state = IconicState;
 		break;
+#endif
 	    case SW_SHOWNORMAL:
 		state = NormalState;
 		break;
 	}
+
+#ifdef UNDER_CE
+	// Undocumented high bits 6 seem to indicate SW_MINIMIZE
+	// Undocumented high bits 2 seem to indicate SW_MAXIMIZE
+	if ((pos->flags & 0xF0000000) == 0x60000000) {
+	    XCETrace("WM: Assuming IconicState");
+	    state = IconicState;
+	} else if ((pos->flags & 0xF0000000) == 0x20000000) {
+	    XCETrace("WM: Assuming ZoomState");
+	    state = ZoomState;
+	}
+#endif
     }
 
     /*
@@ -6176,7 +6215,6 @@
 	return;
     }
 
-
     /*
      * Compute the current geometry of the client area, reshape the
      * Tk window and generate a ConfigureNotify event.
@@ -6188,8 +6226,25 @@
     winPtr->changes.width = rect.right - rect.left;
     winPtr->changes.height = rect.bottom - rect.top;
     wmPtr->borderHeight = pos->cy - winPtr->changes.height;
+#ifdef UNDER_CE
+    {
+	int menuheight = 0;
+
+	if (wmPtr->hMenu && !WCEIsMenuAYG()) {
+	    // expand width
+	    menuheight = WCEGetMenuHeight(wmPtr->wrapper);
+	    MoveWindow(WCEGetMenuWindow(wmPtr->wrapper), 0, 0, 
+		    winPtr->changes.width, menuheight, TRUE);
+	    winPtr->changes.height -= menuheight;
+	}
+
+	MoveWindow(Tk_GetHWND(winPtr->window), 0, menuheight,
+		winPtr->changes.width, winPtr->changes.height, TRUE);
+    }
+#else
     MoveWindow(Tk_GetHWND(winPtr->window), 0, 0,
 	    winPtr->changes.width, winPtr->changes.height, TRUE);
+#endif
     GenerateConfigureNotify(winPtr);
 
     /*
@@ -6785,11 +6840,18 @@
     }
 
     switch (message) {
+#ifdef UNDER_CE
+        case WM_EXITMENULOOP:
+	  // FIX: we must repaint client area, but does not work!
+	  return DefWindowProc(hwnd, message, wParam, lParam);
+#endif
+
 	case WM_KILLFOCUS:
 	case WM_ERASEBKGND:
 	    result = 0;
 	    goto done;
 
+#ifdef WM_ENTERSIZEMOVE // not defined for Windows CE as of v3.0
 	case WM_ENTERSIZEMOVE:
 	    inMoveSize = 1;
 
@@ -6803,19 +6865,24 @@
 
 	    oldMode = Tcl_SetServiceMode(TCL_SERVICE_ALL);
 	    break;
+#endif
 
-	case WM_ACTIVATE:
+#ifdef WM_EXITSIZEMOVE // not defined for Windows CE as of v3.0
 	case WM_EXITSIZEMOVE:
+#endif
+	case WM_ACTIVATE:
 	    if (inMoveSize) {
 		inMoveSize = 0;
 		Tcl_SetServiceMode(oldMode);
 	    }
 	    break;
 
+#ifdef WM_GETMINMAXINFO // not defined for Windows CE as of v3.0
 	case WM_GETMINMAXINFO:
 	    SetLimits(hwnd, (MINMAXINFO *) lParam);
 	    result = 0;
 	    goto done;
+#endif
 
 	case WM_PALETTECHANGED:
 	    result = InstallColormaps(hwnd, WM_PALETTECHANGED,
@@ -6831,6 +6898,7 @@
 	    result = 0;
 	    goto done;
 
+#ifdef WM_NCHITTEST // not defined for Windows CE as of v3.0
 	case WM_NCHITTEST: {
 	    winPtr = GetTopLevel(hwnd);
 	    if (winPtr && (TkGrabState(winPtr) == TK_GRAB_EXCLUDED)) {
@@ -6847,7 +6915,9 @@
 	    }
 	    break;
 	}
+#endif
 
+#ifdef WM_MOUSEACTIVATE // not defined for Windows CE as of v3.0
 	case WM_MOUSEACTIVATE: {
 	    ActivateEvent *eventPtr;
 	    winPtr = GetTopLevel((HWND) wParam);
@@ -6878,6 +6948,7 @@
 	    result = MA_NOACTIVATE;
 	    goto done;
 	}
+#endif
 
 	default:
 	    break;
@@ -7106,3 +7177,53 @@
 	SetForegroundWindow(Tk_GetHWND(winPtr->window));
     }
 }
+
+#ifdef UNDER_CE
+// Recreate the child window of the wrapper window, because
+// SetWindowLong(GWL_STYLE, WS_CHILD) does not work...
+
+// Problem: The old window might be referenced in font pointers!
+
+TkWindow *
+WinCERecreateChild(TkWindow *winPtr, HWND hWrapper, DWORD dwStyle)
+{
+    RECT r;
+    HWND hOldChild, hNewChild;
+    //Tcl_HashEntry *entryPtr;
+    TkWindow *childPtr;
+
+    ThreadSpecificData *tsdPtr = (ThreadSpecificData *) 
+	Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
+
+    GetClientRect(hWrapper, &r);
+    hOldChild = Tk_GetHWND(winPtr->window);
+
+    hNewChild = CreateWindowEx(WS_EX_NOPARENTNOTIFY, 
+	    TK_WIN_CHILD_CLASS_NAME, NULL, dwStyle, 
+	    Tk_X(winPtr), Tk_Y(winPtr), 
+	    Tk_Width(winPtr), Tk_Height(winPtr), 
+	    hWrapper, NULL, Tk_GetHINSTANCE(), NULL);
+
+    XCETrace("WinCERecreateChild: hOldChild = %x hNewChild = %x", 
+	    hOldChild, hNewChild);
+
+    wince_putwinhandles(hOldChild, hNewChild);
+
+    // Reparent children
+    for (childPtr = winPtr->childList; 
+	 childPtr != NULL;
+	 childPtr = childPtr->nextPtr) {
+	if (childPtr->window != (Window) NULL) {
+	    SetParent(Tk_GetHWND(childPtr->window), hNewChild);
+	}
+    }
+
+    DestroyWindow(hOldChild);
+
+    // this automatically deletes old hash entry when windowhandle
+    // of winPtr is not null...
+    Tk_AttachHWND((Tk_Window)winPtr, hNewChild);
+
+    return winPtr;
+}
+#endif
--- ./tkWinX.c	Sat Feb  8 22:23:29 2003
+++ ../wince/tkWinX.c	Fri Apr  4 13:03:26 2003
@@ -31,7 +31,9 @@
  * The zmouse.h file includes the definition for WM_MOUSEWHEEL.
  */
 
+#ifndef UNDER_CE
 #include <zmouse.h>
+#endif
 
 /*
  * imm.h is needed by HandleIMEComposition
@@ -226,7 +228,8 @@
     }
     childClassInitialized = 1;
 
-    if (TkWinGetPlatformId() == VER_PLATFORM_WIN32_NT) {
+    if ((TkWinGetPlatformId() == VER_PLATFORM_WIN32_NT)
+	    || (TkWinGetPlatformId() == VER_PLATFORM_WIN32_CE)) {
 	/*
 	 * This is necessary to enable the use of themeable elements on XP,
 	 * so we don't even try and call it for Win9*.
@@ -259,7 +262,11 @@
     childClass.cbClsExtra = 0;
     childClass.cbWndExtra = 0;
     childClass.hInstance = hInstance;
+#ifdef UNDER_CE
+    childClass.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
+#else
     childClass.hbrBackground = NULL;
+#endif
     childClass.lpszMenuName = NULL;
 
     /*
@@ -336,6 +343,7 @@
  *	    VER_PLATFORM_WIN32s		Win32s on Windows 3.1. 
  *	    VER_PLATFORM_WIN32_WINDOWS	Win32 on Windows 95.
  *	    VER_PLATFORM_WIN32_NT	Win32 on Windows NT
+ *	    VER_PLATFORM_WIN32_CE	Windows CE
  *
  * Side effects:
  *	None.
@@ -642,10 +650,12 @@
     LRESULT result;
 
     switch (message) {
+#ifdef WM_INPUTLANGCHANGE // not defined for Windows CE as of v3.0
         case WM_INPUTLANGCHANGE:
 	    UpdateInputLanguage(wParam);
 	    result = 1;
 	    break;
+#endif
 
         case WM_IME_COMPOSITION:
             result = 0;
@@ -761,6 +771,15 @@
 	case WM_MBUTTONUP:
 	case WM_RBUTTONUP:
 	case WM_MOUSEMOVE:
+#ifdef UNDER_CE_OLD
+	{
+	    POINT pt;
+	    pt.x = (short) LOWORD(lParam);
+	    pt.y = (short) HIWORD(lParam);
+	    ClientToScreen(hwnd, &pt);
+	    WinCESetCursorPos(pt.x, pt.y);
+	}
+#endif
 	    Tk_PointerEvent(hwnd, (short) LOWORD(lParam),
 		    (short) HIWORD(lParam));
 	    return 1;
@@ -1351,7 +1370,11 @@
     char * buff;
     TkWindow *winPtr;
     Tcl_Encoding unicodeEncoding = TkWinGetUnicodeEncoding();
+#ifdef UNDER_CE
+    BOOL isWinNT = TRUE;
+#else
     BOOL isWinNT = (TkWinGetPlatformId() == VER_PLATFORM_WIN32_NT);
+#endif
 
     if ((lParam & GCS_RESULTSTR) == 0) {
         /*
@@ -1365,13 +1388,16 @@
     if (hIMC) {
 	if (isWinNT) {
 	    n = ImmGetCompositionStringW(hIMC, GCS_RESULTSTR, NULL, 0);
+#ifndef UNDER_CE
 	} else {
 	    n = ImmGetCompositionStringA(hIMC, GCS_RESULTSTR, NULL, 0);
+#endif
 	}
 
         if ((n > 0) && ((buff = (char *) ckalloc(n)) != NULL)) {
 	    if (isWinNT) {
 		n = ImmGetCompositionStringW(hIMC, GCS_RESULTSTR, buff, n);
+#ifndef UNDER_CE
 	    } else {
 		Tcl_DString utfString, unicodeString;
 
@@ -1395,6 +1421,7 @@
 		memcpy(buff, Tcl_DStringValue(&unicodeString), n);
 		Tcl_DStringFree(&utfString);
 		Tcl_DStringFree(&unicodeString);
+#endif
 	    }
 
 	    /*
--- ./winMain.c	Tue Feb 18 11:15:31 2003
+++ ../wince/winMain.c	Wed Mar 12 01:00:14 2003
@@ -17,7 +17,10 @@
 #include <windows.h>
 #undef WIN32_LEAN_AND_MEAN
 #include <malloc.h>
+
+#ifndef UNDER_CE
 #include <locale.h>
+#endif
 
 #include "tkInt.h"
 
@@ -81,7 +84,11 @@
  */
 
 int APIENTRY
+#ifdef UNDER_CE
+wWinMain(hInstance, hPrevInstance, lpszCmdLine, nCmdShow)
+#else
 WinMain(hInstance, hPrevInstance, lpszCmdLine, nCmdShow)
+#endif
     HINSTANCE hInstance;
     HINSTANCE hPrevInstance;
     LPSTR lpszCmdLine;
@@ -89,8 +96,20 @@
 {
     char **argv;
     int argc;
+#ifndef UNDER_CE
     char buffer[MAX_PATH+1];
     char *p;
+#endif
+
+#ifdef UNDER_CE
+    nCmdShow = SW_SHOWNORMAL;
+
+    XCEShowWaitCursor();
+
+    xceinit(lpszCmdLine);
+    argc = __xceargc;
+    argv = __xceargv;
+#endif
 
     Tcl_SetPanicProc(WishPanic);
 
@@ -107,6 +126,7 @@
      * is performed correctly.
      */
 
+#ifndef UNDER_CE
     setlocale(LC_ALL, "C");
     setargv(&argc, &argv);
 
@@ -122,6 +142,7 @@
 	    *p = '/';
 	}
     }
+#endif
 
 #ifdef TK_LOCAL_MAIN_HOOK
     TK_LOCAL_MAIN_HOOK(&argc, &argv);
@@ -168,6 +189,10 @@
      * application.
      */
 
+#ifdef UNDER_CE
+    consoleRequired = FALSE;
+#endif
+
     if (consoleRequired) {
 	if (Tk_CreateConsoleWindow(interp) == TCL_ERROR) {
 	    goto error;
@@ -387,8 +412,9 @@
      * Set up the default locale to be standard "C" locale so parsing
      * is performed correctly.
      */
-
+#ifndef UNDER_CE
     setlocale(LC_ALL, "C");
+#endif
 
     /*
      * Create the console channels and install them as the standard
--- ./tkWinWindow.c	Wed Oct  2 15:12:13 2002
+++ ../wince/tkWinWindow.c	Tue Mar 11 18:19:47 2003
@@ -359,10 +359,18 @@
     XEvent event;
     TkWindow *parentPtr;
     TkWindow *winPtr = TkWinGetWinPtr(w);
+    HWND hwnd;
 
     display->request++;
 
-    ShowWindow(Tk_GetHWND(w), SW_SHOWNORMAL);
+    hwnd = Tk_GetHWND(w);
+    ShowWindow(hwnd, SW_SHOWNORMAL);
+
+#ifdef UNDER_CE
+    InvalidateRect(hwnd, NULL, TRUE);
+    UpdateWindow(hwnd);
+#endif
+
     winPtr->flags |= TK_MAPPED;
 
     /*
--- ./tkWinDialog.c	Sat Feb  8 22:22:49 2003
+++ ../wince/tkWinDialog.c	Thu Apr  3 18:10:20 2003
@@ -17,12 +17,21 @@
 
 #include <commdlg.h>    /* includes common dialog functionality */
 #include <dlgs.h>       /* includes common dialog template defines */
+
+#ifdef UNDER_CE
+#include <commctrl.h>
+#else
 #include <cderr.h>      /* includes the common dialog error codes */
+#endif
 
 /*
  * This controls the use of the new style tk_chooseDirectory dialog.
  */
+#ifdef UNDER_CE
+#undef USE_NEW_CHOOSEDIR // not until Windows CE.NET
+#else
 #define USE_NEW_CHOOSEDIR 1
+#endif
 #ifdef USE_NEW_CHOOSEDIR
 #include <shlobj.h>     /* includes SHBrowseForFolder */
 
@@ -657,9 +666,11 @@
 #ifdef _WIN64
     ofn.hInstance		= (HINSTANCE) GetWindowLongPtr(ofn.hwndOwner, 
 					GWLP_HINSTANCE);
-#else
+#elif defined(GWL_HINSTANCE)
     ofn.hInstance		= (HINSTANCE) GetWindowLong(ofn.hwndOwner, 
 					GWL_HINSTANCE);
+#else // Windows CE does not define GWL_HINSTANCE as of v3.0
+    ofn.hInstance		= NULL;
 #endif
     ofn.lpstrFile		= (WCHAR *) file;
     ofn.nMaxFile		= TK_MULTI_MAX_PATH;
@@ -853,7 +864,7 @@
 	 * We could also check for FNERR_BUFFERTOOSMALL, but we can't
 	 * really do anything about it when it happens.
 	 */
-
+#ifdef FNERR_INVALIDFILENAME // not defined on Windows CE as of v3.00
 	if (CommDlgExtendedError() == FNERR_INVALIDFILENAME) {
 	    char *p;
 	    Tcl_DString ds;
@@ -872,7 +883,9 @@
 	    Tcl_SetResult(interp, "invalid filename \"", TCL_STATIC);
 	    Tcl_AppendResult(interp, Tcl_DStringValue(&ds), "\"", NULL);
 	    Tcl_DStringFree(&ds);
-	} else {
+	} else
+#endif
+	    {
 	    result = TCL_OK;
 	}
     }
@@ -1131,9 +1144,11 @@
 #ifdef _WIN64
     ofn.hInstance		= (HINSTANCE) GetWindowLongPtr(ofn.hwndOwner, 
 					GWLP_HINSTANCE);
-#else
+#elif defined(GWL_HINSTANCE)
     ofn.hInstance		= (HINSTANCE) GetWindowLong(ofn.hwndOwner, 
 					GWL_HINSTANCE);
+#else // Windows CE does not define GWL_HINSTANCE as of v3.0
+    ofn.hInstance		= NULL;
 #endif
     ofn.lpstrFilter		= NULL;
     ofn.lpstrCustomFilter	= NULL;
@@ -1337,6 +1352,7 @@
 	 * We could also check for FNERR_BUFFERTOOSMALL, but we can't
 	 * really do anything about it when it happens.
 	 */
+#ifdef FNERR_INVALIDFILENAME // not defined on Windows CE as of v3.00
 	if (CommDlgExtendedError() == FNERR_INVALIDFILENAME) {
 	    char *p;
 	    Tcl_DString ds;
@@ -1354,7 +1370,9 @@
 	    Tcl_SetResult(interp, "invalid filename \"", TCL_STATIC);
 	    Tcl_AppendResult(interp, Tcl_DStringValue(&ds), "\"", NULL);
 	    Tcl_DStringFree(&ds);
-	} else {
+	} else
+#endif
+	    {
 	    result = TCL_OK;
 	}
     }
@@ -1719,7 +1737,7 @@
                  * dialog happy
                  */
                 GetFullPathName(string, MAX_PATH, saveDir, NULL);
-                lstrcpyn(cdCBData.utfInitDir, saveDir, MAX_PATH);
+                memcpy(cdCBData.utfInitDir, saveDir, MAX_PATH);
                 Tcl_DStringFree(&initDirString);
                 break;
             }
@@ -1897,7 +1915,7 @@
              */
             Tcl_TranslateFileName(chooseDirSharedData->interp,
                     (char *)lParam, &initDirString);
-            lstrcpyn (string, Tcl_DStringValue(&initDirString), MAX_PATH);
+            memcpy(string, Tcl_DStringValue(&initDirString), MAX_PATH);
             Tcl_DStringFree(&initDirString);
 
             if (SetCurrentDirectory((char *)string) == 0) {
@@ -1958,7 +1976,9 @@
              * user specified parameter.
              */
             SetCurrentDirectory((char *) lpData);
+#ifdef BFFM_SETSELECTION // not defined for Windows CE as of 3.0
             SendMessage(hwnd, BFFM_SETSELECTION, TRUE, (LPARAM)lpData);
+#endif
             SendMessage(hwnd, BFFM_ENABLEOK, 0, (LPARAM) 1);
             break;
 
@@ -2011,9 +2031,11 @@
 	DIR_INITIAL,	DIR_EXIST,	DIR_PARENT,	FILE_TITLE
     };
 
+#ifdef LBSELCHSTRING // not defined for Windows CE as of v3.0
     if (tsdPtr->WM_LBSELCHANGED == 0) {
         tsdPtr->WM_LBSELCHANGED = RegisterWindowMessage(LBSELCHSTRING);
     }
+#endif
    
     result = TCL_ERROR;
     path[0] = '\0';
@@ -2083,9 +2105,11 @@
 #ifdef _WIN64
     ofn.hInstance		= (HINSTANCE) GetWindowLongPtr(ofn.hwndOwner, 
 					GWLP_HINSTANCE);
-#else
+#elif defined(GWL_HINSTANCE)
     ofn.hInstance		= (HINSTANCE) GetWindowLong(ofn.hwndOwner, 
 					GWL_HINSTANCE);
+#else // Windows CE does not define GWL_HINSTANCE as of v3.0
+    ofn.hInstance		= NULL;
 #endif
     ofn.lpstrFilter		= NULL;
     ofn.lpstrCustomFilter	= NULL;
--- ./tkWinPointer.c	Sat Feb  8 22:23:29 2003
+++ ../wince/tkWinPointer.c	Tue Mar 11 18:10:19 2003
@@ -56,6 +56,11 @@
 {
     int state = 0;
 
+#ifdef UNDER_CE
+    // GetKeyState does not return mouse state on ce...
+#define GetKeyState GetAsyncKeyState
+#endif
+
     if (GetKeyState(VK_SHIFT) & 0x8000) {
 	state |= ShiftMask;
     }
