-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add minimize to tray support. #113
Conversation
Thinking about it, I could probably just use mutex to force single instance. I don't know why I overcomplicated it. |
Yeah, you can do that. Here's an example: // I use a class here to perform cleanup after winmain
class InstanceMutex
{
HANDLE m_handle = NULL;
public:
HRESULT Init()
{
#ifdef _DEBUG
return 0;
#else
SetLastError(NO_ERROR);
m_handle = CreateMutex(NULL, TRUE, WINDOW_CLASS);
if (GetLastError() == ERROR_ALREADY_EXISTS)
{
if (m_handle)
{
CloseHandle(m_handle);
m_handle = NULL;
}
return ERROR_ALREADY_EXISTS;
}
return GetLastError();
#endif
}
~InstanceMutex()
{
#ifdef _DEBUG
if (m_handle)
CloseHandle(m_handle);
#endif
}
};
InstanceMutex g_instanceMutex;
bool DetectDuplicateInstances()
{
HRESULT hres = g_instanceMutex.Init();
if (hres != ERROR_ALREADY_EXISTS) return false;
HWND hWnd = FindWindow(WINDOW_CLASS_NAME, NULL);
if (hWnd) {
SendMessage (hWnd, WM_REQUESTACTIVATE, 0, 0);
return true;
}
return false;
} |
Fix warnings.
@@ -1580,21 +1580,21 @@ static bool ForceSingleInstance(LPCWSTR pClassName) | |||
HRESULT hResult = g_instanceMutex.Init(); | |||
|
|||
if (hResult != ERROR_ALREADY_EXISTS) | |||
return false; | |||
return true; | |||
|
|||
HWND hWnd = FindWindow(pClassName, NULL); | |||
if (hWnd) | |||
{ | |||
SendMessage(hWnd, WM_RESTORE, 0, 0); | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return false
in the condition, and true
just below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me :)
* Don't show the main window on startup. * Don't take focus to the main message box when the channel is switched if the window is not active. * Change `--startup` to `/startup`.
No description provided.