I've just spent the evening tracking down this problem, as it was really annoying me (Tracker: 1165626). The solution was simple, but finding the information was not. It's such a surprising issue (to me anyway) that I thought I'd share it with you.

DoModal was using GetParent() to try to find the owner window, so that it could disable it. It turns out that despite the reference documentation saying

"If the window is a top-level window, the return value is a handle to the owner window."
http://msdn.microsoft.com/library//en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/getparent.asp

the actual behaviour is somewhat more complex, and that statement does not hold for overlapped windows, only for popup windows. The real information can be found at

http://support.microsoft.com/default.aspx?scid=kb;en-us;84190
"The return value from the GetParent function is more confusing. GetParent returns zero for overlapped windows (windows with neither the WS_CHILD nor the WS_POPUP style). For windows with the WS_CHILD style, GetParent returns the parent window. For windows with the WS_POPUP style, GetParent returns the owner window."

So, the solution was simply to use GetWindow(handle, GW_OWNER) instead of GetParent!

I hope that this might save someone else some time in the future.

Regards,
Rob.


Reply via email to