15,472
社区成员
发帖
与我相关
我的任务
分享
// 只生成一个实例,当已有实例存在,使其自动弹出。
#define STR_PROGRAM_NAME L"MagicBackup"
HANDLE hMutex = ::CreateMutex(NULL, TRUE, STR_PROGRAM_NAME);
if (NULL != hMutex)
{
DWORD dwErr = ::GetLastError();
if (ERROR_ALREADY_EXISTS == dwErr)
{
::CloseHandle(hMutex);
HWND hWndPrevious = ::GetWindow(GetDesktopWindow(), GW_CHILD);
while (hWndPrevious)
{
if (::GetProp(hWndPrevious, STR_PROGRAM_NAME))
{
// 问题一:
// 为什么这儿,GetProp函数调用之后,始终进不了?
if (!::IsWindowVisible(hWndPrevious))
{
::ShowWindow(hWndPrevious, SW_RESTORE);
}
::SendMessage(hWndPrevious, WM_SYSCOMMAND, SC_RESTORE, NULL);
::SetForegroundWindow(hWndPrevious);
::SetForegroundWindow(::GetLastActivePopup(hWndPrevious));
}
hWndPrevious = ::GetWindow(hWndPrevious, GW_HWNDNEXT);
}
return FALSE;
}
}