Enable apply now button always

I have an app that uses a property sheet, I want the "Apply" button to always be enabled. It's possible to enable it on the fly, in an event handler for instance, by calling the function CPropertyPage::SetModified(BOOL flag). But when I tried to just call SetModified from the OnInitDialog() function of one my property pages, so that the whole time the property sheet was displayed the apply button would be enabled, it doesn't work.

I suspect that function only works once the dialog has been displayed, so I can't call from OnInitDialog(). Does anyone out there know a way to do what I'm trying to do?

Who is Participating?
I do not know if it work in onactive, but i've had this problem myself a time ago.
I found a rather simple method after a while:
Just implement (using ClassWizard) the OnCmdMsg() handler in your <CPropertySheet>,
like this:

BOOL CMyPropertySheet::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
      // TODO: Add your specialized code here and/or call the base class

/** Add the next two lines */
            return TRUE;
      return CPropertySheet::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);

Then the apply button will - once activated - never been disabled. To activate it initially you have
to call in each property pages OnInitDialog() handler SetModified(TRUE).
You could try doing it in onactivate! but I'm not 100% sure that onactivate work in non wizard mode.
nicholsoAuthor Commented:
I added the code you have, and put the line SetModified(true); in each property page's OnInitDialog() but when the property sheet first displays, the Apply button is still shaded.

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Okay i am sorry - i mixed up things a little bit. Take a look at this:

1. Add OnApply() to your property page, and add the line SetModified(TRUE);
2. In the OnInitDialog() of your property page add the line SetModified(TRUE);
3. Add OnCmdMsg() to your property sheet (like you have done it already) and insert:
    if(nID==ID_APPLY_NOW) return TRUE;
4. Add to your BEGIN_MESSAGE_MAP/END_MESSAGE_MAP of your CPropertySheet
5. Insert the following function def in your CPropertySheet.h:
    afx_msg LRESULT OnPSMChanged(WPARAM wP,LPARAM lP);
6. Add the following code to your CPropertySheet.cpp:

return TRUE;

Now it should work, sorry for any inconvenience.
PS: Andy, i have tried this one with OnActivate() and i think in non-wizard mode it does not work
nicholsoAuthor Commented:
Well, I can see the Apply button all the time now, but when I hit "Apply" it doesn't run any of the OnApply() handlers...

<grin> sorry i do not know what was going on. I made another little mistake
Please remove the SetModified(TRUE) in your OnApply() handler, and replace it by the

BOOL CMyPropPage::OnApply()
   // TODO: ...

  return CPropertyPage::OnApply(); // <--- CHANGE THIS TO return FALSE;
This works really. Sorry
nicholsoAuthor Commented:
Thanks, it works now. There was one mistake, though--in the OnCmdMsg function, it needs to return FALSE if the message is from the Apply button, not TRUE.

Once I changed that it works great. Thanks!!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.