Reputation: 4615
I have one problem . I am trying to destroy child window ,but it also destroys parent window, so application closes. I have such code.
HWND cloneWin =FindWindowEx(hWnd, 0, szChildWin, 0);
if (cloneWin) {
MessageBox(NULL,"You are trying to create more than one child window\n Current child window will be destroyed", "Message", MB_OK|MB_ICONINFORMATION);
DestroyWindow(cloneWin);
}
What is wrong ? THx in advance !
Upvotes: 0
Views: 1218
Reputation: 613461
The documentation says:
A thread cannot use DestroyWindow to destroy a window created by a different thread.
Since you are trying to find these windows using FindWindowEx
, it seems pretty obvious that the windows were created in a different process, never mind a different thread. In other words, your call to DestroyWindow
can never succeed. Hard to know why this is bringing the other application down, but since you are not obeying the rules then I suppose it is reasonable that anything can happen.
It's plausible I suppose that you could send the window a WM_CLOSE
message and hope that it will respond by calling DestroyWindow
. That would be a valid call to DestroyWindow
because it would be made on the thread that created the window. But it all depends on how that other window responds to WM_CLOSE
.
Upvotes: 2