?
Solved

Change a Button on main window from propertysheet.

Posted on 1998-11-17
8
Medium Priority
?
232 Views
Last Modified: 2013-11-20
I´ve mad an app with a popertysheet on the main Dialog. Now when I change some variables in my propertysheet I would like to be able to enable/disable the Apply button on the main dialog. Is that possible??
I would like an easy answer please, since I´m new at MFC.
Thanx..
0
Comment
Question by:joakimf
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 2

Expert Comment

by:wyy_cq
ID: 1324815
of cource you can !!!

 you can call CPropertyPage::SetModified(BOOL) to set the state of the apply button.

an other way.
step by step:
1 define the message map in the sheet , so that you will be notify when something change .for example ,you define the combox select change message map so that you will be notified when the select is changed.
you need to generate a new class from CPropertySheet with the dialog resource also.

2 when be notified you need to get main Dialog HWND and the button HWND of Apply.(HWND can be the CWnd* in MFC)
 GetParent(...) can return the main dialog CWnd*,
 use the main dialog CWnd* you can call GetDlgItem(ID_OF_APPLY) to get the apply button CWnd*.
 ID_OF_APPLY is the ID of the apply button . the value is a constance ,you can find it in VC Online help ,of use the Spy to find it out.

3 according to your need you can enable/disable the apply botton.

by this method you can control not only the apply button but any window's state .
0
 
LVL 1

Author Comment

by:joakimf
ID: 1324816
This looks like it will work. I´m not to good at this things, but I´ve tried this code:
      CWnd* cWnd;
      cWnd = GetParent ();

      cWnd->GetDlgItem(IDC_APPLY_BUTTON)->EnableWindow(FALSE);
      cWnd->UpdateData(FALSE);
And it doesn´t work. The program crashes. Maybe you can tell me what I´ve done wrong.
Thanx...

0
 
LVL 1

Author Comment

by:joakimf
ID: 1324817
I´ve tried some more and when I call GetParent I get a handle to a CPropertySheet, I need a handle to the main Dialog where the propertysheets are placed. I don´t have the the APPLY button that are in the CPropertyPage class, I´ve placed one on the main Dialog, called IDC_APPLY_BUTTON . I would like to be able to call EnableWindow(BOOL) from all the sheets. I´ve placed the controls on the sheets so that when they are changed in those functions On..Check , On...Button and so on I want to call EnableWindow. When I try that I´ve written above I get NULL, when calling EnableWindow.
Thanx....
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 3

Expert Comment

by:plaroche
ID: 1324818
Try this:

      if (bChanged)
            pSheetWnd->SendMessage(PSM_CHANGED, (WPARAM)m_hWnd);
      else
            pSheetWnd->SendMessage(PSM_UNCHANGED, (WPARAM)m_hWnd);

where:

pSheetWnd is a pointer to the property sheet.
m_hWnd is a handle to the page that changed, or NULL might work.
bChanged is the button's state.
0
 
LVL 1

Author Comment

by:joakimf
ID: 1324819
This question can´t be that difficult to answer. I have a Dialog window, (the main dialog) thats created after using AppWizard. Let´s call the Class CMyDlg. I´ve added PropertySheets in OnInitDialog with the following code:
PropertySheet.AddPage(&StartMenuDlg);
PropertySheet.AddPage(&DesktopDlg);
PropertySheet.AddPage(&MiscDlg);

PropertySheet.Create(this, WS_CHILD |WS_VISIBLE,0);
PropertySheet.ModifyStyleEx ( 0,WS_EX_CONTROLPARENT );
PropertySheet.ModifyStyle ( 0,WS_TABSTOP );

All the Dlg:s except the CMyDlg are derived from CPropertyPage.

I´ve put a Button on the CMyDlg and called it Apply. IDC_APPLY_BUTTON. When I change something in a CheckBox on the StartMenuDlg I want to be able to Change the Apply button placed on the CMyDlg. How can I do that??
It´s got to be possible to do this in an easy way.
Increasing points....
0
 
LVL 3

Accepted Solution

by:
plaroche earned 360 total points
ID: 1324820
Have you tried a second GetParent() on the propery sheet.

From your dialog:

CWnd* pSheet = GetParent();
CWnd* pDialog = pSheet->GetParent();

pDialog->GetDlgItem(IDC_APPLY_BUTTON)->EnableWindow(FALSE);

If this works you should add some checks for NULL pointers.
0
 
LVL 3

Expert Comment

by:shaig
ID: 1324821
The answer is not correct (but almost)

the button is the sheet's member, thats why you should:
from within the sheet object

GetDlgItem(IDC_APPLY_BUTTON)->EnableWindow(FALSE);

(and check for NULLs)
0
 
LVL 1

Author Comment

by:joakimf
ID: 1324822
Thank you Plaroche, you helped me out bigtime.....
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question