|Date:||November 2, 2006 / year-entry #372|
|Summary:||Some time ago, I was asked to look at two independent problems with people trying to do modal UI manually. Well, actually, when the issues were presented to me, they weren't described in quite that way. They were more along the lines of, "Something strange is happening in our UI. Can you help?" Only in...|
Some time ago, I was asked to look at two independent problems with people trying to do modal UI manually. Well, actually, when the issues were presented to me, they weren't described in quite that way. They were more along the lines of, "Something strange is happening in our UI. Can you help?" Only in the discussion of the scenarios did it become apparent that it was improper management of modal UI that was the cause.
We already saw one subtlety of managing modal UI manually, namely that you have to enable and disable the windows in the correct order. That wasn't the root of the problems I was looking at, but enabling and disabling windows did play a major role.
took a look at the dialog loop,
the first steps involved manipulating the
if (hwndParent == GetDesktopWindow()) hwndParent = NULL; if (hwndParent) hwndParent = GetAncestor(hwndParent, GA_ROOT); HWND hdlg = CreateDialogIndirectParam(hinst, lpTemplate, hwndParent, lpDlgProc, lParam); BOOL fWasEnabled = EnableWindow(hwndParent, FALSE);
In both cases, the first two "if" statements were missing. We already saw the danger of disabling the desktop window, which is what the first "if" statement protects against. But the specific problem with modal UI was being caused by the missing second "if" statement.
Both of the problems boiled down to somebody passing a child
window as the
The two problems had the same root cause but manifested themselves
The first problem led to strange behavior because
the user could still interact
with the top-level window since it was still enabled.
Sure, a portion of the window was disabled (the portion
controlled by the child window passed as
In the second case,
disabling the wrong window created a different problem:
When the modal UI was complete,
the window manager activated the top-level window that was the
owner of the modal window since that window was never disabled.
This caused the top-level window to receive a
Now, even though this was a subtle problem,
you already knew all the pieces that went into it since I had
covered them earlier.
And as for those psychic powers that I used?
It's really not that magic.
In this case of psychic debugging, I worked backwards.
In response to the report that
Aha, the window isn't enabled.
That's when the customer also mentioned that they were doing
this inside a
Most of what looks like psychic debugging is really just knowing what people tend to get wrong.
<-- Back to Old New Thing Archive Index