mirror of
https://github.com/Linloir/Simple-TCP-Client.git
synced 2025-12-17 00:38:11 +08:00
Improvements
- Restrict one window instance only
This commit is contained in:
parent
01f39f0ca8
commit
f9907c16fe
@ -105,6 +105,31 @@ Win32Window::~Win32Window() {
|
|||||||
bool Win32Window::CreateAndShow(const std::wstring& title,
|
bool Win32Window::CreateAndShow(const std::wstring& title,
|
||||||
const Point& origin,
|
const Point& origin,
|
||||||
const Size& size) {
|
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();
|
Destroy();
|
||||||
|
|
||||||
const wchar_t* window_class =
|
const wchar_t* window_class =
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user