Overriding the default buttons on CPropertySheets

Thursday Aug 6th 1998 by Chris Green

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:

And declare OnSetDefID which would look something like this:
//CMG: Override the CPropertySheet default button and replace with own.
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;
  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

Mobile Site | Full Site