summaryrefslogtreecommitdiffstats
path: root/app/win
diff options
context:
space:
mode:
Diffstat (limited to 'app/win')
-rw-r--r--app/win/window_impl.cc14
-rw-r--r--app/win/window_impl.h4
2 files changed, 17 insertions, 1 deletions
diff --git a/app/win/window_impl.cc b/app/win/window_impl.cc
index b28eab5..8ddd2bc 100644
--- a/app/win/window_impl.cc
+++ b/app/win/window_impl.cc
@@ -180,7 +180,15 @@ LRESULT CALLBACK WindowImpl::WndProc(HWND hwnd,
if (!window)
return 0;
- return window->OnWndProc(message, w_param, l_param);
+ LRESULT return_code = window->OnWndProc(message, w_param, l_param);
+
+ // Clean up state. Do this after the above call so subclasses still have a
+ // valid hwnd(). Can't wait until WM_NCDESTROY because by then |hwnd| is not
+ // guaranteed to be reported to us.
+ if (message == WM_DESTROY)
+ window->OnDestroy();
+
+ return return_code;
}
std::wstring WindowImpl::GetWindowClassName() {
@@ -211,4 +219,8 @@ std::wstring WindowImpl::GetWindowClassName() {
return name;
}
+void WindowImpl::OnDestroy() {
+ hwnd_ = 0;
+}
+
} // namespace app
diff --git a/app/win/window_impl.h b/app/win/window_impl.h
index fb5d512..dd7ef5a 100644
--- a/app/win/window_impl.h
+++ b/app/win/window_impl.h
@@ -87,6 +87,10 @@ class WindowImpl : public MessageMapInterface {
// If necessary, this registers the window class.
std::wstring GetWindowClassName();
+ // Called when the HWND gets a WM_DESTROY message; should cause us to clean
+ // up any state.
+ void OnDestroy();
+
// All classes registered by WidgetWin start with this name.
static const wchar_t* const kBaseClassName;