Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to change button text in CFileDialog

658 views
Skip to first unread message

Joe Buller

unread,
Sep 29, 1997, 3:00:00 AM9/29/97
to

I've been unsuccessful in my attempts to change the button text for the
IDOK / "Open" button in the [common] CFileDialog. Any hints???

Robert Cummings

unread,
Sep 29, 1997, 3:00:00 AM9/29/97
to

On Mon, 29 Sep 1997 09:02:57 -0700, Joe Buller <jbu...@softtest.com>
wrote:

>I've been unsuccessful in my attempts to change the button text for the
>IDOK / "Open" button in the [common] CFileDialog. Any hints???

Hi Joe,

Add a dialog(Insert|Resource), then use ClassWizard to derive a dialog
class from CFileDialog(). Override OnInitDialog() and add the
following:

CWnd* MyFile = GetParent()->GetDlgItem(IDOK);
MyFile->SetWindowText("Help");

Of course, the size of the button will remain the same, so if text is
a bit longer you'll have to do some customizing. Check out the
following KB Article(Q125706):

"Customizing the FileOpen Common Dialog in Windows 95"

Good Luck,
Rob

Jim Kopkowski

unread,
Oct 1, 1997, 3:00:00 AM10/1/97
to

Derive from the common CFileDialog and add the code below to your
OnInitDialog below.


BOOL CSndFileDlg::OnInitDialog()
{
BOOL bRet = CFileDialog::OnInitDialog();
if (bRet == TRUE)
{
GetParent()->GetDlgItem(IDOK)->SetWindowText("Select");
}


return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}

This will change the text on the Ok button.
-Jim Kopkowski
jkop...@manu.com

Joe Buller wrote in article <342FD131...@softtest.com>...

Rail J. Rogut

unread,
Oct 6, 1997, 3:00:00 AM10/6/97
to jbu...@softtest.com

Joe Buller wrote:
>
> I've been unsuccessful in my attempts to change the button text for the
> IDOK / "Open" button in the [common] CFileDialog. Any hints???

Well if you're using the Explorer style then this will do it (The
commented out code will work with Win 3.1).

This version relies on the undocumented SetControlText(). But if you
remove the comments and get rid of the undocumented call it does it the
old fashioned way.

// ExtFileDlg.h : header file
//

/////////////////////////////////////////////////////////////////////////////
// CExtFileDlg dialog

class CExtFileDlg : public CFileDialog
{
DECLARE_DYNAMIC(CExtFileDlg)

public:
void SetOKButtonText(CString szText);
CString m_OKButtonText;
CExtFileDlg(BOOL bOpenFileDialog, // TRUE for FileOpen, FALSE
for
FileSaveAs
LPCTSTR lpszDefExt = NULL,
LPCTSTR lpszFileName = NULL,
DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
LPCTSTR lpszFilter = NULL,
CWnd* pParentWnd = NULL);

protected:
//{{AFX_MSG(CExtFileDlg)
virtual BOOL OnInitDialog();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
private:
BOOL m_bOKText;
CWnd* pOKButton;
};


// ExtFileDlg.cpp : implementation file
//

#include "stdafx.h"
#include "SAWINV2.h"
#include "ExtFileDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CExtFileDlg

IMPLEMENT_DYNAMIC(CExtFileDlg, CFileDialog)

CExtFileDlg::CExtFileDlg(BOOL bOpenFileDialog, LPCTSTR lpszDefExt,
LPCTSTR lpszFileName,
DWORD dwFlags, LPCTSTR lpszFilter, CWnd* pParentWnd) :
CFileDialog(bOpenFileDialog, lpszDefExt, lpszFileName,
dwFlags,
lpszFilter, pParentWnd)
{
m_bOKText = FALSE;
}


BEGIN_MESSAGE_MAP(CExtFileDlg, CFileDialog)
//{{AFX_MSG_MAP(CExtFileDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()


BOOL CExtFileDlg::OnInitDialog()
{
CFileDialog::OnInitDialog();

/*
Original code:

CWnd* pParent = GetParent();

pOKButton = pParent->GetDlgItem(IDOK); // Win95 Style

if (!pOKButton)
pOKButton = GetDlgItem(IDOK); // Old style
*/

if (m_bOKText)
{
// New version with the undocumented call:

SetControlText(IDOK, m_OKButtonText);

// Original code:
// pOKButton->SetWindowText(m_OKButtonText);
}

return TRUE; // return TRUE unless you set the focus to a
control
// EXCEPTION: OCX Property Pages should return
FALSE
}

void CExtFileDlg::SetOKButtonText(CString szText)
{
m_OKButtonText = szText;
m_bOKText = TRUE;
}


This is a real easy class to understand... I've created my own function
SetOKButtonText to enter the control's text before the dialog is created
and it sets a flag to let the OnInitDialog() know if it needs to call
SetControlText.

To use this class make sure to #include "ExtFileDlg.h" and then:

CExtFileDlg DialogDF(TRUE, _T("tem"), NULL,
OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_EXPLORER,
_T("Template Files (*.tem)|*.tem|All Files
(*.*)|*.*||"));

DialogDF.m_ofn.lpstrTitle = (LPCTSTR)_T("Delete File");

DialogDF.SetOKButtonText("Delete");

if (DialogDF.DoModal() == IDOK)
{
// Delete the files here
}

Hope this helps.

Rail
--
Recording Engineer/Software Developer
Rail Jon Rogut Software
http://home.earthlink.net/~railro
mailto:rai...@earthlink.net

0 new messages