Skip to content

Commit a837ed7

Browse files
PatriceJiangminggo
authored and
minggo
committed
[windows] use PostMessage to replace SendMessage (#19569)
1 parent 56abd88 commit a837ed7

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

cocos/base/CCConsole.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ namespace {
114114
if (Director::getInstance()->getOpenGLView())
115115
{
116116
HWND hwnd = Director::getInstance()->getOpenGLView()->getWin32Window();
117-
SendMessage(hwnd,
117+
PostMessage(hwnd,
118118
WM_COPYDATA,
119119
(WPARAM)(HWND)hwnd,
120120
(LPARAM)(LPVOID)&myCDS);

cocos/platform/win32/CCDevice-win32.cpp

+22-16
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ THE SOFTWARE.
3131
#include "platform/CCFileUtils.h"
3232
#include "platform/CCStdC.h"
3333

34+
#include <thread>
35+
3436
NS_CC_BEGIN
3537

3638
int Device::getDPI()
@@ -171,16 +173,18 @@ class BitmapDC
171173
if (fontPath.size() > 0)
172174
{
173175
_curFontPath = fontPath;
174-
wchar_t * pwszBuffer = utf8ToUtf16(_curFontPath);
175-
if (pwszBuffer)
176-
{
177-
if (AddFontResource(pwszBuffer))
176+
std::thread([fontPath, wnd = _wnd, this]() {
177+
wchar_t * pwszBuffer = utf8ToUtf16(fontPath);
178+
if (pwszBuffer)
178179
{
179-
SendMessage(_wnd, WM_FONTCHANGE, 0, 0);
180+
if (AddFontResource(pwszBuffer))
181+
{
182+
PostMessage(wnd, WM_FONTCHANGE, 0, 0);
183+
}
184+
delete[] pwszBuffer;
185+
pwszBuffer = nullptr;
180186
}
181-
delete[] pwszBuffer;
182-
pwszBuffer = nullptr;
183-
}
187+
}).detach();
184188
}
185189

186190
_font = nullptr;
@@ -428,14 +432,16 @@ class BitmapDC
428432
// release temp font resource
429433
if (_curFontPath.size() > 0)
430434
{
431-
wchar_t * pwszBuffer = utf8ToUtf16(_curFontPath);
432-
if (pwszBuffer)
433-
{
434-
RemoveFontResource(pwszBuffer);
435-
SendMessage(_wnd, WM_FONTCHANGE, 0, 0);
436-
delete[] pwszBuffer;
437-
pwszBuffer = nullptr;
438-
}
435+
std::thread([curFontPath = _curFontPath, wnd = _wnd, this]() {
436+
wchar_t * pwszBuffer = utf8ToUtf16(curFontPath);
437+
if (pwszBuffer)
438+
{
439+
RemoveFontResource(pwszBuffer);
440+
PostMessage(wnd, WM_FONTCHANGE, 0, 0);
441+
delete[] pwszBuffer;
442+
pwszBuffer = nullptr;
443+
}
444+
}).detach();
439445
_curFontPath.clear();
440446
}
441447
}

0 commit comments

Comments
 (0)