diff --git a/src/she/CMakeLists.txt b/src/she/CMakeLists.txt index 313f1681b..d0f728518 100644 --- a/src/she/CMakeLists.txt +++ b/src/she/CMakeLists.txt @@ -1,5 +1,5 @@ # SHE -# Copyright (C) 2012-2015 David Capello +# Copyright (C) 2012-2016 David Capello set(SHE_SOURCES) @@ -143,7 +143,8 @@ if(USE_SKIA_BACKEND) if(WIN32) list(APPEND SHE_SOURCES skia/skia_window_win.cpp - win/vk.cpp) + win/vk.cpp + win/window_dde.cpp) endif() if(APPLE) diff --git a/src/she/LICENSE.txt b/src/she/LICENSE.txt index 1021a1983..65642aa80 100644 --- a/src/she/LICENSE.txt +++ b/src/she/LICENSE.txt @@ -1,4 +1,4 @@ -Copyright (c) 2012-2013 David Capello +Copyright (c) 2012-2016 David Capello Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/src/she/alleg4/alleg_display.cpp b/src/she/alleg4/alleg_display.cpp index e4f6614d1..61bbb5305 100644 --- a/src/she/alleg4/alleg_display.cpp +++ b/src/she/alleg4/alleg_display.cpp @@ -1,5 +1,5 @@ // SHE library -// Copyright (C) 2012-2015 David Capello +// Copyright (C) 2012-2016 David Capello // // This file is released under the terms of the MIT license. // Read LICENSE.txt for more information. @@ -82,6 +82,21 @@ bool capture_mouse = false; static LRESULT CALLBACK wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { + // Don't process DDE messages here because we cannot get the first + // DDE message correctly. The problem is that the message pump + // starts before we can subclass the Allegro HWND, so we don't have + // enough time to inject the code to process this kind of message. + // + // For more info see "Once you go input-idle, your application is + // deemed ready to receive DDE messages": + // https://blogs.msdn.microsoft.com/oldnewthing/20140620-00/?p=693 + // + // Anyway a possible solution would be to avoid processing the + // message loop until we subclass the HWND. I've tested this and it + // doesn't work, maybe because the message pump on Allegro 4 isn't + // in the main thread, I really don't know. But it just crash the + // whole system (Windows 10). + switch (msg) { case WM_DROPFILES: { diff --git a/src/she/skia/skia_window_win.cpp b/src/she/skia/skia_window_win.cpp index a7ea98817..f5df7fac3 100644 --- a/src/she/skia/skia_window_win.cpp +++ b/src/she/skia/skia_window_win.cpp @@ -1,5 +1,5 @@ // SHE library -// Copyright (C) 2012-2015 David Capello +// Copyright (C) 2012-2016 David Capello // // This file is released under the terms of the MIT license. // Read LICENSE.txt for more information. @@ -22,6 +22,14 @@ #endif +#ifdef _WIN32 + + #include + #include "she/win/window_dde.h" // Include this one time to + +#endif + + namespace she { SkiaWindow::SkiaWindow(EventQueue* queue, SkiaDisplay* display, diff --git a/src/she/win/window.h b/src/she/win/window.h index d8eaf21c3..dce9a0147 100644 --- a/src/she/win/window.h +++ b/src/she/win/window.h @@ -1,5 +1,5 @@ // SHE library -// Copyright (C) 2012-2015 David Capello +// Copyright (C) 2012-2016 David Capello // // This file is released under the terms of the MIT license. // Read LICENSE.txt for more information. @@ -18,6 +18,7 @@ #include "she/event.h" #include "she/keys.h" #include "she/native_cursor.h" +#include "she/win/window_dde.h" #ifndef WM_MOUSEHWHEEL #define WM_MOUSEHWHEEL 0x020E @@ -554,6 +555,10 @@ namespace she { } + LRESULT result = FALSE; + if (handle_dde_messages(m_hwnd, msg, wparam, lparam, result)) + return result; + return DefWindowProc(m_hwnd, msg, wparam, lparam); } diff --git a/src/she/win/window_dde.cpp b/src/she/win/window_dde.cpp new file mode 100644 index 000000000..12baa4259 --- /dev/null +++ b/src/she/win/window_dde.cpp @@ -0,0 +1,205 @@ +// SHE library +// Copyright (C) 2016 David Capello +// +// This file is released under the terms of the MIT license. +// Read LICENSE.txt for more information. + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "she/win/window_dde.h" + +#include "base/string.h" +#include "she/event.h" +#include "she/event_queue.h" + +#include +#include + +namespace she { + +namespace { + +std::string get_atom_string(ATOM atom, bool isUnicode) +{ + std::string result; + if (!atom) + return result; + + if (isUnicode) { + std::vector buf(256, 0); + GlobalGetAtomNameW(atom, &buf[0], buf.size()); + result = base::to_utf8(std::wstring(&buf[0])); + } + else { + std::vector buf; + UINT chars = GlobalGetAtomNameA(atom, &buf[0], buf.size()); + result = &buf[0]; + } + + return result; +} + +// Converts a DDE command string (e.g. "[open(filename)]") into she events. +// https://msdn.microsoft.com/en-us/library/windows/desktop/ms648995.aspx +bool parse_dde_command(const std::string& cmd) +{ + bool result = false; + + for (size_t i=0; i cmdParams; + + for (i=j+1; i + +namespace she { + +bool handle_dde_messages(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam, LRESULT& result); + +} // namespace she + +#endif