#define UNIQE_NAME "{1AB792D6-EAF2-3267-9A84-9135681127A4}"
#define GIS_MSG "{D48CA993-4925-41cb-8F59-ABAAAFCEF797}"
const UINT ID_GIS_INSTANCE = ::RegisterWindowMessage(GIS_MSG); //注册消息
// 确保程序只有一个实例在运行
m_hOneInstance = ::CreateMutex(NULL, FALSE, UNIQE_NAME);
if (GetLastError() == ERROR_ALREADY_EXISTS )//如果存在前一个
{
//发送消息,激活实例
DWORD dwRecipients = BSM_APPLICATIONS;
::BroadcastSystemMessage(BSF_NOHANG, &dwRecipients,
ID_GIS_INSTANCE, // registered window message
0, 0); // user defined parameters
return FALSE;
}
ON_REGISTERED_MESSAGE(ID_GIS_INSTANCE, OnGISInstance)
LRESULT CMainFrame::OnGISInstance(WPARAM wParam, LPARAM lParam)
{
theApp.m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);
theApp.m_pMainWnd->SetForegroundWindow();
::AfxMessageBox("本程序已经有一个实例在运行了。");
return 0;
}