📄 instancecheck.cpp
字号:
//////////////////////////////////////////////////////////////////////
// FileFury
// Copyright (c) 2000 Tenebril Incorporated
// All rights reserved.
//
// This source code is governed by the Tenebril open source
// license (http://www.tenebril.com/developers/opensource/license.html)
//
// For more information on this and other open source applications,
// visit the Tenebril OpenSource page:
// http://www.tenebril.com/developers/opensource
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "InstanceCheck.h"
CInstanceCheck::CInstanceCheck()
{
m_hMutex = NULL;
}
CInstanceCheck::~CInstanceCheck()
{
if(m_hMutex)
{
ReleaseMutex(m_hMutex);
while(GlobalFindAtom(m_strClassName) != 0)
GlobalDeleteAtom(GlobalFindAtom(m_strClassName));
}
return;
}
bool CInstanceCheck::Create(LPCTSTR lpClassName, bool RegisterWindow,
bool BringToTop)
{
m_strClassName = lpClassName;
m_strClassName += _T(" Class");
m_hMutex = CreateMutex(NULL, FALSE, m_strClassName);
if(GetLastError() == ERROR_ALREADY_EXISTS && GlobalFindAtom(m_strClassName) != 0)
{
/* Instance is already running */
m_hMutex = NULL;
if(BringToTop)
{
HWND hWnd = FindWindowEx(NULL, NULL, m_strClassName, NULL);
if(hWnd)
{
ShowWindow(hWnd, SW_RESTORE);
BringWindowToTop(hWnd);
SetForegroundWindow(hWnd);
}
}
return false;
}
GlobalAddAtom(m_strClassName);
if(RegisterWindow)
{
WNDCLASS wndcls;
memset(&wndcls, 0, sizeof(WNDCLASS));
wndcls.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
wndcls.lpfnWndProc = AfxWndProc;
wndcls.hInstance = AfxGetInstanceHandle();
wndcls.hIcon = (HICON)NULL;
wndcls.hCursor = LoadCursor(wndcls.hInstance, IDC_ARROW);
wndcls.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wndcls.lpszMenuName = NULL;
wndcls.lpszClassName = m_strClassName;
if(!AfxRegisterClass(&wndcls))
{
AfxMessageBox(_T("Failed to register window class!"),
MB_ICONSTOP | MB_OK );
return false;
}
}
return true;
}
CString CInstanceCheck::GetClassName()
{
return m_strClassName;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -