summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2014-10-09 12:52:05 +0000
committerPierre Ossman <ossman@cendio.se>2014-10-09 12:52:05 +0000
commit3e4af3cd8c7d4e09f6074f475727e0cbeb297462 (patch)
tree64264eee958c936f1a14ad6ff6de528d568c2806
parent933840f353beaa303e746cd13cd15be3ba2a41f3 (diff)
Make sure we unregister for clipboard notifications on exit
on Windows. This is necessary because Windows doesn't implicitly clean up when a process dies, and we cannot trust applications to always explicitly unregister. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10367 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
-rw-r--r--src/Fl_win32.cxx30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/Fl_win32.cxx b/src/Fl_win32.cxx
index fe051e363..0872981f5 100644
--- a/src/Fl_win32.cxx
+++ b/src/Fl_win32.cxx
@@ -472,6 +472,11 @@ public:
OleUninitialize();
fl_brush_action(1);
fl_cleanup_dc_list();
+ // This is actually too late in the cleanup process to remove the
+ // clipboard notifications, but we have no earlier hook so we try
+ // to work around it anyway.
+ if (clipboard_wnd != NULL)
+ fl_clipboard_notify_untarget(clipboard_wnd);
}
};
static Fl_Win32_At_Exit win32_at_exit;
@@ -812,7 +817,30 @@ static void fl_clipboard_notify_untarget(HWND wnd) {
if (wnd != clipboard_wnd)
return;
- ChangeClipboardChain(wnd, next_clipboard_wnd);
+ // We might be called late in the cleanup where Windows has already
+ // implicitly destroyed our clipboard window. At that point we need
+ // to do some extra work to manually repair the clipboard chain.
+ if (IsWindow(wnd))
+ ChangeClipboardChain(wnd, next_clipboard_wnd);
+ else {
+ HWND tmp, head;
+
+ tmp = CreateWindow("STATIC", "Temporary FLTK Clipboard Window", 0,
+ 0, 0, 0, 0, HWND_MESSAGE, NULL, NULL, NULL);
+ if (tmp == NULL)
+ return;
+
+ head = SetClipboardViewer(tmp);
+ if (head == NULL)
+ ChangeClipboardChain(tmp, next_clipboard_wnd);
+ else {
+ SendMessage(head, WM_CHANGECBCHAIN, (WPARAM)wnd, (LPARAM)next_clipboard_wnd);
+ ChangeClipboardChain(tmp, head);
+ }
+
+ DestroyWindow(tmp);
+ }
+
clipboard_wnd = next_clipboard_wnd = 0;
}