Overriding the default buttons on CPropertySheets

How to override the default buttons on a properysheet:

What you need to do is override the OnSetDefID in CPropertySheet. So you would add the following to your message map in your derived class:

ON_MESSAGE(DM_SETDEFID, OnSetDefID)
And declare OnSetDefID which would look something like this:
//CMG: Override the CPropertySheet default button and replace with own.
LRESULT CTSIDlg::OnSetDefID(WPARAM wParam, LPARAM lParam)
{
LRESULT lReturn;
//The current default ID, in case you want to access it:
int nIDOldDef = LOWORD(DefWindowProc(DM_GETDEFID, wParam, lParam));

  switch (GetActiveIndex())
  {
   case 1:
    lReturn = DefWindowProc(DM_SETDEFID, YOUR_ID_HERE, lParam);
    return lReturn;
    break;
  }
  return Default(); 
}

Note in the DefWindowProc you can set the default ID for your own control.

One thing I didn't figure out is how to erase the dark highlight from the OK button. But the ID you set will also have the dark highlight.

If you were using the Wizard you might do this differently. If you want a really nice piece of code I could send it later as in Wizard mode the FINISH button and NEXT button would need to be default sometimes. But if you just have a regular PropertySheet dialog and want to override the default button this will do the job.

Cheers, Chris

Last updated: 22 July 1998