Click to See Complete Forum and Search --> : How to Change the button caption of CFileDialog?


Raphael Phan
March 30th, 1999, 07:22 PM
Hi,


I am using CFileDialog for my application, as a prompt to the user to select a

file to be overwritten. The problem is, the button has a caption "Open". how

do i change it to "Overwrite"? Also, how do i change the title of the dialog box?


Raphael

No name
March 30th, 1999, 10:30 PM
Click the properties for the button


In the caption window type the name you desire for the button


The same applies for your app

Raphael Phan
March 30th, 1999, 11:58 PM
Hi,

Well, I am not actually deriving a class from CFileDialog. I just use

an object of CFileDialog and then using it.

static char BASED_CODE szFilter[] = "Text Files (*.txt)|*.txt|Word Documents (*.doc)|*.doc|Image Files

(*.jpg;*.bmp;*.gif)|*.jpg; *.bmp;*.gif|All Files (*.*)|*.*||";

CFileDialog myDlg (TRUE, "*.txt", NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilter);

myDlg.m_ofn.lpstrTitle ="Overwrite a File";

This much I know how to do, that is to replace the title of the dialog box.

and then to display the dialog box, i just use

myDlg.DoModal();

But how do i change the caption of the OK button? the m_ofn structure does not

have any variable for defining the caption of the OK button


Raphael

sally
March 31st, 1999, 12:11 AM
override OnInitDialog and after CFileDialog has done its stuff,

get a handle to IDOK and change the text on the returned CWnd


Sally

Sally
March 31st, 1999, 12:11 AM
override OnInitDialog and after CFileDialog has done its stuff,

get a handle to IDOK and change the text on the returned CWnd


Sally

Reshmi
March 31st, 1999, 01:16 AM
Hi,

Before you call DoModal() of the file open dialog box set timer like this.

SetTimer(0,5,NULL);

Add a command handler for WM_TIMER message in your class.

In the handler do this

CWnd* pWndOfTitle = CWnd::FindWindow(NULL, "Overwrite");

if(pWndOfTitle ){

CWnd* pWndOfOpen = pWndOfTitle ->GetDlgItem(IDOK);

pWndOfOpen->SetWindowText("Overwrite");

}

The result was as expected. But there was a flicker in every 5 ms. Bcoz

windows send WM_TIMER message in every 5ms and the handler gets executed.

I couldn't remove that flicker. If you know the solution please let me know.


Hope this helps u,

Reshmi

Raphael Phan
March 31st, 1999, 02:26 AM
Hi,


Sorry but how do we override OnInitDialog? Can we do that without deriving

a class from CFileDialog?

sally
March 31st, 1999, 02:48 AM
no


Sally

Sally
March 31st, 1999, 02:48 AM
no


Sally

sally
March 31st, 1999, 02:50 AM
it is better to derive CMyFileDialog from CFileDialog, override OnInitDialog

and SET the text there


Sally

Sally
March 31st, 1999, 02:50 AM
it is better to derive CMyFileDialog from CFileDialog, override OnInitDialog

and SET the text there


Sally

Rail Jon Rogut
March 31st, 1999, 03:15 AM
To change the OK button's text, derive a class from CFileDialog and use the undocumented function SetControlText().

To set an initial directory, set the OPENFILENAME structure member lpstrInitialDir to the directory.

CFileDialog dlg(...);

dlg.m_ofn.lpstrInitialDir = "x:\\folder";

dlg.DoModal();

If you look on my web site, at my MFC Example Projects for example 11, the CFileDialog class is set up to allow you to

change the button's text.

To use it:

CXDlg2 dlg(TRUE, _T("*"), NULL,

OFN_FILEMUSTEXIST | OFN_HIDEREADONLY,

_T("(Your File Type) Files (*.*)|*.*|All Files (*.*)|*.*||"));

dlg.m_ofn.lpstrInitialDir = "x:\\folder";

dlg.SetOKButtonText("OverWrite");

dlg.DoModal();


Rail


Recording Engineer/Software Developer

Rail Jon Rogut Software


Rail Jon Rogut Software

Rail Jon Rogut
March 31st, 1999, 03:23 AM
Oops... sorry, I answered how to set the initial folder, when you were asking how to set the dialog box title, in the OPENFILENAME structure, set the lpstrTitle value:


CFileDialog dlg(...)


dlg.m_ofn.lpstrTitle = "Select a file";


dlg.DoModal();


Rail

Recording Engineer/Software Developer

Rail Jon Rogut Software


Rail Jon Rogut Software