I am working on an app that basically capture an application and draw it in openGL.
I first get a valid HWND and want to retrieve all the other windows that are related to it. I fetch all those by using the main HWND pid. I put all of them in a list (standard std::list)
HWND tmpWindowHandle = GetTopWindow(NULL);
while(tmpWindowHandle!=NULL){
DWORD pid;
DWORD currentWindowPid;
GetWindowThreadProcessId(tmpWindowHandle,&pid);
GetWindowThreadProcessId(this->hwnd,¤tWindowPid);
if(pid==currentWindowPid && tmpWindowHandle != this->hwnd){
MyWindow* child = new MyWindow("child",tmpWindowHandle,NULL);
//child->findAllChilds(); <= Recursivity for later
childList.push_front(child);
}
tmpWindowHandle = GetNextWindow(tmpWindowHandle,GW_HWNDNEXT);
}
After this, I get in childList all the windows that do have the same PID as the main HWND (sorted by z-oder)
The second step of my app is to get the bitmap of the specified HWND and to draw it on a surface. I plot them according to the zorder.
drawWindow(HWND hwnd, float zorder) is a function that get the BITMAP of the hwnd handle, and draw it at zorder.
drawWindow(parent, -15);
for(int i = 0; i < currentWindow->childList.size()%10;i++){
MyWindow* child = currentWindow->childList.back();
currentWindow->childList.pop_back();
float deltaZOrder = (float)(currentWindow->childList.size()-i)/currentWindow->childList.size();
drawWindow(child,zOrder+deltaZOrder);
currentWindow->childList.push_front(child);
}
To be more practical, is here what I get when I set the main HWND to be the HWND of a paint windows.
Unfortunately, when it comes to drawing "sisters" (not using the term child because it would mean something else in winapi terminology), I do get weird black cross over my childs :
Do you have any idea what could cause such a behaviour ? My feeling is that there is some windows that also have the same PID that are black and superimpose with the other "visible" windows.
My draw function test if the window is visible (if(IsWindowVisible(currentWindow->hwnd)){
) so I do not get why they are visible anyway as they do not appear on the regular mspaint.exe