Overriding the default buttons on CPropertySheets
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, ChrisLast updated: 22 July 1998

Comments
Adding to Christopher's solution
Posted by Legacy on 06/25/2003 12:00amOriginally posted by: Sreekanth Kollu
void CSheetDerived::OnOK()
{
if (IDYES == MessageBox(_T("Do you really want to make this update?"),
_T("Caption"),
MB_YESNO))
{
PressButton(PSBTN_OK);
// Functionality that can be added..
EndDialog(IDOK);
}
}
EndDialog(IDOK) must be there if we are handling OK button..Because the property sheet DoModal() method wont get IDOK return value. Thanks Christopher, ur soln helped me..
Replyyour code doesn't work well
Posted by Legacy on 01/28/2000 12:00amOriginally posted by: Nguyen Cong Thuan
follow your guide i've been build an app using wizard as following:
LRESULT StsSheet::OnSetDefID(WPARAM wParam, LPARAM lParam)
{
LRESULT lReturn;
int nIDOldDef = LOWORD(DefWindowProc(DM_GETDEFID, wParam, lParam));
if(nIDOldDef==ID_WIZNEXT)
return DefWindowProc(DM_SETDEFID, ID_PG_NEXT, lParam);
return Default();
}
//on pages.h
virtual LRESULT OnButtonNext();
//on pages.cpp
BEGIN_MESSAGE_MAP(Page1, CPropertyPage)
//{{AFX_MSG_MAP(Page1)
ON_MESSAGE(ID_PG_NEXT, OnButtonNext)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
LRESULT Page1::OnButtonNext()
{
//my code here
}
so i don't want to change to next page when user press next button but do another job. In fact function OnButtonNext() has never been called and still change to next page. so that code doesn't work.
please help me to fix this problem. Thank you very much!
ReplyControlling the exit of a CPropertySheet
Posted by Legacy on 10/25/1999 12:00amOriginally posted by: Christopher Duncan
ReplyOverriding the default state border
Posted by Legacy on 02/15/1999 12:00amOriginally posted by: Philippe Lhoste
From the DM_SETDEFID help topic:
Using the DM_SETDEFID message can result in more than one button appearing to have the default push button state. When the system brings up a dialog, it draws the first push button in the dialog template with the default state border. Sending a DM_SETDEFID message to change the default button will not always remove the default state border from the first push button. In these cases, the application should send a BM_SETSTYLE message to change the first push button border style.
I didn't tried it yet...
Reply