Psychic debugging: Why you can't control page navigation when using PSP_DLGINDIRECT
Here’s a problem that floated past a few years ago.
We switched our wizard from using dialog resource IDs to using
PSP_DLGINDIRECTbecause [reasons deleted since they aren’t important]. But once we did that, the Next button doesn’t work! Anybody have any ideas what’s going on?
I made things a little easier by deleting the information that isn’t relevant to the problem. See if you can solve it before reading further. Here’s my reply:
My psychic powers tell me that your wizard navigation code is still trying to navigate by ID even though you aren’t using IDs any more.
PSN_WIZBACK notifications allow you to control navigation by returning the dialog identifier of the page you want to go to. If you change from dialog identifiers to indirect dialogs, you have to remember to update your page-switching logic as well.
But how do you specify pages when you aren’t using dialog resource IDs?
Let’s take a step back and look at the way dialogs are specified. There are three ways to do this:
- By dialog resource ID:
psp.pszTemplate = MAKEINTRESOURCE(n)
- By dialog resource name:
psp.pszTemplate = TEXT("name")
- By dialog resource indirect:
psp.pResource = lpTemplate. If you use this method, you also have to set the
If you look at the property sheet page structure, you’ll also notice that the
pResource members are actually
unioned together; they are just alternate names for the same thing.
If you specified your page via dialog resource ID, you can return that dialog resource ID; but what if you used a dialog resource name or an indirect dialog? Well, since the dialog resource ID, resource name, and indirect dialog are all stored in the same place, you just pass whatever you passed in the
PROPSHEETPAGE.pszTemplate / pResource originally. All the property sheet manager does is compare the value you pass in with the value you specified in the
PROPSHEETPAGE. (As of this writing, the documentation doesn’t make this clear; I’ve submitted a doc change request to fix it.)
This technique works with
PSN_SETACTIVE. It should work in principle with
PSM_IDTOINDEX, except that there was a bug on 64-bit Windows XP (fixed in Windows Vista) that prevented it from working: The value you pass in was accidentally truncated to a 32-bit value. Oops.