忽略窗口最小化和最大化时发送的WM_SIZE消息
This commit is contained in:
parent
950f502b19
commit
8c246df955
|
|
@ -33,7 +33,7 @@ void e2d::Game::destroyInstance()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool e2d::Game::init(const String& mutexName)
|
bool e2d::Game::init()
|
||||||
{
|
{
|
||||||
if (_initialized)
|
if (_initialized)
|
||||||
{
|
{
|
||||||
|
|
@ -41,26 +41,6 @@ bool e2d::Game::init(const String& mutexName)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mutexName.isEmpty())
|
|
||||||
{
|
|
||||||
// 创建进程互斥体
|
|
||||||
String fullMutexName = L"Easy2DApp-" + mutexName;
|
|
||||||
HANDLE hMutex = ::CreateMutex(nullptr, TRUE, (LPCWSTR)fullMutexName);
|
|
||||||
|
|
||||||
if (hMutex == nullptr)
|
|
||||||
{
|
|
||||||
WARN("CreateMutex Failed!");
|
|
||||||
}
|
|
||||||
else if (::GetLastError() == ERROR_ALREADY_EXISTS)
|
|
||||||
{
|
|
||||||
// 如果程序已经存在并且正在运行,弹窗提示
|
|
||||||
Window::getInstance()->info(L"游戏已在其他窗口中打开!", L"提示");
|
|
||||||
// 关闭进程互斥体
|
|
||||||
::CloseHandle(hMutex);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 初始化 COM 组件
|
// 初始化 COM 组件
|
||||||
CoInitialize(nullptr);
|
CoInitialize(nullptr);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,45 @@ void e2d::Window::destroyInstance()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool e2d::Window::createMutex(const String & mutex)
|
||||||
|
{
|
||||||
|
if (mutex.isEmpty())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// 创建进程互斥体
|
||||||
|
String fullMutexName = L"Easy2DApp-" + mutex;
|
||||||
|
HANDLE hMutex = ::CreateMutex(nullptr, TRUE, (LPCWSTR)fullMutexName);
|
||||||
|
|
||||||
|
if (hMutex == nullptr)
|
||||||
|
{
|
||||||
|
WARN("CreateMutex Failed!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if (::GetLastError() == ERROR_ALREADY_EXISTS)
|
||||||
|
{
|
||||||
|
// 关闭进程互斥体
|
||||||
|
::CloseHandle(hMutex);
|
||||||
|
// 打开游戏窗口
|
||||||
|
if (!this->_title.isEmpty())
|
||||||
|
{
|
||||||
|
// 获取窗口句柄
|
||||||
|
HWND hProgramWnd = ::FindWindow(L"Easy2DApp", (LPCTSTR)this->_title);
|
||||||
|
if (hProgramWnd)
|
||||||
|
{
|
||||||
|
// 获取窗口显示状态
|
||||||
|
WINDOWPLACEMENT wpm;
|
||||||
|
::GetWindowPlacement(hProgramWnd, &wpm);
|
||||||
|
// 将运行的程序窗口还原成正常状态
|
||||||
|
wpm.showCmd = SW_SHOW;
|
||||||
|
::SetWindowPlacement(hProgramWnd, &wpm);
|
||||||
|
::SetWindowPos(hProgramWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
HWND e2d::Window::__create()
|
HWND e2d::Window::__create()
|
||||||
{
|
{
|
||||||
// 注册窗口类
|
// 注册窗口类
|
||||||
|
|
@ -350,15 +389,21 @@ LRESULT e2d::Window::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPar
|
||||||
{
|
{
|
||||||
UINT width = LOWORD(lParam);
|
UINT width = LOWORD(lParam);
|
||||||
UINT height = HIWORD(lParam);
|
UINT height = HIWORD(lParam);
|
||||||
|
|
||||||
|
if (wParam == SIZE_RESTORED)
|
||||||
|
{
|
||||||
Window::getInstance()->_size = Size(width, height);
|
Window::getInstance()->_size = Size(width, height);
|
||||||
|
}
|
||||||
|
|
||||||
// 如果程序接收到一个 WM_SIZE 消息,这个方法将调整渲染
|
// 如果程序接收到一个 WM_SIZE 消息,这个方法将调整渲染
|
||||||
// 目标适当。它可能会调用失败,但是这里可以忽略有可能的
|
// 目标适当。它可能会调用失败,但是这里可以忽略有可能的
|
||||||
// 错误,因为这个错误将在下一次调用 EndDraw 时产生
|
// 错误,因为这个错误将在下一次调用 EndDraw 时产生
|
||||||
auto pRT = Renderer::getInstance()->getRenderTarget();
|
auto pRT = Renderer::getInstance()->getRenderTarget();
|
||||||
if (pRT)
|
if (pRT)
|
||||||
|
{
|
||||||
pRT->Resize(D2D1::SizeU(width, height));
|
pRT->Resize(D2D1::SizeU(width, height));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// 处理窗口标题变化消息
|
// 处理窗口标题变化消息
|
||||||
|
|
|
||||||
|
|
@ -21,9 +21,7 @@ public:
|
||||||
static void destroyInstance();
|
static void destroyInstance();
|
||||||
|
|
||||||
// 初始化游戏
|
// 初始化游戏
|
||||||
bool init(
|
bool init();
|
||||||
const String& mutexName = L"" /* ½ø³Ì»¥³âÌåÃû³Æ */
|
|
||||||
);
|
|
||||||
|
|
||||||
// 启动游戏
|
// 启动游戏
|
||||||
void start(
|
void start(
|
||||||
|
|
@ -86,6 +84,11 @@ public:
|
||||||
// 销毁窗口实例
|
// 销毁窗口实例
|
||||||
static void destroyInstance();
|
static void destroyInstance();
|
||||||
|
|
||||||
|
// ´´½¨´°¿Ú»¥³âÌå
|
||||||
|
bool createMutex(
|
||||||
|
const String& mutex = L"" /* ½ø³Ì»¥³âÌåÃû³Æ */
|
||||||
|
);
|
||||||
|
|
||||||
// 修改窗口大小
|
// 修改窗口大小
|
||||||
void setSize(
|
void setSize(
|
||||||
int width, /* 窗口宽度 */
|
int width, /* 窗口宽度 */
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue