Solved

Change a Button on main window from propertysheet.

Posted on 1998-11-17
8
230 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Get filename and folder into excel 7 89
Separate files macro - Errors on larger data set 18 76
unable to delete all specified values regedit 38 886
Path of Workbook 3 87
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

734 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