Improvements

- Restrict one window instance only
This commit is contained in:
Linloir 2022-10-20 15:52:58 +08:00
parent 01f39f0ca8
commit f9907c16fe
No known key found for this signature in database
GPG Key ID: 58EEB209A0F2C366

View File

@ -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 =