diff --git a/windows/runner/win32_window.cpp b/windows/runner/win32_window.cpp index c10f08d..bd11548 100644 --- a/windows/runner/win32_window.cpp +++ b/windows/runner/win32_window.cpp @@ -105,6 +105,31 @@ Win32Window::~Win32Window() { bool Win32Window::CreateAndShow(const std::wstring& title, const Point& origin, const Size& size) { + + HANDLE hMutexHandle=CreateMutex(NULL, TRUE, L"com.linloir.lchatclient.mutex"); + HWND handle=FindWindowA(NULL, "tcp_client"); + + if (hMutexHandle == NULL || GetLastError() == ERROR_ALREADY_EXISTS) + { + WINDOWPLACEMENT place = {sizeof(WINDOWPLACEMENT)}; + GetWindowPlacement(handle, &place); + switch (place.showCmd) + { + case SW_SHOWMAXIMIZED: + ShowWindow(handle, SW_SHOWMAXIMIZED); + break; + case SW_SHOWMINIMIZED: + ShowWindow(handle, SW_RESTORE); + break; + default: + ShowWindow(handle, SW_NORMAL); + break; + } + SetWindowPos(0, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE); + SetForegroundWindow(handle); + return 0; + } + Destroy(); const wchar_t* window_class =