Window::CheckMutex rename to CheckUnique
This commit is contained in:
parent
42ac308278
commit
cf3dfc4cf4
|
|
@ -53,38 +53,18 @@ e2d::Window::~Window()
|
||||||
::CoUninitialize();
|
::CoUninitialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool e2d::Window::CheckMutex(const String & mutex)
|
bool e2d::Window::CheckUnique()
|
||||||
{
|
{
|
||||||
if (mutex.IsEmpty())
|
HANDLE mutex = ::CreateMutex(nullptr, TRUE, LPCWSTR(L"Easy2DApp-" + title_));
|
||||||
return false;
|
|
||||||
|
|
||||||
HANDLE hMutex = ::CreateMutex(nullptr, TRUE, LPCWSTR(L"Easy2DApp-" + mutex));
|
if (mutex == nullptr)
|
||||||
|
|
||||||
if (hMutex == nullptr)
|
|
||||||
{
|
{
|
||||||
WARN("CreateMutex Failed!");
|
WARN("CreateMutex Failed!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if (::GetLastError() == ERROR_ALREADY_EXISTS)
|
else if (::GetLastError() == ERROR_ALREADY_EXISTS)
|
||||||
{
|
{
|
||||||
// 关闭进程互斥体
|
::CloseHandle(mutex);
|
||||||
::CloseHandle(hMutex);
|
|
||||||
// 打开游戏窗口
|
|
||||||
if (!this->title_.IsEmpty())
|
|
||||||
{
|
|
||||||
// 获取窗口句柄
|
|
||||||
HWND hProgramWnd = ::FindWindow(REGISTER_CLASS, (LPCTSTR)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 false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -37,11 +37,6 @@ namespace e2d
|
||||||
// 销毁窗体实例
|
// 销毁窗体实例
|
||||||
static void DestroyInstance();
|
static void DestroyInstance();
|
||||||
|
|
||||||
// ´´½¨´°Ì廥³âÌå
|
|
||||||
bool CheckMutex(
|
|
||||||
const String& mutex = L"" /* ½ø³Ì»¥³âÌåÃû³Æ */
|
|
||||||
);
|
|
||||||
|
|
||||||
// 获取窗体标题
|
// 获取窗体标题
|
||||||
const String& GetTitle() const;
|
const String& GetTitle() const;
|
||||||
|
|
||||||
|
|
@ -91,6 +86,10 @@ namespace e2d
|
||||||
bool enabled
|
bool enabled
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// 检测窗口是否唯一
|
||||||
|
// 返回值:返回 false 说明游戏已经正在进行,可以防止用户同时打开多个游戏窗口
|
||||||
|
bool CheckUnique();
|
||||||
|
|
||||||
// 弹出窗口
|
// 弹出窗口
|
||||||
// 返回值:当窗口包含取消按钮时,返回值表示用户是否点击确认按钮
|
// 返回值:当窗口包含取消按钮时,返回值表示用户是否点击确认按钮
|
||||||
bool Popup(
|
bool Popup(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue