FindWindowEx
fails on getting a visible window from a premium WUP app. I am wondering how do I work around this? My get all windows method works on other non premium WUP apps but not premium as the package owner belongs to Microsoft and not the end user.
What am I doing wrong here? I also tried running it as administrator to no eval. Do I have to create a different handle rather then nullptr?
void GetAllWindowsFromProcessID(DWORD dwProcessID, std::vector <HWND> &vhWnds, bool bg)
{
// find all hWnds (vhWnds) associated with a process id (dwProcessID)
HWND hCurWnd = nullptr;
do
{
hCurWnd = FindWindowEx(nullptr, hCurWnd, nullptr, nullptr);
DWORD checkProcessID = 0;
GetWindowThreadProcessId(hCurWnd, &checkProcessID);
if (checkProcessID == dwProcessID && (bg || IsWindowVisible(hCurWnd)))
{
vhWnds.push_back(hCurWnd);
}
}
while (hCurWnd != nullptr);
}
int main()
{
vector<HWND> windows;
GetAllWindowsFromProcessID(1180, windows, false);//change the number
after you launch say minecraft to it's PID
std::cout << windows.empty() << endl;
GetAllWindowsFromProcessID(1180, windows, true);//test background
windows it finds some but sending them a WM_CLOSE or SC_CLOSE Does
nothing
for(HWND win : windows)
{
cout << win << endl;
PostMessage(win, WM_CLOSE, 0, 0);
// PostMessage(win, WM_SYSCOMMAND, SC_CLOSE, 0);//Terminate what TaskManager uses
}
}