How to remove ok,cancel and apply button from property sheets

2.1k views Asked by At

So I tried using this code and it's not working:

CButton *btnApply;
btnApply = reinterpret_cast<CButton *>(GetDlgItem(IDOK));
btnApply->ShowWindow(FALSE);

Thanks in advance.

2

There are 2 answers

2
Barmak Shemirani On

Use PSH_NOAPPLYNOW to hide the apply button in PropertySheet

CMyPropertySheet psheet;
psheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;
psheet.DoModal();

Hiding OK and Cancel button can be handled in CPropertyPage, a handle to parent window is required because the buttons are in parent window not in page window:

BOOL CMyPropertyPage::OnSetActive()
{
    BOOL res = CPropertyPage::OnSetActive();
    CPropertySheet* psheet = (CPropertySheet*)GetParent();
    psheet->GetDlgItem(IDOK)->ShowWindow(SW_HIDE);
    psheet->GetDlgItem(IDCANCEL)->ShowWindow(SW_HIDE);
    return res;
}

or in property sheet:

BOOL CMyPropertySheet::OnInitDialog()
{
    BOOL res = CPropertySheet::OnInitDialog();
    GetDlgItem(IDOK)->ShowWindow(SW_HIDE);
    GetDlgItem(IDCANCEL)->ShowWindow(SW_HIDE);
    return res;
}
0
satishprattipati On

In your property sheet:

BOOL CMyPropertySheet::OnInitDialog()
{
    CWnd *pWnd = GetParent()->GetDlgItem(IDHELP);
        pWnd->ShowWindow( FALSE );

        CWnd *pWnd1 = GetParent()->GetDlgItem(IDCANCEL);
        pWnd1->ShowWindow( FALSE );

        CWnd *pWnd2 = GetParent()->GetDlgItem(IDOK);
        pWnd2->ShowWindow( FALSE );

        CWnd *pWnd3 = GetParent()->GetDlgItem(0x3021);// 0x3021 == IDAPPLY
        pWnd3->ShowWindow( FALSE )
}