Solved

Change a Button on main window from propertysheet.

Posted on 1998-11-17
8
227 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
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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 90 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MFC Dialog 9 48
ORA-01403: no data found 43 90
maxBlock challenge 30 111
EvenOdd challenge 10 89
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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…
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.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

912 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now