CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13
  1. #1
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,867

    [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

  2. #2
    Join Date
    Oct 2000
    Location
    India
    Posts
    4,620

    Thumbs up Re: CPropertySheet 'Help' key (disabling)

    Hi John,

    Use

    PropSheet.m_psh.dwFlags &= ~PSH_HASHELP;
    Proppage.m_psp.dwFlags &= ~PSH_HASHELP;
    All luck and have a great day.

    Regards,
    V.Girish

    Visit www.geocities.com/contactgirish for Source code, Tutorials, FAQs and Downloads.

  3. #3
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,867

    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

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    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?

  5. #5
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,867

    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

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    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?
    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.

  7. #7
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,867

    Re: CPropertySheet 'Help' key (disabling)

    Quote 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.


    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)
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    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?
    Was id caused by such a stange ModyfyStyle call? OR some other reason?

  9. #9
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,867

    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

  10. #10
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,867

    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

  11. #11
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,244

    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.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  12. #12
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,867

    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

  13. #13
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,244

    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.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured