Windows根据程序标题查找正在运行的程序的HWND--判断窗口程序是否运行

BOOL CALLBACK MyFindWindowEnum(HWND hwnd, LPARAM lParam)
{
	WCHAR szName[MAX_PATH] = { 0 };
	GetWindowText(hwnd, szName, ARRAYSIZE(szName) - 1);
	if (wcsstr(szName, L"[正在运行-MyExe title name]") != NULL)
	{
		*((HWND *)lParam) = hwnd;
		return FALSE;
	}
	return TRUE;
}

HWND MyFindWindow()
{
	HWND hPrevWnd = NULL;
	EnumWindows(MyFindWindowEnum, (LPARAM)&hPrevWnd);
	return hPrevWnd;
}


BOOL IsMyExeRunning()
{
	HWND hWnd = MyFindWindow();
	if( hWnd != NULL )
	{
		return TRUE;
	}
	else
	{
		return FALSE;
	}
}

你可能感兴趣的:([Windows]环境编程)