Solved

Change a Button on main window from propertysheet.

Posted on 1998-11-17
8
229 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Suggested Solutions

Title # Comments Views Activity
sumNumber challenge 16 139
countEvens challenge 2 112
Sed question 2 104
SQUD PROXY SERVER, UNIX, SLL/HTTPS 5 104
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

820 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