|
-
August 4th, 2006, 04:11 AM
#1
[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);
Last edited by John E; August 4th, 2006 at 04:32 AM.
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
August 4th, 2006, 04:28 AM
#2
Re: CPropertySheet 'Help' key (disabling)
Hi John,
Use
PropSheet.m_psh.dwFlags &= ~PSH_HASHELP;
Proppage.m_psp.dwFlags &= ~PSH_HASHELP;
-
August 4th, 2006, 04:34 AM
#3
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.
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
August 4th, 2006, 04:35 AM
#4
Re: CPropertySheet 'Help' key (disabling)
 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.
 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?
-
August 4th, 2006, 04:40 AM
#5
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);
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
August 4th, 2006, 04:50 AM
#6
Re: CPropertySheet 'Help' key (disabling)
 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?
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: ~
Last edited by VictorN; August 4th, 2006 at 04:54 AM.
-
August 4th, 2006, 05:03 AM
#7
Re: CPropertySheet 'Help' key (disabling)
 Originally Posted by VictorN
Well, what does the second parameter ( ~WS_ENABLED) mean?
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.
 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)
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
August 4th, 2006, 05:19 AM
#8
Re: CPropertySheet 'Help' key (disabling)
 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?
Was id caused by such a stange ModyfyStyle call? OR some other reason?
-
August 4th, 2006, 06:06 AM
#9
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....
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
August 4th, 2006, 07:17 AM
#10
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?
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
August 4th, 2006, 07:40 AM
#11
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!
Last edited by ovidiucucu; August 4th, 2006 at 07:43 AM.
-
August 4th, 2006, 08:24 AM
#12
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;
}
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
August 4th, 2006, 08:56 AM
#13
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|