From 530810deda0de9caf90c3937102085eb19ed6870 Mon Sep 17 00:00:00 2001
From: Pietro Gagliardi <pietro10@mac.com>
Date: Sat, 12 Jul 2014 16:15:10 -0400
Subject: [PATCH] Implemented Window.Close() on Windows.

---
 redo/funcnames_windows.go |  1 +
 redo/window_windows.go    | 15 ++++++++++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/redo/funcnames_windows.go b/redo/funcnames_windows.go
index ce334f2..689e54e 100644
--- a/redo/funcnames_windows.go
+++ b/redo/funcnames_windows.go
@@ -25,3 +25,4 @@ package ui
 
 // wfunc user32 SendMessageW uintptr t_UINT t_WPARAM t_LPARAM t_LRESULT,noerr
 // wfunc user32 UpdateWindow uintptr uintptr
+// wfunc user32 DestroyWindow uintptr uintptr
diff --git a/redo/window_windows.go b/redo/window_windows.go
index 4406704..f2e8951 100644
--- a/redo/window_windows.go
+++ b/redo/window_windows.go
@@ -123,11 +123,18 @@ func (w *window) Hide() *Request {
 	}
 }
 
+func doclose(w *window) {
+	res, err := f_DestroyWindow(w.hwnd)
+	if res == 0 {
+		panic(fmt.Errorf("error destroying window: %v", err))
+	}
+}
+
 func (w *window) Close() *Request {
 	c := make(chan interface{})
 	return &Request{
 		op:		func() {
-			// TODO
+			doclose(w)
 			c <- struct{}{}
 		},
 		resp:		c,
@@ -158,6 +165,12 @@ func windowWndProc(hwnd uintptr, msg t_UINT, wParam t_WPARAM, lParam t_LPARAM) t
 		return f_DefWindowProcW(hwnd, msg, wParam, lParam)
 	}
 	switch msg {
+	case c_WM_CLOSE:
+		close := w.closing.fire()
+		if close {
+			doclose(w)
+		}
+		return 0
 	default:
 		return f_DefWindowProcW(hwnd, msg, wParam, lParam)
 	}