[RESOLVED] CPropertySheet 'Help' key (disabling)
I need to "gray out" (i.e. enable / disable) the 'Help' button on a property sheet, depending upon which property page is currently selected. Just to check that I had the right resource ID I tried this:-
GetParent()->GetDlgItem(IDHELP)->SetWindowText("Goodbye");
which successfully changes the text to "Goodbye". I also tried this:-
GetParent()->GetDlgItem(IDHELP)->ShowWindow(SW_HIDE);
which successfully made the button disappear. However, I can't seem to find a way to give the button a standard 'disabled' look. This doesn't work:-
GetParent()->GetDlgItem(IDHELP)->EnableWindow(FALSE);
....and this actually asserts although it's a technique I've used many times before with other buttons:-
GetParent()->GetDlgItem(IDHELP)->ShowWindow(SW_HIDE);
GetParent()->GetDlgItem(IDHELP)->ModifyStyle(WS_TABSTOP, ~WS_ENABLED);
GetParent()->GetDlgItem(IDHELP)->ShowWindow(SW_SHOWNOACTIVATE);
I'm rapidly running out of ideas. Can anyone suggest an alternative strategy?
[ Edit... ]
Just for the record, this doesn't work either - but at least it doesn't assert....
GetParent()->GetDlgItem(IDHELP)->ModifyStyle(WS_TABSTOP, WS_DISABLED);
GetParent()->GetDlgItem(IDHELP)->ShowWindow(SW_HIDE);
GetParent()->GetDlgItem(IDHELP)->ShowWindow(SW_SHOWNOACTIVATE);
Re: CPropertySheet 'Help' key (disabling)
Hi John,
Use
PropSheet.m_psh.dwFlags &= ~PSH_HASHELP;
Proppage.m_psp.dwFlags &= ~PSH_HASHELP;
Re: CPropertySheet 'Help' key (disabling)
Sorry, I don't understand. Would those flags only be relevant at creation time? I need to enable & disable the button on-the-fly.
Re: CPropertySheet 'Help' key (disabling)
Quote:
Originally Posted by VGirish
PropSheet.m_psh.dwFlags &= ~PSH_HASHELP;
Proppage.m_psp.dwFlags &= ~PSH_HASHELP;
Yes, it will work, but button will be hidden not disabled.
Quote:
Originally Posted by John E
....and this actually asserts although it's a technique I've used many times before with other buttons
What does "asserts "? When and where?
Re: CPropertySheet 'Help' key (disabling)
Victor - immediately after this line....
GetParent()->GetDlgItem(IDHELP)->ModifyStyle(WS_TABSTOP, ~WS_ENABLED);
the call to this line asserts:-
GetParent()->GetDlgItem(IDHELP)->ShowWindow(SW_SHOWNOACTIVATE);
However, if I do this, it doesn't assert (but it still doesn't work):-
GetParent()->GetDlgItem(IDHELP)->ModifyStyle(WS_TABSTOP, WS_DISABLED);
GetParent()->GetDlgItem(IDHELP)->ShowWindow(SW_SHOWNOACTIVATE);
Re: CPropertySheet 'Help' key (disabling)
Quote:
Originally Posted by John E
Victor - immediately after this line....
GetParent()->GetDlgItem(IDHELP)->ModifyStyle(WS_TABSTOP, ~WS_ENABLED);
Well, what does the second parameter (~WS_ENABLED) mean? :confused:
Are you sure it has a correct meaning (at least, for ModifyStyle call)?
Or you wanted something "non-standard" ? What?
BTW, you could step in this call(s) by debugging to see what is happening, where and why!
PS. You also might want to read about One's Complement Operator: ~
Re: CPropertySheet 'Help' key (disabling)
Quote:
Originally Posted by VictorN
Well, what does the second parameter (~WS_ENABLED) mean? :confused:
Are you sure it has a correct meaning (at least, for ModifyStyle call)?
No I'm not sure. I'm just trying different approaches because the standard approach ( CWnd::EnableWindow(FALSE) ) wouldn't work.
Quote:
Originally Posted by VictorN
BTW, you could step in this call(s) by debugging to see what is happening, where and why!
Yes, I already did that. This is where the assertion happens:-
Code:
BOOL CWnd::ShowWindow(int nCmdShow)
{
ASSERT(::IsWindow(m_hWnd)); // <--- Asserts here
if (m_pCtrlSite == NULL)
return ::ShowWindow(m_hWnd, nCmdShow);
else
return m_pCtrlSite->ShowWindow(nCmdShow);
}
I've often found that CWnd::EnableWindow(FALSE) is unreliable. I've got into the habit of using this method which always worked successfully, until today.
Code:
GetParent()->GetDlgItem(IDHELP)->ModifyStyle(WS_TABSTOP, WS_DISABLED);
GetParent()->GetDlgItem(IDHELP)->ShowWindow(SW_HIDE);
GetParent()->GetDlgItem(IDHELP)->ShowWindow(SW_SHOWNOACTIVATE)
Re: CPropertySheet 'Help' key (disabling)
Quote:
Originally Posted by John E
... This is where the assertion happens:-
Code:
BOOL CWnd::ShowWindow(int nCmdShow)
{
ASSERT(::IsWindow(m_hWnd)); // <--- Asserts here
if (m_pCtrlSite == NULL)
return ::ShowWindow(m_hWnd, nCmdShow);
else
return m_pCtrlSite->ShowWindow(nCmdShow);
}
It means that the window you want to hide does NOT exist! The question is - how could it happen? :confused:
Was id caused by such a stange ModyfyStyle call? OR some other reason? :confused:
Re: CPropertySheet 'Help' key (disabling)
It's caused by the strange Modify style. I suppose what I really should have done was this....
GetParent()->GetDlgItem(IDHELP)->ModifyStyle(WS_ENABLED, WS_DISABLED);
but that doesn't work either.... :(
Re: CPropertySheet 'Help' key (disabling)
Okay, I figured out what's happening but I'm not sure where it's happening. If I set the button to be disabled within the constructor for my property page (that's the page - not the sheet) it's still disabled by the time OnSetActive() gets reached. However, following OnSetActive(), something else seems to get called which immediately resets the button to be enabled again. Any ideas where that might be happening?
Re: CPropertySheet 'Help' key (disabling)
I told you many times: "a user message, well shot, can save the situation"... ;)
Code:
#define WM_APP_DISABLE_HELP (WM_APP+1)
Code:
class CMyPropertySheet : public CPropertySheet
{
// ...
//}}AFX_MSG
afx_msg LRESULT OnDisableHelp(WPARAM, LPARAM);
DECLARE_MESSAGE_MAP()
};
//}}AFX_MSG_MAP
ON_MESSAGE(WM_APP_DISABLE_HELP, OnDisableHelp)
END_MESSAGE_MAP()
LRESULT CMyPropertySheet::OnDisableHelp(WPARAM, LPARAM)
{
GetDlgItem(IDHELP)->EnableWindow(FALSE);
return (LRESULT)0;
}
Code:
BOOL CMyPropertyPage2::OnSetActive()
{
BOOL bRet = CPropertyPage::OnSetActive();
// ....given some condition...
GetParent()->PostMessage(WM_APP_DISABLE_HELP);
return bRet;
}
Enjoy! :)
Re: CPropertySheet 'Help' key (disabling)
That seems to have done the trick, Ovidiu. Thanks for saving my life yet again!! I'm still a bit mystified though.... why did this work...?
Code:
BOOL CMyPropertyPage2::OnSetActive()
{
BOOL bRet = CPropertyPage::OnSetActive();
GetParent()->PostMessage(WM_APP_DISABLE_HELP);
return bRet;
}
when this wouldn't work....
Code:
BOOL CMyPropertyPage2::OnSetActive()
{
BOOL bRet = CPropertyPage::OnSetActive();
GetParent()->GetDlgItem(IDHELP)->EnableWindow(FALSE)
return bRet;
}
Re: CPropertySheet 'Help' key (disabling)
All I can say is that CPropertyPage::OnSetActive virtual function is called from within CPropertyPage::OnNotify when PSN_SETACTIVE notification was received.
What's happen next? I don't know, as long as I cannot enter in the default window procedure. Ask MS team. :D ;)