Skip to content

Commit

Permalink
[windows] use PostMessage to replace SendMessage (cocos2d#19569)
Browse files Browse the repository at this point in the history
  • Loading branch information
PatriceJiang authored and huangwei1024 committed Jun 20, 2019
1 parent 6f0301a commit aa62874
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion cocos/base/CCConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ namespace {
if (Director::getInstance()->getOpenGLView())
{
HWND hwnd = Director::getInstance()->getOpenGLView()->getWin32Window();
SendMessage(hwnd,
PostMessage(hwnd,
WM_COPYDATA,
(WPARAM)(HWND)hwnd,
(LPARAM)(LPVOID)&myCDS);
Expand Down
38 changes: 22 additions & 16 deletions cocos/platform/win32/CCDevice-win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ THE SOFTWARE.
#include "platform/CCFileUtils.h"
#include "platform/CCStdC.h"

#include <thread>

NS_CC_BEGIN

int Device::getDPI()
Expand Down Expand Up @@ -171,16 +173,18 @@ class BitmapDC
if (fontPath.size() > 0)
{
_curFontPath = fontPath;
wchar_t * pwszBuffer = utf8ToUtf16(_curFontPath);
if (pwszBuffer)
{
if (AddFontResource(pwszBuffer))
std::thread([fontPath, wnd = _wnd, this]() {
wchar_t * pwszBuffer = utf8ToUtf16(fontPath);
if (pwszBuffer)
{
SendMessage(_wnd, WM_FONTCHANGE, 0, 0);
if (AddFontResource(pwszBuffer))
{
PostMessage(wnd, WM_FONTCHANGE, 0, 0);
}
delete[] pwszBuffer;
pwszBuffer = nullptr;
}
delete[] pwszBuffer;
pwszBuffer = nullptr;
}
}).detach();
}

_font = nullptr;
Expand Down Expand Up @@ -428,14 +432,16 @@ class BitmapDC
// release temp font resource
if (_curFontPath.size() > 0)
{
wchar_t * pwszBuffer = utf8ToUtf16(_curFontPath);
if (pwszBuffer)
{
RemoveFontResource(pwszBuffer);
SendMessage(_wnd, WM_FONTCHANGE, 0, 0);
delete[] pwszBuffer;
pwszBuffer = nullptr;
}
std::thread([curFontPath = _curFontPath, wnd = _wnd, this]() {
wchar_t * pwszBuffer = utf8ToUtf16(curFontPath);
if (pwszBuffer)
{
RemoveFontResource(pwszBuffer);
PostMessage(wnd, WM_FONTCHANGE, 0, 0);
delete[] pwszBuffer;
pwszBuffer = nullptr;
}
}).detach();
_curFontPath.clear();
}
}
Expand Down

0 comments on commit aa62874

Please sign in to comment.