Solved

Change a Button on main window from propertysheet.

Posted on 1998-11-17
8
226 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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 video discusses moving either the default database or any database to a new volume.

762 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

28 Experts available now in Live!

Get 1:1 Help Now